Spaces:
Sleeping
Sleeping
Refine generate_response
Browse files
app.py
CHANGED
|
@@ -11,7 +11,8 @@ retrieval_model_name = 'all-MiniLM-L6-v2' # Using a pre-trained model from Hugg
|
|
| 11 |
|
| 12 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 13 |
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
# Initial system message to set the behavior of the assistant
|
| 17 |
messages = [{"role": "system", "content": system_message}]
|
|
@@ -63,17 +64,15 @@ def find_relevant_segment(user_query, segments):
|
|
| 63 |
print(f"Error in finding relevant segment: {e}")
|
| 64 |
return ""
|
| 65 |
|
| 66 |
-
def generate_response(user_query
|
| 67 |
"""
|
| 68 |
Generate a response emphasizing the bot's capability in providing scheduling information.
|
| 69 |
"""
|
| 70 |
try:
|
| 71 |
-
# Use relevant segment in the message to the model
|
| 72 |
-
user_message = f"Here's a to do list based on what you said: {relevant_segment}"
|
| 73 |
-
|
| 74 |
# Append user's message to messages list
|
| 75 |
-
messages.append({"role": "user", "content":
|
| 76 |
|
|
|
|
| 77 |
response = openai.ChatCompletion.create(
|
| 78 |
model="gpt-4",
|
| 79 |
messages=messages,
|
|
@@ -103,13 +102,8 @@ def query_model(question):
|
|
| 103 |
if question == "":
|
| 104 |
return "Hello! I am your time manager Timify! Please enter what you need to do today."
|
| 105 |
|
| 106 |
-
#
|
| 107 |
-
|
| 108 |
-
if not relevant_segment:
|
| 109 |
-
return "Could not find specific information. Please refine your requirements."
|
| 110 |
-
|
| 111 |
-
# Generate a response using the relevant example
|
| 112 |
-
response = generate_response(question, relevant_segment)
|
| 113 |
return response
|
| 114 |
|
| 115 |
# Define the welcome message and specific topics the chatbot can provide information about
|
|
@@ -140,6 +134,5 @@ with gr.Blocks(theme='freddyaboulton/test-blue') as demo:
|
|
| 140 |
submit_button = gr.Button("Submit")
|
| 141 |
submit_button.click(fn=query_model, inputs=question, outputs=answer)
|
| 142 |
|
| 143 |
-
|
| 144 |
# Launch the Gradio app to allow user interaction
|
| 145 |
demo.launch(share=True)
|
|
|
|
| 11 |
|
| 12 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 13 |
|
| 14 |
+
# Update the system message to provide more guidance on generating a to-do list
|
| 15 |
+
system_message = "You are an assistant specialized in creating detailed to-do lists based on user input. Parse the input for tasks and generate a comprehensive list of actionable items. Output the items in a numbered list."
|
| 16 |
|
| 17 |
# Initial system message to set the behavior of the assistant
|
| 18 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 64 |
print(f"Error in finding relevant segment: {e}")
|
| 65 |
return ""
|
| 66 |
|
| 67 |
+
def generate_response(user_query):
|
| 68 |
"""
|
| 69 |
Generate a response emphasizing the bot's capability in providing scheduling information.
|
| 70 |
"""
|
| 71 |
try:
|
|
|
|
|
|
|
|
|
|
| 72 |
# Append user's message to messages list
|
| 73 |
+
messages.append({"role": "user", "content": user_query})
|
| 74 |
|
| 75 |
+
# Call OpenAI API to generate a to-do list based on the user query
|
| 76 |
response = openai.ChatCompletion.create(
|
| 77 |
model="gpt-4",
|
| 78 |
messages=messages,
|
|
|
|
| 102 |
if question == "":
|
| 103 |
return "Hello! I am your time manager Timify! Please enter what you need to do today."
|
| 104 |
|
| 105 |
+
# Generate a response using the user query directly
|
| 106 |
+
response = generate_response(question)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
return response
|
| 108 |
|
| 109 |
# Define the welcome message and specific topics the chatbot can provide information about
|
|
|
|
| 134 |
submit_button = gr.Button("Submit")
|
| 135 |
submit_button.click(fn=query_model, inputs=question, outputs=answer)
|
| 136 |
|
|
|
|
| 137 |
# Launch the Gradio app to allow user interaction
|
| 138 |
demo.launch(share=True)
|