🐛 fix(callback.py): remove "Prompt after formatting" from text before sending it as a prompt to the frontend

 feat(callback.py): send an empty message with the prompt to the frontend when "Prompt after formatting" is in the text
🐛 fix(schemas.py): make the prompt field optional in the ChatResponse schema
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-23 09:55:03 -03:00
commit 4cb647ad47
2 changed files with 10 additions and 0 deletions

View file

@ -104,6 +104,15 @@ class AsyncStreamingLLMCallbackHandler(AsyncCallbackHandler):
# This runs when first sending the prompt
# to the LLM, adding it will send the final prompt
# to the frontend
if "Prompt after formatting" in text:
text = text.replace("Prompt after formatting", "")
resp = ChatResponse(
message="",
type="stream",
intermediate_steps="",
prompt=text,
)
await self.websocket.send_json(resp.dict())
async def on_agent_action(self, action: AgentAction, **kwargs: Any):
log = f"Thought: {action.log}"

View file

@ -61,6 +61,7 @@ class ChatResponse(ChatMessage):
"""Chat response schema."""
intermediate_steps: str
prompt: Optional[str] = ""
type: str
is_bot: bool = True
files: list = []