From 938e2eb0b1ee9ac65eb4a494c9b4083b27be3ce6 Mon Sep 17 00:00:00 2001 From: Felipe Galindo Sanchez Date: Tue, 8 Oct 2024 09:18:15 -0700 Subject: [PATCH] Include current URL in the message payload (#1403) Co-authored-by: Mathijs de Bruin --- backend/chainlit/message.py | 5 ++--- libs/copilot/src/components/InputBox.tsx | 3 ++- libs/react-client/src/types/step.ts | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/chainlit/message.py b/backend/chainlit/message.py index 7bb590f8be..051089c119 100644 --- a/backend/chainlit/message.py +++ b/backend/chainlit/message.py @@ -59,7 +59,7 @@ def __post_init__(self) -> None: @classmethod def from_dict(self, _dict: StepDict): type = _dict.get("type", "assistant_message") - message = Message( + return Message( id=_dict["id"], parent_id=_dict.get("parentId"), created_at=_dict["createdAt"], @@ -67,10 +67,9 @@ def from_dict(self, _dict: StepDict): author=_dict.get("name", config.ui.name), type=type, # type: ignore language=_dict.get("language"), + metadata=_dict.get("metadata", {}), ) - return message - def to_dict(self) -> StepDict: _dict: StepDict = { "id": self.id, diff --git a/libs/copilot/src/components/InputBox.tsx b/libs/copilot/src/components/InputBox.tsx index e9c31150f4..054cc61bbc 100644 --- a/libs/copilot/src/components/InputBox.tsx +++ b/libs/copilot/src/components/InputBox.tsx @@ -45,7 +45,8 @@ const InputBox = memo( name: user?.identifier || 'User', type: 'user_message', output: msg, - createdAt: new Date().toISOString() + createdAt: new Date().toISOString(), + metadata: {location: window.location.href}, }; setInputHistory((old) => { diff --git a/libs/react-client/src/types/step.ts b/libs/react-client/src/types/step.ts index c631aab088..7ef69c89d4 100644 --- a/libs/react-client/src/types/step.ts +++ b/libs/react-client/src/types/step.ts @@ -30,6 +30,7 @@ export interface IStep { language?: string; streaming?: boolean; steps?: IStep[]; + metadata?: Record; //legacy indent?: number; }