Save progress
This commit is contained in:
@@ -172,7 +172,8 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
"I can help you with weather information, share interesting facts, "
|
"I can help you with weather information, share interesting facts, "
|
||||||
"or just have a conversation. What would you like to know?"
|
"or just have a conversation. What would you like to know?"
|
||||||
),
|
),
|
||||||
EndFrame(),
|
# Don't send EndFrame() here - that closes the pipeline!
|
||||||
|
# The conversation should continue after the greeting
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -288,6 +288,8 @@ class OpenAIAgentService(AIService):
|
|||||||
self._agent, input_text, context=self._session_config
|
self._agent, input_text, context=self._session_config
|
||||||
)
|
)
|
||||||
|
|
||||||
|
has_streaming_deltas = False
|
||||||
|
|
||||||
# Process the stream events
|
# Process the stream events
|
||||||
async for event in result.stream_events():
|
async for event in result.stream_events():
|
||||||
if event.type == "raw_response_event":
|
if event.type == "raw_response_event":
|
||||||
@@ -296,19 +298,23 @@ class OpenAIAgentService(AIService):
|
|||||||
if hasattr(event.data, "delta") and getattr(event.data, "delta", None):
|
if hasattr(event.data, "delta") and getattr(event.data, "delta", None):
|
||||||
delta_text = getattr(event.data, "delta", "")
|
delta_text = getattr(event.data, "delta", "")
|
||||||
if delta_text:
|
if delta_text:
|
||||||
|
has_streaming_deltas = True
|
||||||
|
self._accumulated_text += delta_text
|
||||||
await self.push_frame(LLMTextFrame(text=delta_text))
|
await self.push_frame(LLMTextFrame(text=delta_text))
|
||||||
|
|
||||||
elif event.type == "run_item_stream_event":
|
elif event.type == "run_item_stream_event":
|
||||||
# Handle completed items
|
# Handle completed items
|
||||||
if event.item.type == "message_output_item":
|
if event.item.type == "message_output_item":
|
||||||
# Get the complete message text
|
# Only process complete message if we didn't get streaming deltas
|
||||||
message_text = self._extract_message_text(event.item)
|
if not has_streaming_deltas:
|
||||||
if message_text and message_text != self._accumulated_text:
|
message_text = self._extract_message_text(event.item)
|
||||||
# Send any new text that wasn't already streamed
|
logger.debug(
|
||||||
new_text = message_text[len(self._accumulated_text) :]
|
f"Processing complete message (no deltas): {message_text[:50]}..."
|
||||||
if new_text:
|
if len(message_text) > 50
|
||||||
await self.push_frame(LLMTextFrame(text=new_text))
|
else f"Processing complete message: {message_text}"
|
||||||
self._accumulated_text = message_text
|
)
|
||||||
|
if message_text:
|
||||||
|
await self.push_frame(LLMTextFrame(text=message_text))
|
||||||
|
|
||||||
elif event.item.type == "tool_call_item":
|
elif event.item.type == "tool_call_item":
|
||||||
# Use getattr for safe attribute access
|
# Use getattr for safe attribute access
|
||||||
@@ -359,8 +365,27 @@ class OpenAIAgentService(AIService):
|
|||||||
The extracted text content.
|
The extracted text content.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Handle different message item formats
|
# Handle OpenAI Agents SDK MessageOutputItem format
|
||||||
if hasattr(item, "content"):
|
if hasattr(item, "raw_item") and hasattr(item.raw_item, "content"):
|
||||||
|
content = item.raw_item.content
|
||||||
|
if isinstance(content, list):
|
||||||
|
text_parts = []
|
||||||
|
for content_part in content:
|
||||||
|
if hasattr(content_part, "text"):
|
||||||
|
text_parts.append(content_part.text)
|
||||||
|
elif (
|
||||||
|
isinstance(content_part, dict)
|
||||||
|
and content_part.get("type") == "output_text"
|
||||||
|
):
|
||||||
|
text_parts.append(content_part.get("text", ""))
|
||||||
|
elif isinstance(content_part, dict) and content_part.get("type") == "text":
|
||||||
|
text_parts.append(content_part.get("text", ""))
|
||||||
|
return "".join(text_parts)
|
||||||
|
elif isinstance(content, str):
|
||||||
|
return content
|
||||||
|
|
||||||
|
# Handle direct content attribute
|
||||||
|
elif hasattr(item, "content"):
|
||||||
if isinstance(item.content, str):
|
if isinstance(item.content, str):
|
||||||
return item.content
|
return item.content
|
||||||
elif isinstance(item.content, list):
|
elif isinstance(item.content, list):
|
||||||
@@ -373,8 +398,9 @@ class OpenAIAgentService(AIService):
|
|||||||
text_parts.append(content_part)
|
text_parts.append(content_part)
|
||||||
return "".join(text_parts)
|
return "".join(text_parts)
|
||||||
|
|
||||||
# Fallback: try to get text through string conversion
|
# If no text content found, return empty string instead of str(item)
|
||||||
return str(item)
|
logger.debug(f"No extractable text content found in item: {type(item)}")
|
||||||
|
return ""
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Could not extract text from message item: {e}")
|
logger.warning(f"Could not extract text from message item: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user