Skip to content

Commit 3ea0d8e

Browse files
committed
add responses api model
1 parent ba413f2 commit 3ea0d8e

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

docs/references.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@
6666
- [python-sounddevice](https://github.com/spatialaudio/python-sounddevice)
6767
- [python-soundfile](https://github.com/bastibe/python-soundfile)
6868

69-
### Realtime API
69+
### OpenAI
70+
71+
#### Realtime API
7072

7173
- [August 2025 / Realtime API audio model GA](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/whats-new#realtime-api-audio-model-ga)
7274
- [Global Standard model availability](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#global-standard-model-availability)
@@ -75,3 +77,10 @@
7577
- [GPT-4o Realtime API for speech and audio](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/realtime-audio-quickstart?tabs=keyless%2Clinux&pivots=programming-language-python)
7678
- [OpenAI Python API library > examples/realtime](https://github.com/openai/openai-python/tree/main/examples/realtime)
7779
- [How to use the GPT-4o Realtime API via WebRTC](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/realtime-audio-webrtc)
80+
81+
#### Responses API
82+
83+
- [OpenAI / New tools for building agents](https://openai.com/index/new-tools-for-building-agents/)
84+
- [OpenAI / Responses](https://platform.openai.com/docs/api-reference/responses)
85+
- [Azure OpenAI Responses API](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/responses?tabs=python-key)
86+
- [LangChain / Responses API](https://python.langchain.com/docs/integrations/chat/openai/#responses-api)

scripts/azure_openai_operator.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,53 @@ def image(
212212
logger.info(f"Output: {response.content}")
213213

214214

215+
@app.command()
216+
def responses(
217+
query: str = typer.Option(
218+
"What is the weather like today?",
219+
"--query",
220+
"-q",
221+
help="Query to run with the Azure OpenAI chat model",
222+
),
223+
stream: bool = typer.Option(
224+
False,
225+
"--stream",
226+
"-s",
227+
help="Enable streaming output",
228+
),
229+
verbose: bool = typer.Option(
230+
False,
231+
"--verbose",
232+
"-v",
233+
help="Enable verbose output",
234+
),
235+
):
236+
set_verbose_logging(verbose)
237+
238+
logger.info("Running...")
239+
llm = AzureOpenAiWrapper().responses_model
240+
241+
if stream:
242+
for chunk in llm.stream(
243+
input=[
244+
HumanMessage(content=query),
245+
],
246+
):
247+
# FIXME: Currently, just dump the whole chunk
248+
print(chunk)
249+
else:
250+
response = llm.invoke(
251+
input=query,
252+
)
253+
logger.debug(
254+
response.model_dump_json(
255+
indent=2,
256+
exclude_none=True,
257+
)
258+
)
259+
logger.info(f"Output: {response.content}")
260+
261+
215262
if __name__ == "__main__":
216263
load_dotenv(
217264
override=True,

template_langgraph/llms/azure_openais.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(self, settings: Settings = None):
4545
self._chat_model: AzureChatOpenAI | None = None
4646
self._reasoning_model: AzureChatOpenAI | None = None
4747
self._embedding_model: AzureOpenAIEmbeddings | None = None
48+
self._responses_model: AzureChatOpenAI | None = None
4849

4950
def _get_auth_key(self) -> str:
5051
"""Generate a key for authentication caching based on settings."""
@@ -138,6 +139,34 @@ def embedding_model(self) -> AzureOpenAIEmbeddings:
138139
)
139140
return self._embedding_model
140141

142+
@property
143+
def responses_model(self) -> AzureChatOpenAI:
144+
"""Lazily initialize and return responses API model."""
145+
if self._responses_model is None:
146+
if self.settings.azure_openai_use_microsoft_entra_id.lower() == "true":
147+
token = self._get_auth_token()
148+
self._responses_model = AzureChatOpenAI(
149+
azure_ad_token=token,
150+
azure_endpoint=self.settings.azure_openai_endpoint,
151+
api_version=self.settings.azure_openai_api_version,
152+
azure_deployment=self.settings.azure_openai_model_chat,
153+
streaming=True,
154+
model=self.settings.azure_openai_model_chat,
155+
output_version="responses/v1",
156+
)
157+
else:
158+
logger.info("Using API key for authentication")
159+
self._responses_model = AzureChatOpenAI(
160+
api_key=self.settings.azure_openai_api_key,
161+
azure_endpoint=self.settings.azure_openai_endpoint,
162+
api_version=self.settings.azure_openai_api_version,
163+
azure_deployment=self.settings.azure_openai_model_chat,
164+
streaming=True,
165+
model=self.settings.azure_openai_model_chat,
166+
output_version="responses/v1",
167+
)
168+
return self._responses_model
169+
141170
def create_embedding(self, text: str):
142171
"""Create an embedding for the given text."""
143172
return self.embedding_model.embed_query(text)

0 commit comments

Comments
 (0)