oxtest.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import requests
  2. import json
  3. # First API call with reasoning
  4. response = requests.post(
  5. url="https://openrouter.ai/api/v1/chat/completions",
  6. headers={
  7. "Authorization": "Bearer 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",
  8. "Content-Type": "application/json",
  9. },
  10. data=json.dumps({
  11. "model": "stealth/ox-alpha",
  12. "messages": [
  13. {
  14. "role": "user",
  15. "content": "How many r's are in the word 'strawberry'?"
  16. }
  17. ],
  18. "reasoning": {"enabled": True}
  19. })
  20. )
  21. # Extract the assistant message with reasoning_details
  22. response = response.json()
  23. # response = response['choices'][0]['message']
  24. print(response)
  25. # Preserve the assistant message with reasoning_details
  26. messages = [
  27. {"role": "user", "content": "How many r's are in the word 'strawberry'?"},
  28. {
  29. "role": "assistant",
  30. "content": response.get('content'),
  31. "reasoning_details": response.get('reasoning_details') # Pass back unmodified
  32. },
  33. {"role": "user", "content": "Are you sure? Think carefully."}
  34. ]
  35. # Second API call - model continues reasoning from where it left off
  36. response2 = requests.post(
  37. url="https://openrouter.ai/api/v1/chat/completions",
  38. data=json.dumps({
  39. "model": "stealth/ox-alpha",
  40. "messages": messages, # Includes preserved reasoning_details
  41. "reasoning": {"enabled": True}
  42. })
  43. )
  44. print(response2)