Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
71 |
-
|
72 |
"Authorization": f"Bearer {openai_api_key}",
|
73 |
"Content-Type": "application/json"
|
74 |
-
|
75 |
|
76 |
-
|
77 |
-
|
78 |
|
79 |
-
|
80 |
-
|
|
|
|
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
88 |
|
89 |
-
|
90 |
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
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 |
"""
|