Skip to content

Commit 413fbce

Browse files
committed
More function calling examples
1 parent 68c2d42 commit 413fbce

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

function_calling_call.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import os
21
import json
2+
import os
33

44
import azure.identity
55
import openai
@@ -10,7 +10,6 @@
1010
API_HOST = os.getenv("API_HOST")
1111

1212
if API_HOST == "azure":
13-
1413
token_provider = azure.identity.get_bearer_token_provider(
1514
azure.identity.DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
1615
)
@@ -22,20 +21,17 @@
2221
MODEL_NAME = os.getenv("AZURE_OPENAI_DEPLOYMENT")
2322

2423
elif API_HOST == "ollama":
25-
2624
client = openai.OpenAI(
2725
base_url=os.getenv("OLLAMA_ENDPOINT"),
2826
api_key="nokeyneeded",
2927
)
3028
MODEL_NAME = os.getenv("OLLAMA_MODEL")
3129

3230
elif API_HOST == "github":
33-
3431
client = openai.OpenAI(base_url="https://models.inference.ai.azure.com", api_key=os.getenv("GITHUB_TOKEN"))
3532
MODEL_NAME = os.getenv("GITHUB_MODEL")
3633

3734
else:
38-
3935
client = openai.OpenAI(api_key=os.getenv("OPENAI_KEY"))
4036
MODEL_NAME = os.getenv("OPENAI_MODEL")
4137

@@ -45,6 +41,7 @@ def lookup_weather(city_name=None, zip_code=None):
4541
print(f"Looking up weather for {city_name or zip_code}...")
4642
return "It's sunny!"
4743

44+
4845
tools = [
4946
{
5047
"type": "function",
@@ -89,4 +86,4 @@ def lookup_weather(city_name=None, zip_code=None):
8986
function_name = response.choices[0].message.tool_calls[0].function.name
9087
arguments = json.loads(response.choices[0].message.tool_calls[0].function.arguments)
9188
if function_name == "lookup_weather":
92-
lookup_weather(**arguments)
89+
lookup_weather(**arguments)

0 commit comments

Comments
 (0)