AIRider commited on
Commit
3a4c978
·
verified ·
1 Parent(s): af9bced

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -25
app.py CHANGED
@@ -27,31 +27,23 @@ def respond(
27
  system_message,
28
  ):
29
  try:
30
- client = get_client(model_name)
31
- except ValueError as e:
32
- chat_history.append((message, str(e)))
33
- return chat_history
34
-
35
- messages = [{"role": "system", "content": system_message}]
36
- for human, assistant in chat_history:
37
- messages.append({"role": "user", "content": human})
38
- messages.append({"role": "assistant", "content": assistant})
39
- messages.append({"role": "user", "content": message})
40
-
41
- try:
42
- stream = client.chat_completion(
43
- messages,
44
- max_tokens=max_tokens, # 'max_new_tokens'에서 'max_tokens'로 변경
45
- temperature=temperature,
46
- top_p=top_p,
47
- stream=True,
48
- )
49
- partial_message = ""
50
- for response in stream:
51
- if response.choices[0].delta.content is not None:
52
- partial_message += response.choices[0].delta.content
53
- chat_history = chat_history[:-1] + [(message, partial_message)]
54
- yield chat_history
55
 
56
  def clear_conversation():
57
  return []
 
27
  system_message,
28
  ):
29
  try:
30
+ stream = client.chat_completion(
31
+ messages,
32
+ max_tokens=max_tokens,
33
+ temperature=temperature,
34
+ top_p=top_p,
35
+ stream=True,
36
+ )
37
+ partial_message = ""
38
+ for response in stream:
39
+ if response.choices[0].delta.content is not None:
40
+ partial_message += response.choices[0].delta.content
41
+ chat_history = chat_history[:-1] + [(message, partial_message)]
42
+ yield chat_history
43
+ except Exception as e:
44
+ error_message = f"An error occurred: {str(e)}"
45
+ chat_history.append((message, error_message))
46
+ yield chat_history
 
 
 
 
 
 
 
 
47
 
48
  def clear_conversation():
49
  return []