seawolf2357 commited on
Commit
3e050a6
โ€ข
1 Parent(s): e2b30b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -57,14 +57,17 @@ def respond(
57
  for chunk in response.iter_content(chunk_size=None):
58
  if chunk:
59
  chunk_data = chunk.decode('utf-8')
60
- response_json = json.loads(chunk_data)
61
- # content ์˜์—ญ๋งŒ ์ถœ๋ ฅ
62
- if "choices" in response_json:
63
- content = response_json["choices"][0]["message"]["content"]
64
- response_text = content
65
- # ๋งˆ์ง€๋ง‰ ๋Œ€ํ™”์— ๋ชจ๋ธ์˜ ์‘๋‹ต์„ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅ
66
- memory[-1] = (message, response_text)
67
- yield content
 
 
 
68
 
69
  theme = "Nymbo/Nymbo_Theme"
70
 
@@ -81,4 +84,4 @@ demo = gr.ChatInterface(
81
  )
82
 
83
  if __name__ == "__main__":
84
- demo.queue().launch(max_threads=20) # max_threads๋ฅผ launch() ๋ฉ”์„œ๋“œ์— ์„ค์ •
 
57
  for chunk in response.iter_content(chunk_size=None):
58
  if chunk:
59
  chunk_data = chunk.decode('utf-8')
60
+ try:
61
+ response_json = json.loads(chunk_data)
62
+ # content ์˜์—ญ๋งŒ ์ถœ๋ ฅ
63
+ if "choices" in response_json:
64
+ content = response_json["choices"][0]["message"]["content"]
65
+ response_text = content
66
+ # ๋งˆ์ง€๋ง‰ ๋Œ€ํ™”์— ๋ชจ๋ธ์˜ ์‘๋‹ต์„ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅ
67
+ memory[-1] = (message, response_text)
68
+ yield content
69
+ except json.JSONDecodeError:
70
+ continue # ์œ ํšจํ•˜์ง€ ์•Š์€ JSON์ด ์žˆ์„ ๊ฒฝ์šฐ ๋ฌด์‹œํ•˜๊ณ  ๋‹ค์Œ ์ฒญํฌ๋กœ ๋„˜์–ด๊ฐ
71
 
72
  theme = "Nymbo/Nymbo_Theme"
73
 
 
84
  )
85
 
86
  if __name__ == "__main__":
87
+ demo.queue().launch(max_threads=20)