Skip to content

Commit 2cc0063

Browse files
committed
update
1 parent d412a63 commit 2cc0063

File tree

3 files changed

+174
-3
lines changed

3 files changed

+174
-3
lines changed

articles/ai-services/openai/concepts/models.md

Lines changed: 170 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,176 @@ Once access has been granted, you will need to create a deployment for each mode
4949

5050
Support for the **o1 series** models was added in API version `2024-09-01-preview`.
5151

52-
The `max_tokens` parameter has been deprecated and replaced with the new `max_completion_tokens` parameter. **o1 series** models will only work with the `max_completions_tokens` parameter.
52+
The `max_tokens` parameter has been deprecated and replaced with the new `max_completion_tokens` parameter. **o1 series** models will only work with the `max_completion_tokens` parameter.
53+
54+
### Usage
55+
56+
These models do not currently support the same set of parameters as other models that use the chat completions API they only support a limited subset. `o1-preview` and `o1-mini` models will not accept system message role as part of the messages array.
57+
58+
# [Python (Microsoft Entra ID)](#tab/python-secure)
59+
60+
You may need to upgrade your version of the OpenAI Python library to take advantage of the new `max_completion_tokens` parameter.
61+
62+
```cmd
63+
pip install openai pydantic --upgrade
64+
```
65+
66+
If you new to using Microsoft Entra ID for authentication see [How to configure Azure OpenAI Service with Microsoft Entra ID authentication](./managed-identity.md).
67+
68+
```python
69+
from openai import AzureOpenAI
70+
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
71+
72+
token_provider = get_bearer_token_provider(
73+
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
74+
)
75+
76+
client = AzureOpenAI(
77+
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
78+
azure_ad_token_provider=token_provider,
79+
api_version="2024-09-01-preview"
80+
)
81+
82+
response = client.chat.completions.create(
83+
model="o1-preview-new", # replace with the model deployment name of your o1-preview, or o1-mini model
84+
messages=[
85+
{"role": "user", "content": "What steps should I think about when writing my first Python API?"},
86+
],
87+
max_completion_tokens = 5000
88+
89+
)
90+
91+
print(response.model_dump_json(indent=2))
92+
```
93+
94+
95+
# [Python (key-based auth)](#tab/python)
96+
97+
You may need to upgrade your version of the OpenAI Python library to take advantage of the new `max_completion_tokens` parameter.
98+
99+
```cmd
100+
pip install openai --upgrade
101+
```
102+
103+
```python
104+
105+
from openai import AzureOpenAI
106+
107+
client = AzureOpenAI(
108+
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
109+
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
110+
api_version="2024-09-01-preview"
111+
)
112+
113+
response = client.chat.completions.create(
114+
model="o1-preview-new", # replace with the model deployment name of your o1-preview, or o1-mini model
115+
messages=[
116+
{"role": "user", "content": "What steps should I think about when writing my first Python API?"},
117+
],
118+
max_completion_tokens = 5000
119+
120+
)
121+
122+
print(response.model_dump_json(indent=2))
123+
```
124+
125+
# [Output)](#tab/python-output)
126+
127+
```json
128+
{
129+
"id": "chatcmpl-AEj7pKFoiTqDPHuxOcirA9KIvf3yz",
130+
"choices": [
131+
{
132+
"finish_reason": "stop",
133+
"index": 0,
134+
"logprobs": null,
135+
"message": {
136+
"content": "Writing your first Python API is an exciting step in developing software that can communicate with other applications. An API (Application Programming Interface) allows different software systems to interact with each other, enabling data exchange and functionality sharing. Here are the steps you should consider when creating your first Python API:\n\n1. **Define the Purpose and Requirements**\n\n - **Identify the Functionality**: Clearly outline what your API is supposed to do. What data or services will it provide to the users?\n - **Determine the Endpoints**: Plan the different URLs (endpoints) through which users can access the API functionalities.\n - **Specify Request and Response Formats**: Decide on the data formats (usually JSON) for incoming requests and outgoing responses.\n\n2. **Choose the Right Framework**\n\n Python offers several frameworks for building APIs. Two of the most popular are:\n\n - **Flask**: A lightweight and flexible web framework, great for small to medium-sized APIs.\n - **FastAPI**: A modern, high-performance framework for building APIs with Python 3.6+ types, offering automatic interactive documentation.\n\n **Example**:\n ```bash\n pip install flask\n ```\n or\n ```bash\n pip install fastapi uvicorn\n ```\n\n3. **Set Up the Development Environment**\n\n - **Create a Virtual Environment**: Isolate your project dependencies using `venv` or `conda`.\n - **Install Required Packages**: Ensure all necessary libraries and packages are installed.\n\n **Example**:\n ```bash\n python -m venv env\n source env/bin/activate # On Windows use `env\\Scripts\\activate`\n ```\n\n4. **Implement the API Endpoints**\n\n - **Write the Code for Each Endpoint**: Implement the logic that handles requests and returns responses.\n - **Use Decorators to Define Routes**: In frameworks like Flask, you use decorators to specify the URL endpoints.\n\n **Example with Flask**:\n ```python\n from flask import Flask, request, jsonify\n\n app = Flask(__name__)\n\n @app.route('/hello', methods=['GET'])\n def hello_world():\n return jsonify({'message': 'Hello, World!'})\n\n if __name__ == '__main__':\n app.run(debug=True)\n ```\n\n5. **Handle Data Serialization and Deserialization**\n\n - **Parsing Incoming Data**: Use libraries to parse JSON or other data formats from requests.\n - **Formatting Output Data**: Ensure that responses are properly formatted in JSON or XML.\n\n6. **Implement Error Handling**\n\n - **Handle Exceptions Gracefully**: Provide meaningful error messages and HTTP status codes.\n - **Validate Input Data**: Check for required fields and appropriate data types to prevent errors.\n\n **Example**:\n ```python\n @app.errorhandler(404)\n def resource_not_found(e):\n return jsonify(error=str(e)), 404\n ```\n\n7. **Add Authentication and Authorization (If Necessary)**\n\n - **Secure Endpoints**: If your API requires, implement security measures such as API keys, tokens (JWT), or OAuth.\n - **Manage User Sessions**: Handle user login states and permissions appropriately.\n\n8. **Document Your API**\n\n - **Use Tools Like Swagger/OpenAPI**: Automatically generate interactive API documentation.\n - **Provide Usage Examples**: Help users understand how to interact with your API.\n\n **Example with FastAPI**:\n FastAPI automatically generates docs at `/docs` using Swagger UI.\n\n9. **Test Your API**\n\n - **Write Unit and Integration Tests**: Ensure each endpoint works as expected.\n - **Use Testing Tools**: Utilize tools like `unittest`, `pytest`, or API testing platforms like Postman.\n\n **Example**:\n ```python\n import unittest\n class TestAPI(unittest.TestCase):\n def test_hello_world(self):\n response = app.test_client().get('/hello')\n self.assertEqual(response.status_code, 200)\n ```\n\n10. **Optimize Performance**\n\n - **Improve Response Times**: Optimize your code and consider using asynchronous programming if necessary.\n - **Manage Resource Utilization**: Ensure your API can handle the expected load.\n\n11. **Deploy Your API**\n\n - **Choose a Hosting Platform**: Options include AWS, Heroku, DigitalOcean, etc.\n - **Configure the Server**: Set up the environment to run your API in a production setting.\n - **Use a Production Server**: Instead of the development server, use WSGI servers like Gunicorn or Uvicorn.\n\n **Example**:\n ```bash\n uvicorn main:app --host 0.0.0.0 --port 80\n ```\n\n12. **Monitor and Maintain**\n\n - **Logging**: Implement logging to track events and errors.\n - **Monitoring**: Use monitoring tools to track performance and uptime.\n - **Update and Patch**: Keep dependencies up to date and patch any security vulnerabilities.\n\n13. **Consider Versioning**\n\n - **Plan for Updates**: Use versioning in your API endpoints to manage changes without breaking existing clients.\n - **Example**:\n ```python\n @app.route('/v1/hello', methods=['GET'])\n ```\n\n14. **Gather Feedback and Iterate**\n\n - **User Feedback**: Encourage users to provide feedback on your API.\n - **Continuous Improvement**: Use the feedback to make improvements and add features.\n\n**Additional Tips**:\n\n- **Keep It Simple**: Start with a minimal viable API and expand functionality over time.\n- **Follow RESTful Principles**: Design your API according to REST standards to make it intuitive and standard-compliant.\n- **Security Best Practices**: Always sanitize inputs and protect against common vulnerabilities like SQL injection and cross-site scripting (XSS).\n- **Learn from Examples**: Look at open-source APIs on GitHub to understand best practices.\n\n**Resources to Help You Get Started**:\n\n- **Flask Documentation**: [https://flask.palletsprojects.com/](https://flask.palletsprojects.com/)\n- **FastAPI Documentation**: [https://fastapi.tiangolo.com/](https://fastapi.tiangolo.com/)\n- **Python Requests Library**: For interacting with APIs: [https://requests.readthedocs.io/](https://requests.readthedocs.io/)\n- **Postman**: A popular tool for testing APIs: [https://www.postman.com/](https://www.postman.com/)\n\nBy following these steps, you'll be well on your way to creating a functional and robust Python API. Good luck with your development!",
137+
"refusal": null,
138+
"role": "assistant",
139+
"function_call": null,
140+
"tool_calls": null
141+
},
142+
"content_filter_results": {
143+
"hate": {
144+
"filtered": false,
145+
"severity": "safe"
146+
},
147+
"protected_material_code": {
148+
"filtered": false,
149+
"detected": false
150+
},
151+
"protected_material_text": {
152+
"filtered": false,
153+
"detected": false
154+
},
155+
"self_harm": {
156+
"filtered": false,
157+
"severity": "safe"
158+
},
159+
"sexual": {
160+
"filtered": false,
161+
"severity": "safe"
162+
},
163+
"violence": {
164+
"filtered": false,
165+
"severity": "safe"
166+
}
167+
}
168+
}
169+
],
170+
"created": 1728073417,
171+
"model": "o1-preview-2024-09-12",
172+
"object": "chat.completion",
173+
"service_tier": null,
174+
"system_fingerprint": "fp_503a95a7d8",
175+
"usage": {
176+
"completion_tokens": 1843,
177+
"prompt_tokens": 20,
178+
"total_tokens": 1863,
179+
"completion_tokens_details": {
180+
"audio_tokens": null,
181+
"reasoning_tokens": 448
182+
},
183+
"prompt_tokens_details": {
184+
"audio_tokens": null,
185+
"cached_tokens": 0
186+
}
187+
},
188+
"prompt_filter_results": [
189+
{
190+
"prompt_index": 0,
191+
"content_filter_results": {
192+
"custom_blocklists": {
193+
"filtered": false
194+
},
195+
"hate": {
196+
"filtered": false,
197+
"severity": "safe"
198+
},
199+
"jailbreak": {
200+
"filtered": false,
201+
"detected": false
202+
},
203+
"self_harm": {
204+
"filtered": false,
205+
"severity": "safe"
206+
},
207+
"sexual": {
208+
"filtered": false,
209+
"severity": "safe"
210+
},
211+
"violence": {
212+
"filtered": false,
213+
"severity": "safe"
214+
}
215+
}
216+
}
217+
]
218+
}
219+
```
220+
221+
---
53222

54223
### Region availability
55224

articles/ai-services/openai/how-to/batch.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ In the Studio UI the deployment type will appear as `Global-Batch`.
8383
:::image type="content" source="../media/how-to/global-batch/global-batch.png" alt-text="Screenshot that shows the model deployment dialog in Azure OpenAI Studio with Global-Batch deployment type highlighted." lightbox="../media/how-to/global-batch/global-batch.png":::
8484

8585
> [!TIP]
86-
> Each line of your input file for batch processing has a `model` attribute that requires a global batch **deployment name**. For a given input file, all names must be the same deployment name. This is different from OpenAI where the concept of model deployments does not exist.
86+
> Each line of your input file for batch processing has a `model` attribute that requires a global batch **deployment name**. For a given input file, all names must be the same deployment name. This is different from OpenAI where the concept of model deployments does not exist.
87+
>
88+
> For the best performance, we recommend submitting large files for patch processing rather than a large number of small files with only a few lines in each file.
8789
8890
::: zone pivot="programming-language-ai-studio"
8991

articles/ai-services/openai/whats-new.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Customers who were already approved and have access to the model through the ear
3232

3333
Support for the **o1 series** models was added in API version `2024-09-01-preview`.
3434

35-
The `max_tokens` parameter has been deprecated and replaced with the new `max_completion_tokens` parameter. **o1 series** models will only work with the `max_completions_tokens` parameter.
35+
The `max_tokens` parameter has been deprecated and replaced with the new `max_completion_tokens` parameter. **o1 series** models will only work with the `max_completion_tokens` parameter.
3636

3737
**Region availability**:
3838

0 commit comments

Comments
 (0)