Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,22 @@ def compare_responses(message, model1, approach1, model2, approach2, system_mess
|
|
20 |
response2 = respond(message, [], model2, approach2, system_message, max_tokens, temperature, top_p)
|
21 |
return response1, response2
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def respond(message, history, model, approach, system_message, max_tokens, temperature, top_p):
|
24 |
client = OpenAI(api_key=API_KEY, base_url="https://openrouter.ai/api/v1")
|
25 |
messages = [{"role": "system", "content": system_message}]
|
@@ -42,8 +58,7 @@ def respond(message, history, model, approach, system_message, max_tokens, tempe
|
|
42 |
)
|
43 |
return response.choices[0].message.content
|
44 |
else:
|
45 |
-
system_prompt =
|
46 |
-
initial_query = message
|
47 |
if approach == 'rto':
|
48 |
final_response, _ = round_trip_optimization(system_prompt, initial_query, client, model)
|
49 |
elif approach == 'z3':
|
|
|
20 |
response2 = respond(message, [], model2, approach2, system_message, max_tokens, temperature, top_p)
|
21 |
return response1, response2
|
22 |
|
23 |
+
def parse_conversation(messages):
|
24 |
+
system_prompt = ""
|
25 |
+
conversation = []
|
26 |
+
|
27 |
+
for message in messages:
|
28 |
+
role = message['role']
|
29 |
+
content = message['content']
|
30 |
+
|
31 |
+
if role == 'system':
|
32 |
+
system_prompt = content
|
33 |
+
elif role in ['user', 'assistant']:
|
34 |
+
conversation.append(f"{role.capitalize()}: {content}")
|
35 |
+
|
36 |
+
initial_query = "\n".join(conversation)
|
37 |
+
return system_prompt, initial_query
|
38 |
+
|
39 |
def respond(message, history, model, approach, system_message, max_tokens, temperature, top_p):
|
40 |
client = OpenAI(api_key=API_KEY, base_url="https://openrouter.ai/api/v1")
|
41 |
messages = [{"role": "system", "content": system_message}]
|
|
|
58 |
)
|
59 |
return response.choices[0].message.content
|
60 |
else:
|
61 |
+
system_prompt, initial_query = parse_conversation(messages)
|
|
|
62 |
if approach == 'rto':
|
63 |
final_response, _ = round_trip_optimization(system_prompt, initial_query, client, model)
|
64 |
elif approach == 'z3':
|