shuhayas commited on
Commit
e28e99e
·
verified ·
1 Parent(s): ac891f5
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -23,8 +23,10 @@ async def generate_stream(prompt, model="gpt-4o", max_tokens=2048):
23
  stream=True
24
  )
25
  async for chunk in response:
26
- delta = chunk.choices[0].delta.get("content", "")
27
- yield delta
 
 
28
 
29
  async def generate_content(prompt, model="gpt-4o", max_tokens=2048):
30
  """
@@ -32,7 +34,6 @@ async def generate_content(prompt, model="gpt-4o", max_tokens=2048):
32
  """
33
  content = ""
34
  placeholder = st.empty()
35
- # チャンク毎に表示を更新
36
  async for delta in generate_stream(prompt, model, max_tokens):
37
  content += delta
38
  placeholder.write(content)
 
23
  stream=True
24
  )
25
  async for chunk in response:
26
+ # chunk.choices[0].delta は ChoiceDelta オブジェクトなので .content を使う
27
+ delta_obj = chunk.choices[0].delta
28
+ if hasattr(delta_obj, "content") and delta_obj.content:
29
+ yield delta_obj.content
30
 
31
  async def generate_content(prompt, model="gpt-4o", max_tokens=2048):
32
  """
 
34
  """
35
  content = ""
36
  placeholder = st.empty()
 
37
  async for delta in generate_stream(prompt, model, max_tokens):
38
  content += delta
39
  placeholder.write(content)