ferrywuai commited on
Commit
5a2eb52
·
1 Parent(s): 4c61f8e

Connect user input to HF chatCompletion and display assistant response

Browse files

modified: README.md
modified: src/components/ChatInterface.jsx

Files changed (2) hide show
  1. README.md +1 -2
  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
- - Test dummy user input and show response in console log.
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 { useEffect, useState } from "react";
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
- useEffect(() => {
10
- const testHF = async () => {
11
- const result = await hf.chatCompletion({
12
- model: "openai/gpt-oss-20b",
13
- messages: [{ role: "user", content: "Hello!" }],
14
- });
15
- console.log("HF:", result.choices[0].message.content);
16
- };
17
 
18
- testHF();
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