seawolf2357 commited on
Commit
900fa0f
1 Parent(s): f9a359c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -51,13 +51,17 @@ async def respond(
51
  chunk_data = chunk.decode('utf-8')
52
  response_json = json.loads(chunk_data)
53
  if "choices" in response_json:
54
- delta = response_json["choices"][0].get("delta", {})
55
- if "content" in delta:
56
- content = delta["content"]
57
- yield content
58
  except json.JSONDecodeError:
59
- # 로그 기록하거나 다른 방법으로 처리
60
- pass # 'continue' 대신 'pass' 사용
 
 
 
 
 
 
61
 
62
  theme = "Nymbo/Nymbo_Theme"
63
 
 
51
  chunk_data = chunk.decode('utf-8')
52
  response_json = json.loads(chunk_data)
53
  if "choices" in response_json:
54
+ content = response_json["choices"][0]["message"]["content"]
55
+ yield content
 
 
56
  except json.JSONDecodeError:
57
+ # Log the error or handle it appropriately
58
+ pass
59
+ except StopAsyncIteration:
60
+ # Handle the case where the stream is prematurely terminated
61
+ pass
62
+ finally:
63
+ # Ensure that the generator is properly closed
64
+ yield "Stream ended"
65
 
66
  theme = "Nymbo/Nymbo_Theme"
67