forked from phoenix/litellm-mirror
test(test_function_call_parsing.py): fix test
This commit is contained in:
parent
2b7a64ee28
commit
edbe9e0741
1 changed files with 57 additions and 51 deletions
|
@ -1,23 +1,27 @@
|
||||||
# What is this?
|
# What is this?
|
||||||
## Test to make sure function call response always works with json.loads() -> no extra parsing required. Relevant issue - https://github.com/BerriAI/litellm/issues/2654
|
## Test to make sure function call response always works with json.loads() -> no extra parsing required. Relevant issue - https://github.com/BerriAI/litellm/issues/2654
|
||||||
import sys, os
|
import os
|
||||||
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
import os, io
|
import io
|
||||||
|
import os
|
||||||
|
|
||||||
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 pytest
|
|
||||||
import litellm
|
|
||||||
import json
|
import json
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from litellm import completion
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
import litellm
|
||||||
|
from litellm import completion
|
||||||
|
|
||||||
|
|
||||||
# Just a stub to keep the sample code simple
|
# Just a stub to keep the sample code simple
|
||||||
class Trade:
|
class Trade:
|
||||||
|
@ -78,6 +82,7 @@ def trade(model_name: str) -> List[Trade]:
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
response = completion(
|
response = completion(
|
||||||
model_name,
|
model_name,
|
||||||
[
|
[
|
||||||
|
@ -129,7 +134,8 @@ def trade(model_name: str) -> List[Trade]:
|
||||||
"function": {"name": tool_spec["function"]["name"]}, # type: ignore
|
"function": {"name": tool_spec["function"]["name"]}, # type: ignore
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
except litellm.InternalServerError:
|
||||||
|
pass
|
||||||
calls = response.choices[0].message.tool_calls
|
calls = response.choices[0].message.tool_calls
|
||||||
trades = [trade for call in calls for trade in parse_call(call)]
|
trades = [trade for call in calls for trade in parse_call(call)]
|
||||||
return trades
|
return trades
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue