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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -14
app.py CHANGED
@@ -27,20 +27,29 @@ def respond(
27
 
28
  response = ""
29
 
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- try:
38
- token = message.choices[0].delta.content
39
- response += token
40
- yield response
41
- except (AttributeError, IndexError, KeyError) as e:
42
- print(f"Error processing message: {e}")
43
- continue
 
 
 
 
 
 
 
 
 
44
 
45
  """
46
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
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