reedmayhew commited on
Commit
816374b
·
verified ·
1 Parent(s): aa90007

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -20
app.py CHANGED
@@ -65,35 +65,38 @@ max_phrase_length = max(len(phrase) for phrase, _ in replacements)
65
  MIN_FLUSH_SIZE = max(50, max_phrase_length * 2)
66
 
67
  def think(request):
68
- question = request
69
 
70
- url = "https://openrouter.ai/api/v1/chat/completions"
71
- headers = {
72
  "Authorization": f"Bearer {openai_api_key}",
73
  "Content-Type": "application/json"
74
- }
75
 
76
- def do_req(model, content, include_reasoning=False, reasoning=""):
77
- messages = [{"role": "user", "content": content}]
78
 
79
- if reasoning != "":
80
- messages.append({"role": "assistant", "content": "<think>\n" + reasoning + "</think>\n"})
 
 
81
 
82
- payload = {
83
- "model": model,
84
- "messages": messages,
85
- "include_reasoning": include_reasoning,
86
- "stop": "</think>"
87
- }
 
 
 
88
 
89
- return requests.post(url, headers=headers, data=json.dumps(payload))
90
 
91
 
92
- # R1 will reliably return "done" for the content portion of the response
93
- content = f"{question} Please think this through, but don't output an answer"
94
- reasoning_response = do_req("deepseek/deepseek-r1", content, True)
95
- reasoning = reasoning_response.json()['choices'][0]['message']['reasoning']
96
- return reasoning
97
 
98
  def apply_replacements(text):
99
  """
 
65
  MIN_FLUSH_SIZE = max(50, max_phrase_length * 2)
66
 
67
  def think(request):
 
68
 
69
+ url = "https://openrouter.ai/api/v1/chat/completions"
70
+ headers = {
71
  "Authorization": f"Bearer {openai_api_key}",
72
  "Content-Type": "application/json"
73
+ }
74
 
75
+ def do_req(model, content, include_reasoning=False, reasoning=""):
76
+ messages = content
77
 
78
+ if messages[-1]["role"] == "user":
79
+ messages[-1]["content"] += " Please think this through, but don't output an answer."
80
+
81
+ #messages = [{"role": "user", "content": content}]
82
 
83
+ #if reasoning != "":
84
+ # messages.append({"role": "assistant", "content": "<think>\n" + reasoning + "</think>\n"})
85
+ print(messages)
86
+ payload = {
87
+ "model": model,
88
+ "messages": messages,
89
+ "include_reasoning": include_reasoning,
90
+ "stop": "</think>"
91
+ }
92
 
93
+ return requests.post(url, headers=headers, data=json.dumps(payload))
94
 
95
 
96
+ # R1 will reliably return "done" for the content portion of the response
97
+ reasoning_response = do_req("deepseek/deepseek-r1", request, True)
98
+ reasoning = reasoning_response.json()['choices'][0]['message']['reasoning']
99
+ return reasoning
 
100
 
101
  def apply_replacements(text):
102
  """