Skip to content

Commit d4ce3bf

Browse files
authored
Merge pull request #150 from AnguseZhang/dev/zhouh
feat: unify quotation marks and implement dynamic language detection
2 parents 8fbcc25 + d839ae3 commit d4ce3bf

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

agents/matmaster_agent/callback.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from google.genai.types import FunctionCall, Part
1212

1313
from agents.matmaster_agent.constant import FRONTEND_STATE_KEY
14-
from agents.matmaster_agent.model import TransferCheck
15-
from agents.matmaster_agent.prompt import get_transfer_check_prompt
14+
from agents.matmaster_agent.model import TransferCheck, UserContent
15+
from agents.matmaster_agent.prompt import get_transfer_check_prompt, get_user_content_lang
1616
from agents.matmaster_agent.utils.llm_response_utils import has_function_call
1717

1818
logger = logging.getLogger(__name__)
@@ -25,7 +25,6 @@ async def matmaster_prepare_state(callback_context: CallbackContext) -> Optional
2525

2626
callback_context.state[FRONTEND_STATE_KEY] = callback_context.state.get(FRONTEND_STATE_KEY, {})
2727
callback_context.state[FRONTEND_STATE_KEY]['biz'] = callback_context.state[FRONTEND_STATE_KEY].get('biz', {})
28-
callback_context.state['target_language'] = callback_context.state[FRONTEND_STATE_KEY].get('target_language', 'zh')
2928
callback_context.state['long_running_ids'] = callback_context.state.get('long_running_ids', [])
3029
callback_context.state['long_running_jobs'] = callback_context.state.get('long_running_jobs', {})
3130
callback_context.state['long_running_jobs_count'] = callback_context.state.get('long_running_jobs_count', 0)
@@ -39,6 +38,15 @@ async def matmaster_prepare_state(callback_context: CallbackContext) -> Optional
3938
callback_context.state['invocation_id_with_tool_call'] = callback_context.state.get('invocation_id_with_tool_call',
4039
None)
4140

41+
user_content = callback_context.user_content.parts[0].text
42+
prompt = get_user_content_lang().format(user_content=user_content)
43+
response = litellm.completion(model='azure/gpt-4o', messages=[{'role': 'user', 'content': prompt}],
44+
response_format=UserContent)
45+
result: dict = json.loads(response.choices[0].message.content)
46+
logger.info(f"[matmaster_prepare_state] user_content = {result}")
47+
language = str(result.get('language', 'zh'))
48+
callback_context.state['target_language'] = language
49+
4250

4351
# after_model_callback
4452
async def matmaster_check_transfer(callback_context: CallbackContext, llm_response: LlmResponse) -> Optional[

agents/matmaster_agent/model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ class DFlowJobInfo(BaseModel):
5454
class TransferCheck(BaseModel):
5555
is_transfer: bool
5656
target_agent: str
57+
58+
59+
class UserContent(BaseModel):
60+
language: str

agents/matmaster_agent/prompt.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,3 +783,17 @@ def get_params_check_info_prompt():
783783
784784
Generate an appropriate confirmation message based on the provided function information and the user's language.
785785
"""
786+
787+
788+
def get_user_content_lang():
789+
return """
790+
You are a professional assistant responsible for analysing language of user_content.
791+
792+
User Content:
793+
{user_content}
794+
795+
Provide your analysis in the following JSON format:
796+
{{
797+
"language": <string>
798+
}}
799+
"""

0 commit comments

Comments
 (0)