diff --git a/pilot/utils/function_calling.py b/pilot/utils/function_calling.py index 03eac27..e22b20e 100644 --- a/pilot/utils/function_calling.py +++ b/pilot/utils/function_calling.py @@ -19,7 +19,7 @@ def add_function_calls_to_request(gpt_data, function_calls: FunctionCallSet | No return model: str = gpt_data['model'] - is_llama = 'llama' in model + is_llama = 'llama' in model or 'anthropic' in model # if model == 'gpt-4': # gpt_data['functions'] = function_calls['definitions'] @@ -93,7 +93,7 @@ class JsonPrompter: (empty if the function doesn't exist or has no description) """ return [ - "Function description: " + function["description"] + function["description"] for function in functions if function["name"] == function_to_call and "description" in function ] @@ -131,8 +131,8 @@ class JsonPrompter: return "\n".join( self.function_descriptions(functions, function_to_call) + [ - "Function parameters should follow this schema:", - "```jsonschema", + "The response should be a JSON object matching this schema:", + "```json", self.function_parameters(functions, function_to_call), "```", ] @@ -187,7 +187,8 @@ class JsonPrompter: if function_to_call is None else f"Define the arguments for {function_to_call} to answer the user's question." # ) + "\nYou must return a JSON object without notes or commentary." - ) + " \nIn your response you must only use JSON output and provide no explanation or commentary." + # ) + " \nIn your response you must only use JSON output and provide no explanation or commentary." + ) + " \nThe response should contain only the JSON object, with no additional text or explanation." data = ( self.function_data(functions, function_to_call) diff --git a/pilot/utils/test_llm_connection.py b/pilot/utils/test_llm_connection.py index fcba855..e896b2c 100644 --- a/pilot/utils/test_llm_connection.py +++ b/pilot/utils/test_llm_connection.py @@ -61,11 +61,11 @@ class TestLlmConnection: @pytest.mark.parametrize("endpoint, model", [ ("OPENAI", "gpt-4"), # role: system ("OPENROUTER", "openai/gpt-3.5-turbo"), # role: user - ("OPENROUTER", "meta-llama/codellama-34b-instruct"), # rule: user, is_llama + ("OPENROUTER", "meta-llama/codellama-34b-instruct"), # rule: user, is_llama missed "choices" ("OPENROUTER", "google/palm-2-chat-bison"), # role: user/system # See https://github.com/1rgs/jsonformer-claude/blob/main/jsonformer_claude/main.py - # ("OPENROUTER", "anthropic/claude-2"), # role: user, prompt 2 + ("OPENROUTER", "anthropic/claude-2"), # role: user, prompt 2 - sometimes JSON, sometimes Python to generate JSON # ("OPENROUTER", "google/palm-2-codechat-bison"), # not working ]) def test_chat_completion_Architect(self, endpoint, model, monkeypatch):