AIRider commited on
Commit
0f2c971
1 Parent(s): 4b530fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -17
app.py CHANGED
@@ -27,7 +27,7 @@ def respond(
27
  system_message,
28
  ):
29
  try:
30
- client = get_client(model_name) # 여기서 client를 정의합니다.
31
  except ValueError as e:
32
  chat_history.append((message, str(e)))
33
  return chat_history
@@ -39,22 +39,35 @@ def respond(
39
  messages.append({"role": "user", "content": message})
40
 
41
  try:
42
- stream = client.chat_completion(
43
- messages,
44
- max_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
- if len(chat_history) > 0 and chat_history[-1][0] == message:
54
- chat_history[-1] = (message, partial_message)
55
- else:
56
- chat_history.append((message, partial_message))
57
- yield chat_history
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  except Exception as e:
59
  error_message = f"An error occurred: {str(e)}"
60
  chat_history.append((message, error_message))
 
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
 
39
  messages.append({"role": "user", "content": message})
40
 
41
  try:
42
+ if "Cohere" in model_name:
43
+ # Cohere 모델을 위한 비스트리밍 처리
44
+ response = client.chat_completion(
45
+ messages,
46
+ max_tokens=max_tokens,
47
+ temperature=temperature,
48
+ top_p=top_p,
49
+ )
50
+ assistant_message = response.choices[0].message.content
51
+ chat_history.append((message, assistant_message))
52
+ yield chat_history
53
+ else:
54
+ # 다른 모델들을 위한 스트리밍 처리
55
+ stream = client.chat_completion(
56
+ messages,
57
+ max_tokens=max_tokens,
58
+ temperature=temperature,
59
+ top_p=top_p,
60
+ stream=True,
61
+ )
62
+ partial_message = ""
63
+ for response in stream:
64
+ if response.choices[0].delta.content is not None:
65
+ partial_message += response.choices[0].delta.content
66
+ if len(chat_history) > 0 and chat_history[-1][0] == message:
67
+ chat_history[-1] = (message, partial_message)
68
+ else:
69
+ chat_history.append((message, partial_message))
70
+ yield chat_history
71
  except Exception as e:
72
  error_message = f"An error occurred: {str(e)}"
73
  chat_history.append((message, error_message))