diff --git a/wavefront/server/apps/call_processing/call_processing/services/language_detection_tool.py b/wavefront/server/apps/call_processing/call_processing/services/language_detection_tool.py index 299e2b5..41ac208 100644 --- a/wavefront/server/apps/call_processing/call_processing/services/language_detection_tool.py +++ b/wavefront/server/apps/call_processing/call_processing/services/language_detection_tool.py @@ -150,7 +150,7 @@ async def detect_and_switch_language(params: FunctionCallParams): return # Append new language instruction to clean base prompt - updated_content = f'{base_prompt}\n\n{language_instruction}' + updated_content = f'{language_instruction}\n\n{base_prompt}' updated_system_message = { 'role': 'system', 'content': updated_content, diff --git a/wavefront/server/apps/call_processing/call_processing/services/llm_service.py b/wavefront/server/apps/call_processing/call_processing/services/llm_service.py index 3bd00fd..199111f 100644 --- a/wavefront/server/apps/call_processing/call_processing/services/llm_service.py +++ b/wavefront/server/apps/call_processing/call_processing/services/llm_service.py @@ -50,7 +50,13 @@ def create_llm_service(llm_config: Dict[str, Any]): logger.info(f'Creating LLM service: {llm_type} / {model}') if llm_type == 'openai': - return LLMServiceFactory._create_openai_llm(api_key, model, parameters) + base_url = llm_config.get('base_url') + if not base_url or base_url == 'https://api.openai.com/v1': + return LLMServiceFactory._create_openai_llm(api_key, model, parameters) + else: + return LLMServiceFactory._create_openai_compatible_llm( + api_key, model, parameters, base_url + ) elif llm_type == 'azure_openai': base_url = llm_config.get('base_url') if not base_url: @@ -97,6 +103,36 @@ def _create_openai_llm(api_key: str, model: str, parameters: Dict[str, Any]): return OpenAILLMService(api_key=api_key, model=model, params=input_params) + @staticmethod + def _create_openai_compatible_llm( + api_key: str, model: str, parameters: Dict[str, Any], base_url: str + ): + """Create a BaseOpenAILLMService for OpenAI-compatible endpoints""" + params_dict = {} + + if 'temperature' in parameters: + params_dict['temperature'] = parameters['temperature'] + if 'max_completion_tokens' in parameters: + params_dict['max_completion_tokens'] = parameters['max_completion_tokens'] + if 'top_p' in parameters: + params_dict['top_p'] = parameters['top_p'] + if 'frequency_penalty' in parameters: + params_dict['frequency_penalty'] = parameters['frequency_penalty'] + if 'presence_penalty' in parameters: + params_dict['presence_penalty'] = parameters['presence_penalty'] + if 'seed' in parameters: + params_dict['seed'] = parameters['seed'] + + input_params = BaseOpenAILLMService.InputParams(**params_dict) + + logger.info( + f"OpenAI-compatible LLM config: model={model}, base_url={base_url}, temp={params_dict.get('temperature', 'default')}" + ) + + return BaseOpenAILLMService( + api_key=api_key, model=model, base_url=base_url, params=input_params + ) + @staticmethod def _create_google_llm(api_key: str, model: str, parameters: Dict[str, Any]): """Create Google LLM service""" diff --git a/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py b/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py index 069d887..b1b6798 100644 --- a/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py +++ b/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py @@ -321,7 +321,7 @@ async def run_conversation( f'- Do NOT switch based on a greeting (e.g. "Namaste") or incidental use of another language.\n' f'- If the user requests a language not in the supported list, apologise and tell them which languages are available. Do not call the switch tool.' ) - system_content = f'{base_system_prompt}\n\n{initial_language_instruction}{language_switching_rules}' + system_content = f'{initial_language_instruction}\n\n{base_system_prompt}{language_switching_rules}' # Store base prompt without language instruction for switching (rules persist across switches) language_state['original_system_prompt'] = ( base_system_prompt + language_switching_rules