Spaces:
Running
Running
Connect user input to HF chatCompletion and display assistant response
Browse filesmodified: README.md
modified: src/components/ChatInterface.jsx
- README.md +1 -2
- src/components/ChatInterface.jsx +8 -16
README.md
CHANGED
|
@@ -18,8 +18,7 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo
|
|
| 18 |
## Features
|
| 19 |
|
| 20 |
- Get Hugging Face Access Token from environment variable.
|
| 21 |
-
-
|
| 22 |
-
- Support UI to send user input and get dummy response.
|
| 23 |
- Keep user input and response in chat history.
|
| 24 |
|
| 25 |
## Usage
|
|
|
|
| 18 |
## Features
|
| 19 |
|
| 20 |
- Get Hugging Face Access Token from environment variable.
|
| 21 |
+
- Support UI to send user input and get response of the chatbot.
|
|
|
|
| 22 |
- Keep user input and response in chat history.
|
| 23 |
|
| 24 |
## Usage
|
src/components/ChatInterface.jsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import {
|
| 2 |
import { hf } from "../utils/hfClient";
|
| 3 |
import MessageInput from "./MessageInput";
|
| 4 |
import MessagePair from "./MessagePair";
|
|
@@ -6,22 +6,14 @@ import MessagePair from "./MessagePair";
|
|
| 6 |
export default function ChatInterface() {
|
| 7 |
const [chatHistory, setChatHistory] = useState([]);
|
| 8 |
|
| 9 |
-
|
| 10 |
-
const
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
});
|
| 15 |
-
console.log("HF:", result.choices[0].message.content);
|
| 16 |
-
};
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
const handleMessageSend = (message) => {
|
| 22 |
-
const fakeResponse =
|
| 23 |
-
"This is a simulated response.\nIt can span multiple lines.";
|
| 24 |
-
const newPair = { user: message, assistant: fakeResponse };
|
| 25 |
setChatHistory([newPair, ...chatHistory]);
|
| 26 |
};
|
| 27 |
|
|
|
|
| 1 |
+
import { useState } from "react";
|
| 2 |
import { hf } from "../utils/hfClient";
|
| 3 |
import MessageInput from "./MessageInput";
|
| 4 |
import MessagePair from "./MessagePair";
|
|
|
|
| 6 |
export default function ChatInterface() {
|
| 7 |
const [chatHistory, setChatHistory] = useState([]);
|
| 8 |
|
| 9 |
+
const handleMessageSend = async (message) => {
|
| 10 |
+
const result = await hf.chatCompletion({
|
| 11 |
+
model: "openai/gpt-oss-20b",
|
| 12 |
+
messages: [{ role: "user", content: message }],
|
| 13 |
+
});
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
const assistantReply = result.choices[0].message.content;
|
| 16 |
+
const newPair = { user: message, assistant: assistantReply };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
setChatHistory([newPair, ...chatHistory]);
|
| 18 |
};
|
| 19 |
|