Spaces:
Runtime error
Runtime error
Download azurel/tutorial1.py from abhishek2406/question_Paper: direct link, hf CLI and curl.
- Browser
- Download file 3.9 kB
-
https://huggingface.co/spaces/abhishek2406/question_Paper/resolve/main/azurel/tutorial1.py
- Command line
-
hf download hf://spaces/abhishek2406/question_Paper/azurel/tutorial1.py
-
curl -L -o tutorial1.py https://huggingface.co/spaces/abhishek2406/question_Paper/resolve/main/azurel/tutorial1.py
3.9 kB
| import os | |
| #from azure.core.credentials import AzureKeyCredential | |
| from openai import AzureOpenAI | |
| client = AzureOpenAI( | |
| api_version="2024-12-01-preview", | |
| endpoint="https://learningabhishekquestionmakerapp.openai.azure.com/", | |
| credential=os.getenv('AZURE_OPENAI_API_KEY'), | |
| ) | |
| endpoint = "https://learningabhishekquestionmakerapp.openai.azure.com/" | |
| model_name = "gpt-4.1" | |
| deployment = "gpt-4.1" | |
| subscription_key = "<your-api-key>" | |
| api_version = "2024-12-01-preview" | |
| client = AzureOpenAI( | |
| api_version=api_version, | |
| azure_endpoint=endpoint, | |
| api_key=subscription_key, | |
| ) | |
| response = client.chat.completions.create( | |
| messages=[ | |
| { | |
| "role": "system", | |
| "content": "You are a helpful assistant.", | |
| }, | |
| { | |
| "role": "user", | |
| "content": "I am going to Paris, what should I see?", | |
| } | |
| ], | |
| max_completion_tokens=800, | |
| temperature=1.0, | |
| top_p=1.0, | |
| frequency_penalty=0.0, | |
| presence_penalty=0.0, | |
| model=deployment | |
| ) | |
| print(response.choices[0].message.content) | |
| ----------------- | |
| import os | |
| from openai import AzureOpenAI | |
| endpoint = "https://learningabhishekquestionmakerapp.openai.azure.com/" | |
| model_name = "gpt-4.1" | |
| deployment = "gpt-4.1" | |
| subscription_key = "<your-api-key>" | |
| api_version = "2024-12-01-preview" | |
| client = AzureOpenAI( | |
| api_version=api_version, | |
| azure_endpoint=endpoint, | |
| api_key=subscription_key, | |
| ) | |
| response = client.chat.completions.create( | |
| messages=[ | |
| { | |
| "role": "system", | |
| "content": "You are a helpful assistant.", | |
| }, | |
| { | |
| "role": "user", | |
| "content": "I am going to Paris, what should I see?", | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris:\n \n 1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.\n 2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.\n 3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows.\n \n These are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world.", | |
| }, | |
| { | |
| "role": "user", | |
| "content": "What is so great about #1?", | |
| } | |
| ], | |
| max_completion_tokens=800, | |
| temperature=1.0, | |
| top_p=1.0, | |
| frequency_penalty=0.0, | |
| presence_penalty=0.0, | |
| model=deployment | |
| ) | |
| print(response.choices[0].message.content) | |
| ---------------- | |
| #stream the output | |
| import os | |
| from openai import AzureOpenAI | |
| endpoint = "https://learningabhishekquestionmakerapp.openai.azure.com/" | |
| model_name = "gpt-4.1" | |
| deployment = "gpt-4.1" | |
| subscription_key = "<your-api-key>" | |
| api_version = "2024-12-01-preview" | |
| client = AzureOpenAI( | |
| api_version=api_version, | |
| azure_endpoint=endpoint, | |
| api_key=subscription_key, | |
| ) | |
| response = client.chat.completions.create( | |
| stream=True, | |
| messages=[ | |
| { | |
| "role": "system", | |
| "content": "You are a helpful assistant.", | |
| }, | |
| { | |
| "role": "user", | |
| "content": "I am going to Paris, what should I see?", | |
| } | |
| ], | |
| max_completion_tokens=800, | |
| temperature=1.0, | |
| top_p=1.0, | |
| frequency_penalty=0.0, | |
| presence_penalty=0.0, | |
| model=deployment, | |
| ) | |
| for update in response: | |
| if update.choices: | |
| print(update.choices[0].delta.content or "", end="") | |
| client.close() |