Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,10 @@ MODEL_OPTIONS = [
|
|
27 |
|
28 |
def generate_text(input_text, selected_model, history):
|
29 |
if history is None:
|
30 |
-
history =
|
|
|
|
|
|
|
31 |
|
32 |
# Call the API to get the model response
|
33 |
response = requests.post(
|
@@ -37,8 +40,8 @@ def generate_text(input_text, selected_model, history):
|
|
37 |
"Content-Type": "application/json"
|
38 |
},
|
39 |
data=json.dumps({
|
40 |
-
"model": selected_model, # Use selected model
|
41 |
-
"messages":
|
42 |
"top_p": 1,
|
43 |
"temperature": 1,
|
44 |
"frequency_penalty": 0,
|
@@ -59,10 +62,14 @@ def generate_text(input_text, selected_model, history):
|
|
59 |
except json.JSONDecodeError:
|
60 |
generated_response = "Error: Unable to parse response."
|
61 |
|
62 |
-
# Append the
|
63 |
-
history
|
|
|
|
|
|
|
64 |
|
65 |
-
return generated_response,
|
|
|
66 |
|
67 |
# Inject custom CSS directly into the Gradio interface for scrollbars
|
68 |
css = """
|
|
|
27 |
|
28 |
def generate_text(input_text, selected_model, history):
|
29 |
if history is None:
|
30 |
+
history = [] # Initialize history as a list if it's None
|
31 |
+
|
32 |
+
# Append the user's input to the conversation history
|
33 |
+
history.append({"role": "user", "content": input_text})
|
34 |
|
35 |
# Call the API to get the model response
|
36 |
response = requests.post(
|
|
|
40 |
"Content-Type": "application/json"
|
41 |
},
|
42 |
data=json.dumps({
|
43 |
+
"model": selected_model, # Use the selected model
|
44 |
+
"messages": history, # Send the entire conversation history
|
45 |
"top_p": 1,
|
46 |
"temperature": 1,
|
47 |
"frequency_penalty": 0,
|
|
|
62 |
except json.JSONDecodeError:
|
63 |
generated_response = "Error: Unable to parse response."
|
64 |
|
65 |
+
# Append the model's response to the conversation history
|
66 |
+
history.append({"role": "assistant", "content": generated_response})
|
67 |
+
|
68 |
+
# Format the history for display
|
69 |
+
display_history = "\n\n".join([f"{msg['role'].capitalize()}: {msg['content']}" for msg in history])
|
70 |
|
71 |
+
return generated_response, display_history, history # Return the updated history for continuity
|
72 |
+
|
73 |
|
74 |
# Inject custom CSS directly into the Gradio interface for scrollbars
|
75 |
css = """
|