@@ -63,7 +63,7 @@ For more information, see the following references.
63
63
1 . Get Azure OpenAI Service API key
64
64
1 . Copy [ .env.template] ( ../../.env.template ) to ` .env ` in the same directory
65
65
1 . Set credentials in ` .env `
66
- 1 . Run [ main.py ] ( ./main.py )
66
+ 1 . Run scripts
67
67
68
68
``` shell
69
69
# Create a virtual environment
@@ -79,7 +79,7 @@ $ pip install -r requirements.txt
79
79
$ python apps/1_call_azure_openai_chat/main.py
80
80
```
81
81
82
- ### Example
82
+ ### [ main.py ] ( ../../apps/1_call_azure_openai_chat/main.py )
83
83
84
84
To call the Azure OpenAI Service API, run the following command.
85
85
@@ -168,11 +168,59 @@ $ python apps/1_call_azure_openai_chat/main.py
168
168
}
169
169
```
170
170
171
- ## References
171
+ #### References
172
172
173
173
- Python basics
174
174
- [ Python Cheatsheet > Basics] ( https://www.pythoncheatsheet.org/cheatsheet/basics )
175
175
- [ venv — Creation of virtual environments] ( https://docs.python.org/3/library/venv.html#creating-virtual-environments )
176
176
- Azure OpenAI Basics
177
177
- [ Azure OpenAI Service documentation] ( https://learn.microsoft.com/azure/ai-services/openai/ )
178
178
- [ 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