abbygracehoffman commited on
Commit
3004bef
·
verified ·
1 Parent(s): c3ee649

add streaming text

Browse files
Files changed (1) hide show
  1. app.py +23 -5
app.py CHANGED
@@ -53,11 +53,29 @@ def respond(message, history):
53
  messages.append({"role": "user", "content": message})
54
 
55
  response = ""
56
- for msg in client.chat_completion(messages, max_tokens=500, temperature=.1, stream=True):
57
- token = msg.choices[0].delta.content
58
- if token:
59
- response += token
60
- return response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  # === UI ===
63
  about_text = """
 
53
  messages.append({"role": "user", "content": message})
54
 
55
  response = ""
56
+
57
+ # for msg in client.chat_completion(messages, max_tokens=500, temperature=.1, stream=True):
58
+ # token = msg.choices[0].delta.content
59
+ # if token:
60
+ # response += token
61
+ # return response
62
+
63
+
64
+ # iterate through each message in the method
65
+ try:
66
+ for message in client.chat_completion(
67
+ messages,
68
+ max_tokens=500,
69
+ temperature=0.1,
70
+ stream=True
71
+ ):
72
+ # add the tokens to the output content
73
+ token = message.choices[0].delta.content # capture the most recent token
74
+ response += token # Add it to the response
75
+ yield response # yield the response
76
+
77
+ except Exception as e:
78
+ print(f"An error occurred: {e}")
79
 
80
  # === UI ===
81
  about_text = """