Update app.py
Browse files
app.py
CHANGED
@@ -33,18 +33,17 @@ def process_message(message, history, analysis_prompt, rethinking_prompt, refine
|
|
33 |
|
34 |
llama_prompt = f"{rethinking_prompt}\n\nConversation history:\n{context}\n\nOriginal user query: {message}\n\nInitial response: {' '.join(gpt4o_response)}\n\nPlease review and suggest improvements or confirm if satisfactory."
|
35 |
llama_response = get_llm_response(llama_prompt, "gpt-4o-mini")
|
36 |
-
yield from stream_words("\nRethinking: ", llama_response)
|
37 |
|
38 |
if "<error>" in " ".join(llama_response):
|
39 |
-
return
|
40 |
|
41 |
if "done" not in " ".join(llama_response).lower():
|
42 |
final_gpt4o_prompt = f"{refinement_prompt}\n\nConversation history:\n{context}\n\nOriginal user query: {message}\n\nInitial response: {' '.join(gpt4o_response)}\n\nSuggestion: {' '.join(llama_response)}\n\nPlease provide a final response considering the suggestion."
|
43 |
final_response = get_llm_response(final_gpt4o_prompt, "gpt-4o-mini")
|
44 |
-
yield from stream_words("\nFinal Response: ", final_response)
|
45 |
-
return " ".join(final_response)
|
46 |
else:
|
47 |
-
|
48 |
|
49 |
def stream_words(prefix, words):
|
50 |
response = prefix
|
@@ -54,14 +53,12 @@ def stream_words(prefix, words):
|
|
54 |
yield response
|
55 |
|
56 |
def respond(message, history, analysis_prompt, rethinking_prompt, refinement_prompt):
|
57 |
-
|
58 |
for chunk in process_message(message, history, analysis_prompt, rethinking_prompt, refinement_prompt):
|
59 |
-
|
60 |
-
yield
|
61 |
|
62 |
-
|
63 |
-
final_response = response.split("Final Response: ")[-1] if "Final Response: " in response else response.split("Analysis: ")[-1]
|
64 |
-
return final_response
|
65 |
|
66 |
# (The rest of the code remains the same: analysis_prompt, rethinking_prompt, refinement_prompt, and the Gradio
|
67 |
# (Previous code remains the same)
|
|
|
33 |
|
34 |
llama_prompt = f"{rethinking_prompt}\n\nConversation history:\n{context}\n\nOriginal user query: {message}\n\nInitial response: {' '.join(gpt4o_response)}\n\nPlease review and suggest improvements or confirm if satisfactory."
|
35 |
llama_response = get_llm_response(llama_prompt, "gpt-4o-mini")
|
36 |
+
yield from stream_words("\n\nRethinking: ", llama_response)
|
37 |
|
38 |
if "<error>" in " ".join(llama_response):
|
39 |
+
return
|
40 |
|
41 |
if "done" not in " ".join(llama_response).lower():
|
42 |
final_gpt4o_prompt = f"{refinement_prompt}\n\nConversation history:\n{context}\n\nOriginal user query: {message}\n\nInitial response: {' '.join(gpt4o_response)}\n\nSuggestion: {' '.join(llama_response)}\n\nPlease provide a final response considering the suggestion."
|
43 |
final_response = get_llm_response(final_gpt4o_prompt, "gpt-4o-mini")
|
44 |
+
yield from stream_words("\n\nFinal Response: ", final_response)
|
|
|
45 |
else:
|
46 |
+
yield "\n\nFinal Response: The initial response is satisfactory and no further refinement is needed."
|
47 |
|
48 |
def stream_words(prefix, words):
|
49 |
response = prefix
|
|
|
53 |
yield response
|
54 |
|
55 |
def respond(message, history, analysis_prompt, rethinking_prompt, refinement_prompt):
|
56 |
+
full_response = ""
|
57 |
for chunk in process_message(message, history, analysis_prompt, rethinking_prompt, refinement_prompt):
|
58 |
+
full_response = chunk
|
59 |
+
yield full_response
|
60 |
|
61 |
+
return full_response
|
|
|
|
|
62 |
|
63 |
# (The rest of the code remains the same: analysis_prompt, rethinking_prompt, refinement_prompt, and the Gradio
|
64 |
# (Previous code remains the same)
|