Skip to content

Commit ed859ff

Browse files
lang instruction to beginning of prompt (#233)
* lang instruction to beginning of prompt * pipecat - support openai compatible llms
1 parent 377a316 commit ed859ff

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

wavefront/server/apps/call_processing/call_processing/services/language_detection_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async def detect_and_switch_language(params: FunctionCallParams):
150150
return
151151

152152
# Append new language instruction to clean base prompt
153-
updated_content = f'{base_prompt}\n\n{language_instruction}'
153+
updated_content = f'{language_instruction}\n\n{base_prompt}'
154154
updated_system_message = {
155155
'role': 'system',
156156
'content': updated_content,

wavefront/server/apps/call_processing/call_processing/services/llm_service.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ def create_llm_service(llm_config: Dict[str, Any]):
5050
logger.info(f'Creating LLM service: {llm_type} / {model}')
5151

5252
if llm_type == 'openai':
53-
return LLMServiceFactory._create_openai_llm(api_key, model, parameters)
53+
base_url = llm_config.get('base_url')
54+
if not base_url or base_url == 'https://api.openai.com/v1':
55+
return LLMServiceFactory._create_openai_llm(api_key, model, parameters)
56+
else:
57+
return LLMServiceFactory._create_openai_compatible_llm(
58+
api_key, model, parameters, base_url
59+
)
5460
elif llm_type == 'azure_openai':
5561
base_url = llm_config.get('base_url')
5662
if not base_url:
@@ -97,6 +103,36 @@ def _create_openai_llm(api_key: str, model: str, parameters: Dict[str, Any]):
97103

98104
return OpenAILLMService(api_key=api_key, model=model, params=input_params)
99105

106+
@staticmethod
107+
def _create_openai_compatible_llm(
108+
api_key: str, model: str, parameters: Dict[str, Any], base_url: str
109+
):
110+
"""Create a BaseOpenAILLMService for OpenAI-compatible endpoints"""
111+
params_dict = {}
112+
113+
if 'temperature' in parameters:
114+
params_dict['temperature'] = parameters['temperature']
115+
if 'max_completion_tokens' in parameters:
116+
params_dict['max_completion_tokens'] = parameters['max_completion_tokens']
117+
if 'top_p' in parameters:
118+
params_dict['top_p'] = parameters['top_p']
119+
if 'frequency_penalty' in parameters:
120+
params_dict['frequency_penalty'] = parameters['frequency_penalty']
121+
if 'presence_penalty' in parameters:
122+
params_dict['presence_penalty'] = parameters['presence_penalty']
123+
if 'seed' in parameters:
124+
params_dict['seed'] = parameters['seed']
125+
126+
input_params = BaseOpenAILLMService.InputParams(**params_dict)
127+
128+
logger.info(
129+
f"OpenAI-compatible LLM config: model={model}, base_url={base_url}, temp={params_dict.get('temperature', 'default')}"
130+
)
131+
132+
return BaseOpenAILLMService(
133+
api_key=api_key, model=model, base_url=base_url, params=input_params
134+
)
135+
100136
@staticmethod
101137
def _create_google_llm(api_key: str, model: str, parameters: Dict[str, Any]):
102138
"""Create Google LLM service"""

wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ async def run_conversation(
321321
f'- Do NOT switch based on a greeting (e.g. "Namaste") or incidental use of another language.\n'
322322
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.'
323323
)
324-
system_content = f'{base_system_prompt}\n\n{initial_language_instruction}{language_switching_rules}'
324+
system_content = f'{initial_language_instruction}\n\n{base_system_prompt}{language_switching_rules}'
325325
# Store base prompt without language instruction for switching (rules persist across switches)
326326
language_state['original_system_prompt'] = (
327327
base_system_prompt + language_switching_rules

0 commit comments

Comments
 (0)