inteligenciamilgrau commited on
Commit
e62890c
·
verified ·
1 Parent(s): 838efce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -22
app.py CHANGED
@@ -27,29 +27,29 @@ def respond(
27
 
28
  response = ""
29
 
30
- try:
31
- for message in client.chat_completion(
32
- messages,
33
- max_tokens=max_tokens,
34
- stream=True,
35
- temperature=temperature,
36
- top_p=top_p,
37
- ):
38
- # Check if the message is in the expected format
39
- if not message or not isinstance(message, dict):
40
- continue
 
 
 
 
 
41
 
42
- # Extract token and handle potential errors in parsing
43
- try:
44
- token = message.choices[0].delta.content
45
- response += token
46
- yield response
47
- except (AttributeError, IndexError, KeyError) as e:
48
- print(f"Error processing message: {e}")
49
- continue
50
- except Exception as e:
51
- print(f"Unexpected error: {e}")
52
- yield "An error occurred while generating the response."
53
 
54
  """
55
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
27
 
28
  response = ""
29
 
30
+
31
+ for message in client.chat_completion(
32
+ messages,
33
+ max_tokens=max_tokens,
34
+ stream=True,
35
+ temperature=temperature,
36
+ top_p=top_p,
37
+ ):
38
+ print("MESSAGE", message)
39
+ # Check if the message is in the expected format
40
+ if not message or not isinstance(message, dict):
41
+ continue
42
+
43
+ # Extract token and handle potential errors in parsing
44
+ try:
45
+ token = message.choices[0].delta.content
46
 
47
+ response += token
48
+ yield response
49
+ except (AttributeError, IndexError, KeyError) as e:
50
+ print(f"Error processing message: {e}")
51
+ continue
52
+
 
 
 
 
 
53
 
54
  """
55
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface