Spaces:
Sleeping
Sleeping
yield response
Browse files
app.py
CHANGED
|
@@ -6,19 +6,24 @@ from huggingface_hub import InferenceClient
|
|
| 6 |
#AI API being used
|
| 7 |
client= InferenceClient("Qwen/Qwen2.5-7B-Instruct-1M")
|
| 8 |
|
|
|
|
|
|
|
| 9 |
#defining role of AI and user
|
| 10 |
def respond(message,history):
|
| 11 |
-
|
| 12 |
-
messages = [{"role": "system", "content":
|
| 13 |
|
| 14 |
if history:
|
| 15 |
messages.extend(history) #keep adding history
|
| 16 |
|
| 17 |
messages.append({"role":"user", "content": message})
|
| 18 |
|
| 19 |
-
response=client.chat_completion(messages, temperature=0.8, max_tokens=300) #capping how many words the LLM is allowed to generate as a respond (300 words)
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
#Defining chatbot giving user a UI to interact, see their conversation history, and see new messages using built in gr feature
|
|
|
|
| 6 |
#AI API being used
|
| 7 |
client= InferenceClient("Qwen/Qwen2.5-7B-Instruct-1M")
|
| 8 |
|
| 9 |
+
response=""
|
| 10 |
+
|
| 11 |
#defining role of AI and user
|
| 12 |
def respond(message,history):
|
| 13 |
+
system_message: "You are acting like a comforting, guiding parent helping their child navigate academia."
|
| 14 |
+
messages = [{"role": "system", "content": system_message}]
|
| 15 |
|
| 16 |
if history:
|
| 17 |
messages.extend(history) #keep adding history
|
| 18 |
|
| 19 |
messages.append({"role":"user", "content": message})
|
| 20 |
|
| 21 |
+
response=client.chat_completion(messages, temperature=0.8, stream=True, max_tokens=300) #capping how many words the LLM is allowed to generate as a respond (300 words)
|
| 22 |
|
| 23 |
+
for message in client.chat_completion():
|
| 24 |
+
token=message.choices[0].delta.content
|
| 25 |
+
response+=token
|
| 26 |
+
yield response['choices'][0]['message']['content'].strip() #storing value of response in a readable format to display
|
| 27 |
|
| 28 |
|
| 29 |
#Defining chatbot giving user a UI to interact, see their conversation history, and see new messages using built in gr feature
|