fix(factory.py): support image url requests for anthropic

This commit is contained in:
Krrish Dholakia 2024-03-06 11:09:50 -08:00
parent 688b903d19
commit 81b92f3434
2 changed files with 97 additions and 15 deletions

View file

@ -151,8 +151,6 @@ def test_completion_claude_3_function_call():
assert isinstance(
response.choices[0].message.tool_calls[0].function.arguments, str
)
except litellm.ServiceUnavailableError as e:
pass
except Exception as e:
pytest.fail(f"Error occurred: {e}")
@ -221,6 +219,55 @@ def test_completion_claude_3_base64():
pytest.fail(f"An exception occurred - {str(e)}")
def test_completion_claude_3_function_plus_image():
litellm.set_verbose = True
image_content = [
{"type": "text", "text": "Whats in this image?"},
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
},
},
]
image_message = {"role": "user", "content": image_content}
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "text",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
},
}
]
tool_choice = {"type": "function", "function": {"name": "get_current_weather"}}
messages = [{"role": "user", "content": "What's the weather like in Boston today?"}]
response = completion(
model="claude-3-sonnet-20240229",
messages=[image_message],
tool_choice=tool_choice,
tools=tools,
stream=False,
)
print(response)
def test_completion_mistral_api():
try:
litellm.set_verbose = True
@ -1406,9 +1453,9 @@ def test_completion_replicate_vicuna():
def test_replicate_custom_prompt_dict():
litellm.set_verbose = True
model_name = "replicate/mistralai/mixtral-8x7b-instruct-v0.1"
model_name = "replicate/meta/llama-2-7b-chat:13c3cdee13ee059ab779f0291d29054dab00a47dad8261375654de5540165fb0"
litellm.register_prompt_template(
model="replicate/mistralai/mixtral-8x7b-instruct-v0.1",
model="replicate/meta/llama-2-7b-chat:13c3cdee13ee059ab779f0291d29054dab00a47dad8261375654de5540165fb0",
initial_prompt_value="You are a good assistant", # [OPTIONAL]
roles={
"system": {