Skip to content

Commit b09cfaa

Browse files
author
ks6088ts
committed
cosmetic changes
1 parent 89f2ee5 commit b09cfaa

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

apps/1_call_azure_openai_chat/convert_code.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@ def print_structured_output_openai(
3232
system: str,
3333
user: str,
3434
):
35-
"""
36-
How to use:
37-
Support for structured outputs was first added in API version 2024-08-01-preview.
38-
It is available in the latest preview APIs as well as the latest GA API: 2024-10-21.
39-
40-
Install dependencies:
41-
$ pip install openai python-dotenv pydantic
42-
43-
References:
44-
- https://learn.microsoft.com/ja-jp/azure/ai-services/openai/how-to/structured-outputs?tabs=python
45-
"""
46-
4735
client = AzureOpenAI(
4836
azure_endpoint=getenv("AZURE_OPENAI_ENDPOINT"),
4937
api_key=getenv("AZURE_OPENAI_API_KEY"),
@@ -67,17 +55,6 @@ def print_structured_output_langchain(
6755
system: str,
6856
user: str,
6957
):
70-
"""
71-
How to use:
72-
Support for structured outputs was first added in API version 2024-08-01-preview.
73-
It is available in the latest preview APIs as well as the latest GA API: 2024-10-21.
74-
75-
Install dependencies:
76-
$ pip install openai python-dotenv pydantic langchain-openai
77-
78-
References:
79-
- https://python.langchain.com/docs/how_to/structured_output/
80-
"""
8158
llm = AzureChatOpenAI(
8259
temperature=0,
8360
api_key=getenv("AZURE_OPENAI_API_KEY"),

docs/apps/1_call_azure_openai_chat.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ For more information, see the following references.
6363
1. Get Azure OpenAI Service API key
6464
1. Copy [.env.template](../../.env.template) to `.env` in the same directory
6565
1. Set credentials in `.env`
66-
1. Run [main.py](./main.py)
66+
1. Run scripts
6767

6868
```shell
6969
# Create a virtual environment
@@ -79,7 +79,7 @@ $ pip install -r requirements.txt
7979
$ python apps/1_call_azure_openai_chat/main.py
8080
```
8181

82-
### Example
82+
### [main.py](../../apps/1_call_azure_openai_chat/main.py)
8383

8484
To call the Azure OpenAI Service API, run the following command.
8585

@@ -168,11 +168,59 @@ $ python apps/1_call_azure_openai_chat/main.py
168168
}
169169
```
170170

171-
## References
171+
#### References
172172

173173
- Python basics
174174
- [Python Cheatsheet > Basics](https://www.pythoncheatsheet.org/cheatsheet/basics)
175175
- [venv — Creation of virtual environments](https://docs.python.org/3/library/venv.html#creating-virtual-environments)
176176
- Azure OpenAI Basics
177177
- [Azure OpenAI Service documentation](https://learn.microsoft.com/azure/ai-services/openai/)
178178
- [Quickstart: Get started generating text using Azure OpenAI Service](https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?tabs=command-line%2Cpython-new&pivots=programming-language-python)
179+
180+
### [convert_code.py](../../apps/1_call_azure_openai_chat/convert_code.py)
181+
182+
Support for structured outputs was first added in API version 2024-08-01-preview.
183+
It is available in the latest preview APIs as well as the latest GA API: 2024-10-21.
184+
See details in [Structured outputs](https://learn.microsoft.com/azure/ai-services/openai/how-to/structured-outputs?tabs=python).
185+
186+
To set up the environment, run the following commands.
187+
188+
```shell
189+
# Create a virtual environment
190+
python -m venv .venv
191+
192+
# Activate the virtual environment
193+
source .venv/bin/activate
194+
195+
# Install dependencies
196+
pip install openai python-dotenv pydantic langchain-openai
197+
```
198+
199+
Run the following command to convert code via OpenAI SDK or LangChain.
200+
201+
```shell
202+
203+
# help
204+
python apps/1_call_azure_openai_chat/convert_code.py --help
205+
206+
# convert code via OpenAI SDK in verbose mode
207+
python apps/1_call_azure_openai_chat/convert_code.py \
208+
--system "Extract the event information." \
209+
--user "Alice and Bob are going to a science fair on Friday." \
210+
--type "openai" \
211+
--verbose
212+
# Result: name='Science Fair' date='Friday' participants=['Alice', 'Bob']
213+
214+
# convert code via LangChain in verbose mode
215+
python apps/1_call_azure_openai_chat/convert_code.py \
216+
--system "Extract the event information." \
217+
--user "Alice and Bob are going to a science fair on Friday." \
218+
--type "langchain" \
219+
--verbose
220+
# Result: name='Science Fair' date='Friday' participants=['Alice', 'Bob']
221+
```
222+
223+
#### References
224+
225+
- [Structured outputs](https://learn.microsoft.com/azure/ai-services/openai/how-to/structured-outputs?tabs=python)
226+
- [How to return structured data from a model](https://python.langchain.com/docs/how_to/structured_output/)

0 commit comments

Comments
 (0)