akhaliq HF Staff commited on
Commit
af660b4
·
verified ·
1 Parent(s): 23357ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
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.get("HF_TOKEN", ""),
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
- completion = client.chat.completions.create(
22
  model="deepseek-ai/DeepSeek-V4-Pro:together",
23
  messages=messages,
24
- stream=True
25
  )
26
 
27
  full_response = ""
28
- for chunk in completion:
29
- if chunk.choices and chunk.choices[0].delta.content:
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