(test) add func to prompt

This commit is contained in:
ishaan-jaff 2023-10-30 20:06:06 -07:00
parent ad2b75a8cc
commit 0089442341

View file

@ -1,75 +1,75 @@
# #### What this tests #### #### What this tests ####
# # Allow the user to map the function to the prompt, if the model doesn't support function calling # Allow the user to map the function to the prompt, if the model doesn't support function calling
# import sys, os, pytest import sys, os, pytest
# import traceback import traceback
# sys.path.insert( sys.path.insert(
# 0, os.path.abspath("../..") 0, os.path.abspath("../..")
# ) # Adds the parent directory to the system path ) # Adds the parent directory to the system path
# import litellm import litellm
# ## case 1: set_function_to_prompt not set ## case 1: set_function_to_prompt not set
# def test_function_call_non_openai_model(): def test_function_call_non_openai_model():
# try: try:
# model = "claude-instant-1" model = "claude-instant-1"
# messages=[{"role": "user", "content": "what's the weather in sf?"}] messages=[{"role": "user", "content": "what's the weather in sf?"}]
# functions = [ functions = [
# { {
# "name": "get_current_weather", "name": "get_current_weather",
# "description": "Get the current weather in a given location", "description": "Get the current weather in a given location",
# "parameters": { "parameters": {
# "type": "object", "type": "object",
# "properties": { "properties": {
# "location": { "location": {
# "type": "string", "type": "string",
# "description": "The city and state, e.g. San Francisco, CA" "description": "The city and state, e.g. San Francisco, CA"
# }, },
# "unit": { "unit": {
# "type": "string", "type": "string",
# "enum": ["celsius", "fahrenheit"] "enum": ["celsius", "fahrenheit"]
# } }
# }, },
# "required": ["location"] "required": ["location"]
# } }
# } }
# ] ]
# response = litellm.completion(model=model, messages=messages, functions=functions) response = litellm.completion(model=model, messages=messages, functions=functions)
# pytest.fail(f'An error occurred') pytest.fail(f'An error occurred')
# except Exception as e: except Exception as e:
# pass pass
# test_function_call_non_openai_model() test_function_call_non_openai_model()
# ## case 2: add_function_to_prompt set ## case 2: add_function_to_prompt set
# def test_function_call_non_openai_model_litellm_mod_set(): def test_function_call_non_openai_model_litellm_mod_set():
# litellm.add_function_to_prompt = True litellm.add_function_to_prompt = True
# try: try:
# model = "claude-instant-1" model = "claude-instant-1"
# messages=[{"role": "user", "content": "what's the weather in sf?"}] messages=[{"role": "user", "content": "what's the weather in sf?"}]
# functions = [ functions = [
# { {
# "name": "get_current_weather", "name": "get_current_weather",
# "description": "Get the current weather in a given location", "description": "Get the current weather in a given location",
# "parameters": { "parameters": {
# "type": "object", "type": "object",
# "properties": { "properties": {
# "location": { "location": {
# "type": "string", "type": "string",
# "description": "The city and state, e.g. San Francisco, CA" "description": "The city and state, e.g. San Francisco, CA"
# }, },
# "unit": { "unit": {
# "type": "string", "type": "string",
# "enum": ["celsius", "fahrenheit"] "enum": ["celsius", "fahrenheit"]
# } }
# }, },
# "required": ["location"] "required": ["location"]
# } }
# } }
# ] ]
# response = litellm.completion(model=model, messages=messages, functions=functions) response = litellm.completion(model=model, messages=messages, functions=functions)
# print(f'response: {response}') print(f'response: {response}')
# except Exception as e: except Exception as e:
# pytest.fail(f'An error occurred {e}') pytest.fail(f'An error occurred {e}')
# # test_function_call_non_openai_model_litellm_mod_set() # test_function_call_non_openai_model_litellm_mod_set()