Skip to content

Commit 49d9418

Browse files
committed
Add reasoning example
1 parent 336eead commit 49d9418

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

reasoning.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
3+
import azure.identity
4+
import openai
5+
from dotenv import load_dotenv
6+
from rich import print
7+
8+
# Setup the OpenAI client to use either Azure, OpenAI.com, or Ollama API
9+
load_dotenv(override=True)
10+
API_HOST = os.getenv("API_HOST", "github")
11+
12+
if API_HOST == "azure":
13+
token_provider = azure.identity.get_bearer_token_provider(
14+
azure.identity.DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
15+
)
16+
client = openai.AzureOpenAI(
17+
api_version=os.environ["AZURE_OPENAI_VERSION"],
18+
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
19+
azure_ad_token_provider=token_provider,
20+
)
21+
MODEL_NAME = os.environ["AZURE_OPENAI_DEPLOYMENT"]
22+
23+
elif API_HOST == "ollama":
24+
client = openai.OpenAI(base_url=os.environ["OLLAMA_ENDPOINT"], api_key="nokeyneeded")
25+
MODEL_NAME = os.environ["OLLAMA_MODEL"]
26+
27+
elif API_HOST == "github":
28+
client = openai.OpenAI(base_url="https://models.github.ai/inference", api_key=os.environ["GITHUB_TOKEN"])
29+
MODEL_NAME = os.getenv("GITHUB_MODEL", "openai/gpt-5")
30+
31+
else:
32+
client = openai.OpenAI(api_key=os.environ["OPENAI_KEY"])
33+
MODEL_NAME = os.environ["OPENAI_MODEL"]
34+
35+
response = client.chat.completions.create(
36+
model=MODEL_NAME,
37+
messages=[
38+
{
39+
"role": "user",
40+
"content": "Multiply together 1897234 and 12903812039.",
41+
},
42+
],
43+
reasoning_effort="minimal",
44+
verbosity="low",
45+
)
46+
print(response.choices[0].message.content)
47+
print(response.usage)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
azure-identity
2-
openai
2+
openai>=1.100.2
33
python-dotenv
44
langchain
55
langchain-openai

0 commit comments

Comments
 (0)