2025-12-13 11:58:49 +01:00
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
2026-01-29 19:59:08 +01:00
|
|
|
class Feedback(BaseModel):
|
2025-12-13 11:58:49 +01:00
|
|
|
query_id: int
|
|
|
|
|
content: str
|
|
|
|
|
|
|
|
|
|
def moe(query: str, query_id: int, response: str) -> str:
|
|
|
|
|
moe_prompt = f"""
|
|
|
|
|
User query: {query}
|
|
|
|
|
query_id: {query_id}
|
|
|
|
|
|
2025-12-16 09:46:36 +01:00
|
|
|
The following is an assistant response to the original user query. Analyse the response, then criticize the it by discussing both strengths and weaknesses. Do not add additional commentary.
|
2025-12-13 11:58:49 +01:00
|
|
|
|
|
|
|
|
<assistant_response>
|
|
|
|
|
{response}
|
|
|
|
|
</assistant_response>
|
2025-12-16 09:46:36 +01:00
|
|
|
|
|
|
|
|
Respond in the format:
|
|
|
|
|
original_response
|
|
|
|
|
---
|
|
|
|
|
Response Analysis:
|
|
|
|
|
your analysis
|
2025-12-13 11:58:49 +01:00
|
|
|
"""
|
|
|
|
|
return moe_prompt
|
|
|
|
|
|
2025-12-16 09:46:36 +01:00
|
|
|
def moe_select_candidate(query: str, candidates: list[str]) -> str:
|
|
|
|
|
if not candidates:
|
2026-01-29 19:59:08 +01:00
|
|
|
raise ValueError("No candidates supplied")
|
2025-12-16 09:46:36 +01:00
|
|
|
|
|
|
|
|
candidate_sections = ""
|
2026-01-29 19:59:08 +01:00
|
|
|
for i, cand in enumerate(candidates[:3], start=1):
|
2025-12-16 09:46:36 +01:00
|
|
|
candidate_sections += f"""
|
|
|
|
|
<candidate_{i}>
|
2026-01-29 19:59:08 +01:00
|
|
|
{cand}
|
2025-12-16 09:46:36 +01:00
|
|
|
</candidate_{i}>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# Strict instruction: "Respond **only** with the final answer."
|
2025-12-13 11:58:49 +01:00
|
|
|
select_prompt = f"""
|
|
|
|
|
From the following responses for the user query: {query}
|
|
|
|
|
|
2025-12-16 09:46:36 +01:00
|
|
|
{candidate_sections}
|
2025-12-13 11:58:49 +01:00
|
|
|
|
2025-12-16 09:46:36 +01:00
|
|
|
Choose the best candidate and output the final answer in the language of the query.
|
|
|
|
|
**Do NOT** mention candidate numbers, strengths, weaknesses, or any other commentary.
|
|
|
|
|
Just give the final answer—nothing else.
|
2025-12-13 11:58:49 +01:00
|
|
|
"""
|
2026-01-29 19:59:08 +01:00
|
|
|
return select_prompt.strip()
|