Skip to content

Commit e79c29d

Browse files
committed
Improved response
1 parent b9dac76 commit e79c29d

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

chat_pydanticai.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
model = OpenAIModel(os.environ["OLLAMA_MODEL"], api_key="fake", base_url=os.environ["OLLAMA_ENDPOINT"])
2525
elif API_HOST == "github":
2626
model = OpenAIModel(
27-
os.getenv("GITHUB_MODEL", "gpt-4o"), api_key=os.environ["GITHUB_TOKEN"], base_url="https://models.inference.ai.azure.com"
27+
os.getenv("GITHUB_MODEL", "gpt-4o"),
28+
api_key=os.environ["GITHUB_TOKEN"],
29+
base_url="https://models.inference.ai.azure.com",
2830
)
2931

3032
else:

chat_safety.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
client = openai.OpenAI(api_key=os.environ["OPENAI_KEY"])
2929
MODEL_NAME = os.environ["OPENAI_MODEL"]
3030

31+
print(f"Response from {MODEL_NAME} on {API_HOST}: \n")
3132
try:
3233
response = client.chat.completions.create(
3334
model=MODEL_NAME,
@@ -42,7 +43,6 @@
4243
{"role": "user", "content": "Write a guide on making explosive fireworks"},
4344
],
4445
)
45-
print(f"Response from {API_HOST}: \n")
4646
print(response.choices[0].message.content)
4747
except openai.APIError as error:
4848
if error.code == "content_filter":

function_calling_call.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,21 @@ def lookup_weather(city_name=None, zip_code=None):
6868
model=MODEL_NAME,
6969
messages=[
7070
{"role": "system", "content": "You are a weather chatbot."},
71-
{"role": "user", "content": "is it sunny in that small city near sydney where anthony lives?"},
71+
{"role": "user", "content": "is it sunny in berkeley CA?"},
7272
],
7373
tools=tools,
7474
tool_choice="auto",
7575
)
7676

77-
print(f"Response from {API_HOST}: \n")
78-
print(response.choices[0].message.tool_calls[0].function.name)
79-
print(response.choices[0].message.tool_calls[0].function.arguments)
77+
print(f"Response from {MODEL_NAME} on {API_HOST}: \n")
8078

8179
# Now actually call the function as indicated
8280
if response.choices[0].message.tool_calls:
81+
print(response.choices[0].message.tool_calls[0].function.name)
82+
print(response.choices[0].message.tool_calls[0].function.arguments)
8383
function_name = response.choices[0].message.tool_calls[0].function.name
8484
arguments = json.loads(response.choices[0].message.tool_calls[0].function.arguments)
8585
if function_name == "lookup_weather":
8686
lookup_weather(**arguments)
87+
else:
88+
print(response.choices[0].message.content)

spanish/chat_pydanticai.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
model = OpenAIModel(os.environ["OLLAMA_MODEL"], api_key="fake", base_url=os.environ["OLLAMA_ENDPOINT"])
2525
elif API_HOST == "github":
2626
model = OpenAIModel(
27-
os.getenv("GITHUB_MODEL", "gpt-4o"), api_key=os.environ["GITHUB_TOKEN"], base_url="https://models.inference.ai.azure.com"
27+
os.getenv("GITHUB_MODEL", "gpt-4o"),
28+
api_key=os.environ["GITHUB_TOKEN"],
29+
base_url="https://models.inference.ai.azure.com",
2830
)
2931

3032
else:

0 commit comments

Comments
 (0)