@@ -63,7 +63,7 @@ For more information, see the following references.
63631 . Get Azure OpenAI Service API key
64641 . Copy [ .env.template] ( ../../.env.template ) to ` .env ` in the same directory
65651 . 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
8484To 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