mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
(test) parallel tool calling
This commit is contained in:
parent
fdbaceab8e
commit
d2bac07b48
1 changed files with 73 additions and 63 deletions
|
@ -12,14 +12,12 @@ import pytest
|
||||||
import litellm
|
import litellm
|
||||||
from litellm import embedding, completion, completion_cost, Timeout
|
from litellm import embedding, completion, completion_cost, Timeout
|
||||||
from litellm import RateLimitError
|
from litellm import RateLimitError
|
||||||
|
import pytest
|
||||||
litellm.num_retries = 3
|
litellm.num_retries = 3
|
||||||
litellm.cache = None
|
litellm.cache = None
|
||||||
litellm.set_verbose=True
|
litellm.set_verbose=False
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
# Example dummy function hard coded to return the same weather
|
|
||||||
# In production, this could be your backend API or an external API
|
|
||||||
def get_current_weather(location, unit="fahrenheit"):
|
def get_current_weather(location, unit="fahrenheit"):
|
||||||
"""Get the current weather in a given location"""
|
"""Get the current weather in a given location"""
|
||||||
if "tokyo" in location.lower():
|
if "tokyo" in location.lower():
|
||||||
|
@ -31,7 +29,10 @@ def get_current_weather(location, unit="fahrenheit"):
|
||||||
else:
|
else:
|
||||||
return json.dumps({"location": location, "temperature": "unknown"})
|
return json.dumps({"location": location, "temperature": "unknown"})
|
||||||
|
|
||||||
def run_conversation():
|
# Example dummy function hard coded to return the same weather
|
||||||
|
# In production, this could be your backend API or an external API
|
||||||
|
def test_parallel_function_call():
|
||||||
|
try:
|
||||||
# Step 1: send the conversation and available functions to the model
|
# Step 1: send the conversation and available functions to the model
|
||||||
messages = [{"role": "user", "content": "What's the weather like in San Francisco, Tokyo, and Paris?"}]
|
messages = [{"role": "user", "content": "What's the weather like in San Francisco, Tokyo, and Paris?"}]
|
||||||
tools = [
|
tools = [
|
||||||
|
@ -63,6 +64,11 @@ def run_conversation():
|
||||||
print("Response\n", response)
|
print("Response\n", response)
|
||||||
response_message = response.choices[0].message
|
response_message = response.choices[0].message
|
||||||
tool_calls = response_message.tool_calls
|
tool_calls = response_message.tool_calls
|
||||||
|
|
||||||
|
print("length of tool calls", len(tool_calls))
|
||||||
|
print("Expecting there to be 3 tool calls")
|
||||||
|
assert len(tool_calls) > 1 # this has to call the function for SF, Tokyo and parise
|
||||||
|
|
||||||
# Step 2: check if the model wanted to call a function
|
# Step 2: check if the model wanted to call a function
|
||||||
if tool_calls:
|
if tool_calls:
|
||||||
# Step 3: call the function
|
# Step 3: call the function
|
||||||
|
@ -93,5 +99,9 @@ def run_conversation():
|
||||||
model="gpt-3.5-turbo-1106",
|
model="gpt-3.5-turbo-1106",
|
||||||
messages=messages,
|
messages=messages,
|
||||||
) # get a new response from the model where it can see the function response
|
) # get a new response from the model where it can see the function response
|
||||||
|
print("second response\n", second_response)
|
||||||
return second_response
|
return second_response
|
||||||
print(run_conversation())
|
except Exception as e:
|
||||||
|
pytest.fail(f"Error occurred: {e}")
|
||||||
|
|
||||||
|
test_parallel_function_call()
|
Loading…
Add table
Add a link
Reference in a new issue