Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add initialization chat message_list parameter #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Use the widget API to customize your widget:
| window_title | string | No |
| session_id | string | No |
| additional_headers | json | No |
| message_list | json | No |

- **api_key:**
- Type: String
Expand Down Expand Up @@ -261,6 +262,10 @@ Use the widget API to customize your widget:
- Required: No
- Description: Additional headers to be sent to Langflow server

- **message_list:**
- Type: JSON
- Required: No
- Description: Chat message list. eg. [{"message": string ,"isSend": boolean }]

## Live example:
Try out or [live example](https://codesandbox.io/s/langflow-embedded-chat-example-dv9zpx) to see how the Langflow Embedded Chat ⛓️ works.
Expand Down
2 changes: 1 addition & 1 deletion dist/build/static/js/bundle.min.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
<title>Document</title>
</head>
<body style="width: 100vh; height: 100vh; ">
<langflow-chat window_title="Langflow Chat"
flow_id="4317421c-d4b5-4a22-bc7b-05e8af053b0e"
<langflow-chat window_title="Langflow Chat"
host_url="http://localhost:7860"
width="700"
></langflow-chat>
flow_id='0a68660c-025e-46c1-9ca9-691e5854136b'
session_id='184426d9-80b9-47ed-86a5-4486bec38b46'
message_list='[{"message": "hello langflow!","isSend":true}, {"message": "hello!","isSend": false}]'
>
</langflow-chat>
</body>
</html>
4 changes: 3 additions & 1 deletion src/chatWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function ChatWidget({
additional_headers,
session_id,
start_open=false,
message_list=[],
}: {
api_key?: string;
input_value: string,
Expand Down Expand Up @@ -63,9 +64,10 @@ export default function ChatWidget({
additional_headers?: { [key: string]: string };
session_id?: string;
start_open?: boolean;
message_list: ChatMessageType[];
}) {
const [open, setOpen] = useState(start_open);
const [messages, setMessages] = useState<ChatMessageType[]>([]);
const [messages, setMessages] = useState<ChatMessageType[]>(message_list);
const sessionId = useRef(session_id ?? uuidv4());
function updateLastMessage(message: ChatMessageType) {
setMessages((prev) => {
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ customElements.define('langflow-chat', r2wc(ChatWidget, {
input_container_style:"json",
chat_position:"string",
additional_headers:"json",
message_list:"json",
},
}));