nomyo-router/enhance.py
alpha-nerd-nomyo 34d6abd28b refactor: optimize token aggregation query and enhance chat proxy
- Refactored token aggregation query in db.py to use a single SQL query with SUM() instead of iterating through rows, improving performance
- Combined import statements in db.py and router.py to reduce lines of code
- Enhanced chat proxy in router.py to handle "moe-" prefixed models with multiple query execution and critique generation
- Added last_user_content() helper function to extract user content from messages
- Improved code readability and maintainability through these structural changes
2025-12-13 11:58:49 +01:00

38 lines
1 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 critizise the response by discussing both strength and weakness of the response.
<assistant_response>
{response}
</assistant_response>
"""
return moe_prompt
def moe_select_candiadate(query: str, candidates_with_feedback: list[str]) -> str:
select_prompt = f"""
From the following responses for the user query: {query}
select the best fitting candidate and formulate a final anser for the user.
<candidate_0>
{candidates_with_feedback[0].message.content}
</candidate_0>
<candidate_1>
{candidates_with_feedback[1].message.content}
</candidate_1>
<candidate_2>
{candidates_with_feedback[2].message.content}
</candidate_2>
"""
return select_prompt