seawolf2357 commited on
Commit
85f74eb
โ€ข
1 Parent(s): e83c18e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -19
app.py CHANGED
@@ -14,35 +14,38 @@ def respond(
14
  temperature,
15
  top_p,
16
  ):
17
-
18
  system_prefix = """
19
  If the input language is Korean, respond in Korean. If it's English, respond in English.
20
- ๋™์‹œ์— ๋‘๊ฐ€์ง€ ์–ธ์–ด๋ฅผ ์ถœ๋ ฅํ•˜์ง€ ๋ง๊ฒƒ. ๋ฐ˜๋“œ์‹œ ํ•œ๊ตญ์–ด ์งˆ๋ฌธ์—๋Š” ํ•œ๊ตญ์–ด๋กœ ๋‹ต๋ณ€ํ•˜๊ณ , ์˜์–ด ์งˆ๋ฌธ์—๋Š” ์˜์–ด๋กœ๋งŒ ๋‹ต๋ณ€ํ•˜๋ผ
21
  """
22
 
23
- messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}] # Add prefix
24
 
25
- for val in history:
26
- if val[0]:
27
- messages.append({"role": "user", "content": val[0]})
28
- if val[1]:
29
- messages.append({"role": "assistant", "content": val[1]})
30
 
 
31
  messages.append({"role": "user", "content": message})
32
 
33
  response = ""
34
 
35
- for message in hf_client.chat_completion(
36
- messages,
37
- max_tokens=max_tokens,
38
- stream=True,
39
- temperature=temperature,
40
- top_p=top_p,
41
- ):
42
- token = message.choices[0].delta.content
43
- if token is not None:
44
- response += token.strip("") # Remove tokens
45
- yield response
 
 
 
46
 
47
 
48
  theme = "Nymbo/Nymbo_Theme"
 
14
  temperature,
15
  top_p,
16
  ):
 
17
  system_prefix = """
18
  If the input language is Korean, respond in Korean. If it's English, respond in English.
19
+ Do not output in both languages simultaneously. Always respond in Korean to Korean questions and in English to English questions.
20
  """
21
 
22
+ messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
23
 
24
+ # Ensure alternating user/assistant messages
25
+ for user_msg, assistant_msg in history:
26
+ messages.append({"role": "user", "content": user_msg})
27
+ if assistant_msg: # Only add assistant message if it exists
28
+ messages.append({"role": "assistant", "content": assistant_msg})
29
 
30
+ # Add the current user message
31
  messages.append({"role": "user", "content": message})
32
 
33
  response = ""
34
 
35
+ try:
36
+ for message in hf_client.chat_completion(
37
+ messages,
38
+ max_tokens=max_tokens,
39
+ stream=True,
40
+ temperature=temperature,
41
+ top_p=top_p,
42
+ ):
43
+ token = message.choices[0].delta.content
44
+ if token is not None:
45
+ response += token.strip("")
46
+ yield response
47
+ except Exception as e:
48
+ yield f"An error occurred: {str(e)}"
49
 
50
 
51
  theme = "Nymbo/Nymbo_Theme"