Skip to content

Commit 252f3c4

Browse files
authored
Merge pull request #50 from ks6088ts-labs/feature/issue-47_support-reasoning-model
support reasoning model
2 parents 19c750e + b325aed commit 252f3c4

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

.env.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ LANGSMITH_API_KEY="lsv2_xxx"
1515
## Azure OpenAI Service
1616
AZURE_OPENAI_ENDPOINT="https://xxx.openai.azure.com/"
1717
AZURE_OPENAI_API_KEY="xxx"
18-
AZURE_OPENAI_API_VERSION="2024-10-21"
18+
AZURE_OPENAI_API_VERSION="2025-04-01-preview"
1919
AZURE_OPENAI_MODEL_CHAT="gpt-4o"
2020
AZURE_OPENAI_MODEL_EMBEDDING="text-embedding-3-small"
21+
AZURE_OPENAI_MODEL_REASONING="o4-mini"
2122

2223
# ---------
2324
# Tools

scripts/azure_openai_operator.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import logging
2+
3+
import typer
4+
from dotenv import load_dotenv
5+
6+
from template_langgraph.llms.azure_openais import AzureOpenAiWrapper
7+
from template_langgraph.loggers import get_logger
8+
9+
# Initialize the Typer application
10+
app = typer.Typer(
11+
add_completion=False,
12+
help="Azure OpenAI operator CLI",
13+
)
14+
15+
# Set up logging
16+
logger = get_logger(__name__)
17+
18+
19+
@app.command()
20+
def chat(
21+
query: str = typer.Option(
22+
"What is the weather like today?",
23+
"--query",
24+
"-q",
25+
help="Query to run with the Azure OpenAI chat model",
26+
),
27+
verbose: bool = typer.Option(
28+
False,
29+
"--verbose",
30+
"-v",
31+
help="Enable verbose output",
32+
),
33+
):
34+
# Set up logging
35+
if verbose:
36+
logger.setLevel(logging.DEBUG)
37+
38+
logger.info("Running...")
39+
response = AzureOpenAiWrapper().chat_model.invoke(
40+
input=query,
41+
)
42+
logger.debug(
43+
response.model_dump_json(
44+
indent=2,
45+
exclude_none=True,
46+
)
47+
)
48+
logger.info(f"Output: {response.content}")
49+
50+
51+
@app.command()
52+
def reasoning(
53+
query: str = typer.Option(
54+
"患者のデータから考えられる病名を診断してください。年齢: 55歳, 性別: 男性, 主訴: 激しい胸の痛み、息切れ, 検査データ: 心電図異常、トロポニン値上昇, 病歴: 高血圧、喫煙歴あり", # noqa: E501
55+
"--query",
56+
"-q",
57+
help="Query to run with the Azure OpenAI reasoning model",
58+
),
59+
verbose: bool = typer.Option(
60+
False,
61+
"--verbose",
62+
"-v",
63+
help="Enable verbose output",
64+
),
65+
):
66+
# Set up logging
67+
if verbose:
68+
logger.setLevel(logging.DEBUG)
69+
70+
logger.info("Running...")
71+
response = AzureOpenAiWrapper().reasoning_model.invoke(
72+
input=query,
73+
)
74+
logger.debug(
75+
response.model_dump_json(
76+
indent=2,
77+
exclude_none=True,
78+
)
79+
)
80+
logger.info(f"Output: {response.content}")
81+
82+
83+
if __name__ == "__main__":
84+
load_dotenv(
85+
override=True,
86+
verbose=True,
87+
)
88+
app()

template_langgraph/llms/azure_openais.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Settings(BaseSettings):
1010
azure_openai_api_version: str = "2024-10-21"
1111
azure_openai_model_chat: str = "gpt-4o"
1212
azure_openai_model_embedding: str = "text-embedding-3-small"
13+
azure_openai_model_reasoning: str = "o4-mini"
1314

1415
model_config = SettingsConfigDict(
1516
env_file=".env",
@@ -42,6 +43,12 @@ def __init__(self, settings: Settings = None):
4243
api_version=settings.azure_openai_api_version,
4344
azure_deployment=settings.azure_openai_model_embedding,
4445
)
46+
self.reasoning_model = AzureChatOpenAI(
47+
azure_endpoint=settings.azure_openai_endpoint,
48+
api_key=settings.azure_openai_api_key,
49+
api_version=settings.azure_openai_api_version,
50+
azure_deployment=settings.azure_openai_model_reasoning,
51+
)
4552

4653
def create_embedding(self, text: str):
4754
"""Create an embedding for the given text."""

0 commit comments

Comments
 (0)