Update app.py
Browse files
app.py
CHANGED
@@ -13,19 +13,23 @@ system_prompt = {
|
|
13 |
"content": "You are a helpful assistant to answer user queries."
|
14 |
}
|
15 |
|
16 |
-
# Main chat function with memory from Gradio
|
17 |
def get_text_response(user_message, history):
|
18 |
-
# Convert Gradio message history
|
19 |
-
|
|
|
20 |
|
21 |
-
#
|
|
|
|
|
|
|
22 |
response = ""
|
23 |
completion = client.chat.completions.create(
|
24 |
model="nvidia/llama-3.1-nemotron-70b-instruct",
|
25 |
messages=messages,
|
26 |
temperature=0.5,
|
27 |
top_p=1,
|
28 |
-
max_tokens=
|
29 |
stream=True
|
30 |
)
|
31 |
|
@@ -36,12 +40,12 @@ def get_text_response(user_message, history):
|
|
36 |
|
37 |
return response
|
38 |
|
39 |
-
# Gradio Chat
|
40 |
demo = gr.ChatInterface(
|
41 |
fn=get_text_response,
|
42 |
title="🧠 Nemotron 70B Assistant",
|
43 |
theme="soft",
|
44 |
-
chatbot=gr.Chatbot(height=400
|
45 |
textbox=gr.Textbox(placeholder="Ask me anything...", container=False),
|
46 |
examples=["How are you doing?", "What are your interests?", "Which places do you like to visit?"]
|
47 |
)
|
|
|
13 |
"content": "You are a helpful assistant to answer user queries."
|
14 |
}
|
15 |
|
16 |
+
# Main chat function with memory from Gradio
|
17 |
def get_text_response(user_message, history):
|
18 |
+
# Convert Gradio message history to OpenAI format
|
19 |
+
formatted_history = [{"role": "user" if i % 2 == 0 else "assistant", "content": msg}
|
20 |
+
for i, msg in enumerate(sum(history, []))]
|
21 |
|
22 |
+
# Add the latest user message
|
23 |
+
messages = [system_prompt] + formatted_history + [{"role": "user", "content": user_message}]
|
24 |
+
|
25 |
+
# Stream the response
|
26 |
response = ""
|
27 |
completion = client.chat.completions.create(
|
28 |
model="nvidia/llama-3.1-nemotron-70b-instruct",
|
29 |
messages=messages,
|
30 |
temperature=0.5,
|
31 |
top_p=1,
|
32 |
+
max_tokens=100,
|
33 |
stream=True
|
34 |
)
|
35 |
|
|
|
40 |
|
41 |
return response
|
42 |
|
43 |
+
# Gradio Chat Interface
|
44 |
demo = gr.ChatInterface(
|
45 |
fn=get_text_response,
|
46 |
title="🧠 Nemotron 70B Assistant",
|
47 |
theme="soft",
|
48 |
+
#chatbot=gr.Chatbot(height=400), # default type is compatible
|
49 |
textbox=gr.Textbox(placeholder="Ask me anything...", container=False),
|
50 |
examples=["How are you doing?", "What are your interests?", "Which places do you like to visit?"]
|
51 |
)
|