fix: preserve camera permission intent and distinguish unknown reply expression
This commit is contained in:
+17
-3
@@ -472,6 +472,8 @@ class Dialogue:
|
||||
messages = [{'role': 'system', 'content': system}] + self.contexts.get(turn, []) + [{'role': 'user', 'content': text}]
|
||||
url, headers, body = self.llm_provider.request(messages, max_tokens=160)
|
||||
raw_body = ''
|
||||
finish_reason = 'not_provided'
|
||||
usage = {}
|
||||
async with asyncio.timeout(30):
|
||||
async with self.client.stream('POST', url, headers=headers, json=body) as response:
|
||||
response.raise_for_status()
|
||||
@@ -483,7 +485,15 @@ class Dialogue:
|
||||
raw = '\n'.join(event_data); event_data = []
|
||||
if raw == '[DONE]': break
|
||||
data = json.loads(raw)
|
||||
reported_usage = data.get('usage')
|
||||
if isinstance(reported_usage, dict):
|
||||
for key in ('prompt_tokens', 'completion_tokens', 'total_tokens'):
|
||||
value = reported_usage.get(key)
|
||||
if type(value) is int and 0 <= value <= 10_000_000: usage[key] = value
|
||||
for choice in data.get('choices', []):
|
||||
reported_finish = choice.get('finish_reason')
|
||||
if reported_finish is not None:
|
||||
finish_reason = reported_finish if reported_finish in ('stop', 'length', 'content_filter', 'tool_calls', 'function_call') else 'unknown'
|
||||
delta = choice.get('delta', {}).get('content') or ''
|
||||
if not delta: continue
|
||||
metrics.setdefault('llm_first_token_ms', round((time.perf_counter() - request_start) * 1000, 2))
|
||||
@@ -492,7 +502,10 @@ class Dialogue:
|
||||
if turn != self.turn: return
|
||||
if not raw_body.strip(): raise ValueError('empty LLM body')
|
||||
parse_start = time.perf_counter()
|
||||
result = parse_reply(raw_body)
|
||||
result = parse_reply(raw_body, finish_reason=finish_reason)
|
||||
metrics.update(reply_emotion_reason=result.reason, reply_parse_branch=result.parse_branch,
|
||||
reply_emotion=result.emotion, reply_intensity=result.intensity,
|
||||
llm_finish_reason=finish_reason, llm_usage=usage, llm_max_tokens=body['max_tokens'])
|
||||
metrics['reply_parse_ms'] = round((time.perf_counter() - parse_start) * 1000, 2)
|
||||
metrics['reply_emotion_source'] = result.source
|
||||
metrics['llm_first_body_ms'] = round((time.perf_counter() - request_start) * 1000, 2)
|
||||
@@ -501,7 +514,8 @@ class Dialogue:
|
||||
# Only the extracted reply enters events, persistent history and the single TTS generator.
|
||||
self.answers[turn] = result.reply
|
||||
await self.event('llm', turn, text=result.reply)
|
||||
await self.event('reply.emotion', turn, emotion=result.emotion, intensity=result.intensity, source=result.source)
|
||||
await self.event('reply.emotion', turn, emotion=result.emotion, intensity=result.intensity, source=result.source, reason=result.reason, parse_branch=result.parse_branch,
|
||||
finish_reason=finish_reason, usage=usage)
|
||||
await self.event('llm.finished', turn, voice_mode=self.voice_mode, llm_finished_ms=metrics['llm_finished_ms'])
|
||||
async def enqueue(fragment):
|
||||
if fragment:
|
||||
@@ -536,7 +550,7 @@ class Dialogue:
|
||||
self.debug_captures[turn] = await asyncio.to_thread(self.debug_store.create, {'run_id':self.run_id,'conversation_id':self.conversation_id,'turn_id':turn,'voice_id':self.voice_id,'voice_mode':self.voice_mode,'persona':self.persona,'tts_requests':[]})
|
||||
capture = self.debug_captures.get(turn)
|
||||
if capture:
|
||||
capture.meta['tts_requests'].append({'input':text,'parameters':{'model':'openbmb/VoxCPM2','voice':self.voice_id,'stream':True},'request_number':sentence})
|
||||
capture.meta['tts_requests'].append({'input_chars':len(text),'parameters':{'model':'openbmb/VoxCPM2','voice':self.voice_id,'stream':True},'request_number':sentence})
|
||||
async with asyncio.timeout(30):
|
||||
async with self.client.stream('POST', 'http://192.168.31.61:5002/v1/audio/speech', json={'model': 'openbmb/VoxCPM2', 'input': text, 'voice': self.voice_id, 'stream': True}) as response:
|
||||
response.raise_for_status()
|
||||
|
||||
Reference in New Issue
Block a user