* chore(.gitignore): add 'venv' to the list of ignored files/directories

* fix(test_completion.py): fix import order and remove unused imports
* feat(test_completion.py): add test for empty assistant message in completion_claude_3_empty_message()
This commit is contained in:
nkvch 2024-05-07 12:45:16 +02:00
parent 7d7b59ff78
commit 389530efb4
2 changed files with 35 additions and 4 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
.venv .venv
venv
.env .env
litellm_uuid.txt litellm_uuid.txt
__pycache__/ __pycache__/

View file

@ -1,17 +1,21 @@
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 pytest
import litellm import litellm
from litellm import embedding, completion, completion_cost, Timeout from litellm import (RateLimitError, Timeout, completion, completion_cost,
from litellm import RateLimitError embedding)
from litellm.llms.prompt_templates.factory import anthropic_messages_pt from litellm.llms.prompt_templates.factory import anthropic_messages_pt
# litellm.num_retries=3 # litellm.num_retries=3
@ -163,6 +167,32 @@ def test_completion_claude_3():
pytest.fail(f"Error occurred: {e}") pytest.fail(f"Error occurred: {e}")
def test_completion_claude_3_empty_message():
litellm.set_verbose = True
messages = [{'role': 'user', 'content': 'please create a logo for a modern AI app. create in SVG format'},
{'role': 'assistant', 'content': "To create a logo for a modern AI app in SVG format, I'll use the DALL-E 3 Image Generator."},
{'role': 'user', 'content': 'output SVG'},
{'role': 'assistant', 'content': 'To generate a logo for a modern AI app in SVG format using DALL-E 3, I need to:\n1. Craft a detailed prompt describing the desired logo style and elements\n2. Specify the image size (SVG is vector-based, so size is less relevant)\n3. Call the generate_image function with the prompt and size\n4. Display the generated SVG logo using the provided syntax\nThe prompt should include keywords related to AI, modern design, and SVG format. Some key elements to incorporate could be a brain symbol, circuit lines, or a robot icon, using a minimalist style and a blue color scheme often associated with technology and intelligence.',
'tool_calls': [
{'id': 'toolu_01KEUtRVySSeMrf3g7rCA12E', 'type': 'function', 'function': {'name': 'python_tool', 'arguments': '{"code": "...python code..."}'}}
]},
{'role': 'tool', 'content': '...python output...', 'tool_call_id': 'toolu_01KEUtRVySSeMrf3g7rCA12E'},
{'role': 'assistant', 'content': ''}, # empty message appended by model after tool call response
{'role': 'user', 'content': 'write SVG source youself!'},
]
try:
response = completion(
model="anthropic/claude-3-opus-20240229",
messages=messages,
stream=True,
tools=[{'type': 'function', 'function': {'name': 'python_tool', 'description': 'Execute code', 'parameters': {'type': 'object', 'properties': {'headline': {'description': 'Must have. Title of this tool call (maximum 15 characters).', 'type': 'string'}, 'code': {'description': 'Python code to execute.', 'type': 'string'}}, 'required': ['code', 'headline']}}}]
)
print(response)
except Exception as e:
pytest.fail(f"Error occurred: {e}")
def test_completion_claude_3_function_call(): def test_completion_claude_3_function_call():
litellm.set_verbose = True litellm.set_verbose = True
tools = [ tools = [