From 4cb647ad47c4017386253670e7e56606f510e60f Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 23 Aug 2023 09:55:03 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(callback.py):=20remove=20"Pr?= =?UTF-8?q?ompt=20after=20formatting"=20from=20text=20before=20sending=20i?= =?UTF-8?q?t=20as=20a=20prompt=20to=20the=20frontend=20=E2=9C=A8=20feat(ca?= =?UTF-8?q?llback.py):=20send=20an=20empty=20message=20with=20the=20prompt?= =?UTF-8?q?=20to=20the=20frontend=20when=20"Prompt=20after=20formatting"?= =?UTF-8?q?=20is=20in=20the=20text=20=F0=9F=90=9B=20fix(schemas.py):=20mak?= =?UTF-8?q?e=20the=20prompt=20field=20optional=20in=20the=20ChatResponse?= =?UTF-8?q?=20schema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/callback.py | 9 +++++++++ src/backend/langflow/api/v1/schemas.py | 1 + 2 files changed, 10 insertions(+) diff --git a/src/backend/langflow/api/v1/callback.py b/src/backend/langflow/api/v1/callback.py index 69dbf5082..d465f8684 100644 --- a/src/backend/langflow/api/v1/callback.py +++ b/src/backend/langflow/api/v1/callback.py @@ -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}" diff --git a/src/backend/langflow/api/v1/schemas.py b/src/backend/langflow/api/v1/schemas.py index de0348d38..27de03083 100644 --- a/src/backend/langflow/api/v1/schemas.py +++ b/src/backend/langflow/api/v1/schemas.py @@ -61,6 +61,7 @@ class ChatResponse(ChatMessage): """Chat response schema.""" intermediate_steps: str + prompt: Optional[str] = "" type: str is_bot: bool = True files: list = []