Merge pull request #3234 from hwuiwon/hw/bugfix-llmcontext
Fix LLM context tool audio content handling
This commit is contained in:
1
changelog/3234.fixed.md
Normal file
1
changelog/3234.fixed.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
- Fix a bug in LLM context audio content handling
|
||||||
@@ -187,13 +187,12 @@ class LLMContext:
|
|||||||
audio_frames: List of audio frame objects to include.
|
audio_frames: List of audio frame objects to include.
|
||||||
text: Optional text to include with the audio.
|
text: Optional text to include with the audio.
|
||||||
"""
|
"""
|
||||||
|
content = [{"type": "text", "text": text}]
|
||||||
|
|
||||||
async def encode_audio():
|
async def encode_audio():
|
||||||
sample_rate = audio_frames[0].sample_rate
|
sample_rate = audio_frames[0].sample_rate
|
||||||
num_channels = audio_frames[0].num_channels
|
num_channels = audio_frames[0].num_channels
|
||||||
|
|
||||||
content = []
|
|
||||||
content.append({"type": "text", "text": text})
|
|
||||||
data = b"".join(frame.audio for frame in audio_frames)
|
data = b"".join(frame.audio for frame in audio_frames)
|
||||||
|
|
||||||
with io.BytesIO() as buffer:
|
with io.BytesIO() as buffer:
|
||||||
@@ -203,7 +202,7 @@ class LLMContext:
|
|||||||
wf.setframerate(sample_rate)
|
wf.setframerate(sample_rate)
|
||||||
wf.writeframes(data)
|
wf.writeframes(data)
|
||||||
|
|
||||||
encoded_audio = base64.b64encode(buffer.getvalue()).decode("utf-8")
|
encoded_audio = base64.b64encode(buffer.getvalue()).decode("utf-8")
|
||||||
return encoded_audio
|
return encoded_audio
|
||||||
|
|
||||||
encoded_audio = await asyncio.to_thread(encode_audio)
|
encoded_audio = await asyncio.to_thread(encode_audio)
|
||||||
|
|||||||
Reference in New Issue
Block a user