Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ app = Server()
|
|
| 7 |
|
| 8 |
client = OpenAI(
|
| 9 |
base_url="https://router.huggingface.co/v1",
|
| 10 |
-
api_key=os.environ
|
| 11 |
default_headers={
|
| 12 |
"X-HF-Bill-To": "huggingface"
|
| 13 |
}
|
|
@@ -15,18 +15,17 @@ client = OpenAI(
|
|
| 15 |
|
| 16 |
@app.api()
|
| 17 |
def chat(message: str, history_json: list) -> str:
|
| 18 |
-
# history_json should be a list of dictionaries like [{"role": "user", "content": "..."}, {"role": "assistant", "content": "..."}]
|
| 19 |
messages = history_json + [{"role": "user", "content": message}]
|
| 20 |
|
| 21 |
-
|
| 22 |
model="deepseek-ai/DeepSeek-V4-Pro:together",
|
| 23 |
messages=messages,
|
| 24 |
-
stream=True
|
| 25 |
)
|
| 26 |
|
| 27 |
full_response = ""
|
| 28 |
-
for chunk in
|
| 29 |
-
if chunk.choices
|
| 30 |
full_response += chunk.choices[0].delta.content
|
| 31 |
yield full_response
|
| 32 |
|
|
|
|
| 7 |
|
| 8 |
client = OpenAI(
|
| 9 |
base_url="https://router.huggingface.co/v1",
|
| 10 |
+
api_key=os.environ["HF_TOKEN"],
|
| 11 |
default_headers={
|
| 12 |
"X-HF-Bill-To": "huggingface"
|
| 13 |
}
|
|
|
|
| 15 |
|
| 16 |
@app.api()
|
| 17 |
def chat(message: str, history_json: list) -> str:
|
|
|
|
| 18 |
messages = history_json + [{"role": "user", "content": message}]
|
| 19 |
|
| 20 |
+
stream = client.chat.completions.create(
|
| 21 |
model="deepseek-ai/DeepSeek-V4-Pro:together",
|
| 22 |
messages=messages,
|
| 23 |
+
stream=True,
|
| 24 |
)
|
| 25 |
|
| 26 |
full_response = ""
|
| 27 |
+
for chunk in stream:
|
| 28 |
+
if chunk.choices[0].delta.content is not None:
|
| 29 |
full_response += chunk.choices[0].delta.content
|
| 30 |
yield full_response
|
| 31 |
|