nomyo-router/enhance.py
alpha-nerd-nomyo d80b29e4f2 feat: enhance code quality and documentation
- Renamed Feedback class to follow PascalCase convention
- Fixed candidate enumeration start index from 0 to 1
- Simplified candidate content access by removing .message.content
- Updated CONFIG_PATH environment variable name to CONFIG_PATH_ARG
- Bumped version from 0.5 to 0.6
- Removed unnecessary return statement and trailing newline
2026-01-29 19:59:08 +01:00

48 lines
No EOL
1.4 KiB
Python

from pydantic import BaseModel
class Feedback(BaseModel):
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}
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.
<assistant_response>
{response}
</assistant_response>
Respond in the format:
original_response
---
Response Analysis:
your analysis
"""
return moe_prompt
def moe_select_candidate(query: str, candidates: list[str]) -> str:
if not candidates:
raise ValueError("No candidates supplied")
candidate_sections = ""
for i, cand in enumerate(candidates[:3], start=1):
candidate_sections += f"""
<candidate_{i}>
{cand}
</candidate_{i}>
"""
# Strict instruction: "Respond **only** with the final answer."
select_prompt = f"""
From the following responses for the user query: {query}
{candidate_sections}
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.
"""
return select_prompt.strip()