bujin2 commited on
Commit
fff41b0
·
verified ·
1 Parent(s): 1598e65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -17
app.py CHANGED
@@ -14,31 +14,33 @@ def respond(
14
  """
15
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
16
  """
17
- # client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
18
  client = InferenceClient(token=hf_token.token, model="utter-project/EuroLLM-9B-Instruct")
19
 
20
  messages = [{"role": "system", "content": system_message}]
21
-
22
  messages.extend(history)
23
-
24
  messages.append({"role": "user", "content": message})
25
 
26
  response = ""
27
 
28
- for message in client.chat_completion(
29
- messages,
30
- max_tokens=max_tokens,
31
- stream=True,
32
- temperature=temperature,
33
- top_p=top_p,
34
- ):
35
- choices = message.choices
36
- token = ""
37
- if len(choices) and choices[0].delta.content:
38
- token = choices[0].delta.content
39
-
40
- response += token
41
- yield response
 
 
 
 
 
42
 
43
 
44
  """
@@ -69,3 +71,4 @@ with gr.Blocks() as demo:
69
 
70
  if __name__ == "__main__":
71
  demo.launch()
 
 
14
  """
15
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
16
  """
 
17
  client = InferenceClient(token=hf_token.token, model="utter-project/EuroLLM-9B-Instruct")
18
 
19
  messages = [{"role": "system", "content": system_message}]
 
20
  messages.extend(history)
 
21
  messages.append({"role": "user", "content": message})
22
 
23
  response = ""
24
 
25
+ try:
26
+ for msg in client.chat_completion(
27
+ messages,
28
+ max_tokens=max_tokens,
29
+ stream=True,
30
+ temperature=temperature,
31
+ top_p=top_p,
32
+ ):
33
+ choices = msg.choices
34
+ if len(choices) and choices[0].delta.content:
35
+ token = choices[0].delta.content
36
+ response += token
37
+ yield response
38
+ except StopIteration:
39
+ pass
40
+
41
+ # Osigurajte da se uvijek vrati barem jedan rezultat
42
+ if not response:
43
+ yield "Sorry, I couldn't generate a response."
44
 
45
 
46
  """
 
71
 
72
  if __name__ == "__main__":
73
  demo.launch()
74
+ # client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")