Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update function calling docs #673

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions docs/my-website/docs/completion/function_call.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,25 @@ messages = [
{"role": "user", "content": "What is the weather like in Boston?"}
]

def get_current_weather(location):
if location == "Boston, MA":
return "The weather is 12F"
def get_current_weather(location: str, unit: str):
"""Get the current weather in a given location

functions = litellm.utils.function_to_dict(get_current_weather)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling function_to_dict on get_current_weather results in a NoneType exception; A docstring must be present.

Parameters
----------
location : str
The city and state, e.g. San Francisco, CA
unit : str {'celsius', 'fahrenheit'}
Temperature unit

Returns
-------
str
a sentence indicating the weather
"""
if location == "Boston, MA":
return "The weather is 12F"

functions = [litellm.utils.function_to_dict(get_current_weather)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made functions to a list.


response = completion(model="gpt-3.5-turbo-0613", messages=messages, functions=functions)
print(response)
Expand All @@ -127,7 +141,7 @@ from litellm import completion
# IMPORTANT - Set this to TRUE to add the function to the prompt for Non OpenAI LLMs
litellm.add_function_to_prompt = True # set add_function_to_prompt for Non OpenAI LLMs

os.environ['OPENAI_API_KEY'] = ""
os.environ['ANTHROPIC_API_KEY'] = ""

messages = [
{"role": "user", "content": "What is the weather like in Boston?"}
Expand Down