Spaces:
Sleeping
Sleeping
update respond func
Browse files
app.py
CHANGED
@@ -9,37 +9,17 @@ For more information on `huggingface_hub` Inference API support, please check th
|
|
9 |
client = InferenceClient("EleutherAI/gpt-neo-125M")
|
10 |
|
11 |
|
12 |
-
def respond(
|
13 |
-
message,
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
top_p,
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
if val[0]:
|
24 |
-
messages.append({"role": "user", "content": val[0]})
|
25 |
-
if val[1]:
|
26 |
-
messages.append({"role": "assistant", "content": val[1]})
|
27 |
-
|
28 |
-
messages.append({"role": "user", "content": message})
|
29 |
-
|
30 |
-
response = ""
|
31 |
-
|
32 |
-
for message in client.chat_completion(
|
33 |
-
messages,
|
34 |
-
max_tokens=max_tokens,
|
35 |
-
stream=True,
|
36 |
-
temperature=temperature,
|
37 |
-
top_p=top_p,
|
38 |
-
):
|
39 |
-
token = message.choices[0].delta.content
|
40 |
-
|
41 |
-
response += token
|
42 |
-
yield response
|
43 |
|
44 |
"""
|
45 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
9 |
client = InferenceClient("EleutherAI/gpt-neo-125M")
|
10 |
|
11 |
|
12 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
13 |
+
# Construct the prompt with system message, history, and user input
|
14 |
+
prompt = system_message + "\n" + "\n".join([f"User: {msg[0]}\nAssistant: {msg[1]}" for msg in history if msg[0] and msg[1]])
|
15 |
+
prompt += f"\nUser: {message}\nAssistant:"
|
16 |
+
|
17 |
+
# Generate a response using the model
|
18 |
+
response = client(prompt, max_length=max_tokens, temperature=temperature, top_p=top_p, do_sample=True)[0]['generated_text']
|
19 |
+
|
20 |
+
# Extract the assistant's response part (after "Assistant:")
|
21 |
+
assistant_response = response.split("Assistant:", 1)[-1].strip()
|
22 |
+
return assistant_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
"""
|
25 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|