Update app.py
Browse files
app.py
CHANGED
|
@@ -111,49 +111,38 @@ By adhering to these rules and utilizing the provided examples as guidelines, we
|
|
| 111 |
|
| 112 |
# # Launch the app
|
| 113 |
# iface.launch()
|
| 114 |
-
def get_response(prompt, model_choice, chat_history):
|
| 115 |
client = Groq(api_key=GROQ_API_KEY)
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
chat_history += f"\nUser: {prompt}"
|
| 120 |
else:
|
| 121 |
-
chat_history =
|
| 122 |
-
|
| 123 |
-
# Create a chat completion with the user's question, selected model, and the chat history
|
| 124 |
chat_completion = client.chat.completions.create(
|
| 125 |
-
messages=[
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
caption:{SYSTEM_PROMPT_TEMPLATE}, Please keep your answer concise. {chat_history}",
|
| 130 |
-
}
|
| 131 |
-
],
|
| 132 |
model=model_choice,
|
| 133 |
)
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
# Update the chat history with the model's response
|
| 139 |
-
updated_chat_history = chat_history + f"\nVinci: {model_response}"
|
| 140 |
-
|
| 141 |
-
# Return the model response and the updated chat history
|
| 142 |
return model_response, updated_chat_history
|
| 143 |
|
| 144 |
-
# Define the Gradio interface inputs, including a hidden State input for maintaining the chat history
|
| 145 |
-
# Update the Gradio interface definition
|
| 146 |
iface = gr.Interface(
|
| 147 |
fn=get_response,
|
| 148 |
inputs=[
|
| 149 |
gr.Textbox(lines=2, placeholder="Enter your question here..."),
|
| 150 |
-
gr.Radio(choices=["mixtral-8x7b-32768", "llama2-70b-4096"], label="Model Selection"
|
| 151 |
-
gr.State()
|
| 152 |
],
|
| 153 |
outputs=[
|
| 154 |
gr.TextArea(label="Answer"),
|
| 155 |
-
gr.State()
|
| 156 |
-
]
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
)
|
|
|
|
| 111 |
|
| 112 |
# # Launch the app
|
| 113 |
# iface.launch()
|
| 114 |
+
def get_response(prompt, model_choice, chat_history=None): # Default `chat_history` to None if not provided
|
| 115 |
client = Groq(api_key=GROQ_API_KEY)
|
| 116 |
+
|
| 117 |
+
if chat_history is None:
|
| 118 |
+
chat_history = "User: " + prompt
|
|
|
|
| 119 |
else:
|
| 120 |
+
chat_history += "\nUser: " + prompt
|
| 121 |
+
|
|
|
|
| 122 |
chat_completion = client.chat.completions.create(
|
| 123 |
+
messages=[{
|
| 124 |
+
"role": "user",
|
| 125 |
+
"content": f"Your prompt: {prompt}\n\nChat History:\n{chat_history}"
|
| 126 |
+
}],
|
|
|
|
|
|
|
|
|
|
| 127 |
model=model_choice,
|
| 128 |
)
|
| 129 |
+
|
| 130 |
+
model_response = chat_completion.choices[0].message.content
|
| 131 |
+
updated_chat_history = chat_history + "\nVinci: " + model_response
|
| 132 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
return model_response, updated_chat_history
|
| 134 |
|
|
|
|
|
|
|
| 135 |
iface = gr.Interface(
|
| 136 |
fn=get_response,
|
| 137 |
inputs=[
|
| 138 |
gr.Textbox(lines=2, placeholder="Enter your question here..."),
|
| 139 |
+
gr.Radio(choices=["mixtral-8x7b-32768", "llama2-70b-4096"], label="Model Selection"),
|
| 140 |
+
gr.State()
|
| 141 |
],
|
| 142 |
outputs=[
|
| 143 |
gr.TextArea(label="Answer"),
|
| 144 |
+
gr.State()
|
| 145 |
+
]
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
iface.launch()
|