Update app.py
Browse files
app.py
CHANGED
@@ -7,22 +7,19 @@ client = OpenAI(
|
|
7 |
api_key="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"
|
8 |
)
|
9 |
|
10 |
-
# System
|
11 |
-
system_prompt = {
|
12 |
-
"role": "system",
|
13 |
-
"content": "You are a helpful assistant to answer user queries."
|
14 |
-
}
|
15 |
|
16 |
-
# Main chat function with memory
|
17 |
def get_text_response(user_message, history):
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
# Add the
|
23 |
-
messages = [system_prompt] +
|
24 |
|
25 |
-
# Stream
|
26 |
response = ""
|
27 |
completion = client.chat.completions.create(
|
28 |
model="nvidia/llama-3.1-nemotron-70b-instruct",
|
@@ -38,14 +35,18 @@ def get_text_response(user_message, history):
|
|
38 |
if delta and delta.content:
|
39 |
response += delta.content
|
40 |
|
41 |
-
|
|
|
|
|
42 |
|
43 |
-
|
|
|
|
|
44 |
demo = gr.ChatInterface(
|
45 |
fn=get_text_response,
|
46 |
title="🧠 Nemotron 70B Assistant",
|
47 |
theme="soft",
|
48 |
-
|
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 |
)
|
|
|
7 |
api_key="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"
|
8 |
)
|
9 |
|
10 |
+
# System prompt
|
11 |
+
system_prompt = {"role": "system", "content": "You are a helpful assistant to answer user queries."}
|
|
|
|
|
|
|
12 |
|
13 |
+
# Main chat function with memory
|
14 |
def get_text_response(user_message, history):
|
15 |
+
# history is a list of {"role": ..., "content": ...}
|
16 |
+
if history is None:
|
17 |
+
history = []
|
18 |
|
19 |
+
# Add the user message to the history
|
20 |
+
messages = [system_prompt] + history + [{"role": "user", "content": user_message}]
|
21 |
|
22 |
+
# Stream response
|
23 |
response = ""
|
24 |
completion = client.chat.completions.create(
|
25 |
model="nvidia/llama-3.1-nemotron-70b-instruct",
|
|
|
35 |
if delta and delta.content:
|
36 |
response += delta.content
|
37 |
|
38 |
+
# Update chat history
|
39 |
+
history.append({"role": "user", "content": user_message})
|
40 |
+
history.append({"role": "assistant", "content": response})
|
41 |
|
42 |
+
return response, history
|
43 |
+
|
44 |
+
# Gradio Chat UI
|
45 |
demo = gr.ChatInterface(
|
46 |
fn=get_text_response,
|
47 |
title="🧠 Nemotron 70B Assistant",
|
48 |
theme="soft",
|
49 |
+
chatbot=gr.Chatbot(height=400, type="messages"),
|
50 |
textbox=gr.Textbox(placeholder="Ask me anything...", container=False),
|
51 |
examples=["How are you doing?", "What are your interests?", "Which places do you like to visit?"]
|
52 |
)
|