From 40f70c99b096cf3f22ae721b2175fd344c72868c Mon Sep 17 00:00:00 2001 From: Amit Kalay <47650976+amitkalay@users.noreply.github.com> Date: Wed, 15 Jan 2025 21:12:04 +0000 Subject: [PATCH 1/5] writing some starter code which can fetch a secret securely --- just_trials.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 just_trials.py diff --git a/just_trials.py b/just_trials.py new file mode 100644 index 00000000..b82b6d0b --- /dev/null +++ b/just_trials.py @@ -0,0 +1,6 @@ +import os +from dotenv import load_dotenv +load_dotenv() +AZURE_CREDENTIAL = os.getenv('AZURE_CREDENTIAL') +a = 5 +print(f'the azure credential is: {AZURE_CREDENTIAL}') \ No newline at end of file From ff7661a88f6d6d30fa2f67c09c4621c54839ad64 Mon Sep 17 00:00:00 2001 From: Amit Kalay <47650976+amitkalay@users.noreply.github.com> Date: Wed, 15 Jan 2025 21:23:36 +0000 Subject: [PATCH 2/5] finished trial code --- just_trials.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/just_trials.py b/just_trials.py index b82b6d0b..2919b00c 100644 --- a/just_trials.py +++ b/just_trials.py @@ -1,6 +1,49 @@ import os from dotenv import load_dotenv +from azure.ai.inference import ChatCompletionsClient +from azure.core.credentials import AzureKeyCredential load_dotenv() -AZURE_CREDENTIAL = os.getenv('AZURE_CREDENTIAL') -a = 5 -print(f'the azure credential is: {AZURE_CREDENTIAL}') \ No newline at end of file + +api_key = os.getenv("AZURE_CREDENTIAL", '') +if not api_key: + raise Exception("A key should be provided to invoke the endpoint") + +client = ChatCompletionsClient( + endpoint='https://phi-3-5-2.eastus.models.ai.azure.com', + credential=AzureKeyCredential(api_key) +) + +model_info = client.get_model_info() +print("Model name:", model_info.model_name) +print("Model type:", model_info.model_type) +print("Model provider name:", model_info.model_provider_name) + +payload = { + "messages": [ + { + "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\n1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.\n2. 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.\n3. 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\nThese 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_tokens": 2048, + "temperature": 0.8, + "top_p": 0.1, + "presence_penalty": 0, + "frequency_penalty": 0 +} +response = client.complete(payload) + +print("Response:", response.choices[0].message.content) +print("Model:", response.model) +print("Usage:") +print(" Prompt tokens:", response.usage.prompt_tokens) +print(" Total tokens:", response.usage.total_tokens) +print(" Completion tokens:", response.usage.completion_tokens) \ No newline at end of file From 4dc12a6277bb82f6e955668963c6630a633336b5 Mon Sep 17 00:00:00 2001 From: Amit Kalay <47650976+amitkalay@users.noreply.github.com> Date: Wed, 15 Jan 2025 21:30:34 +0000 Subject: [PATCH 3/5] added code for the aoai model as well --- aoai_trial.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 aoai_trial.py diff --git a/aoai_trial.py b/aoai_trial.py new file mode 100644 index 00000000..9c01499b --- /dev/null +++ b/aoai_trial.py @@ -0,0 +1,58 @@ + +import os +import base64 +from openai import AzureOpenAI + +endpoint = os.getenv("ENDPOINT_URL", "https://azs-grok-aoai.openai.azure.com/") +deployment = os.getenv("DEPLOYMENT_NAME", "azs-grok-gpt-4o") +subscription_key = os.getenv("AZURE_OPENAI_API_KEY", "REPLACE_WITH_YOUR_KEY_VALUE_HERE") + +# Initialize Azure OpenAI Service client with key-based authentication +client = AzureOpenAI( + azure_endpoint=endpoint, + api_key=subscription_key, + api_version="2024-05-01-preview", +) + +# IMAGE_PATH = "YOUR_IMAGE_PATH" +# encoded_image = base64.b64encode(open(IMAGE_PATH, 'rb').read()).decode('ascii') + +# Prepare the chat prompt +chat_prompt = [ + { + "role": "system", + "content": [ + { + "type": "text", + "text": "You are an AI assistant that helps people find information." + } + ] + }, + { + "role": "user", + "content": [ + { + "type": "text", + "text": "How can I get better at pickleball?" + } + ] + } +] + +# Include speech result if speech is enabled +messages = chat_prompt + +# Generate the completion +completion = client.chat.completions.create( + model=deployment, + messages=messages, + max_tokens=800, + temperature=0.7, + top_p=0.95, + frequency_penalty=0, + presence_penalty=0, + stop=None, + stream=False +) + +print(completion.to_json()) \ No newline at end of file From 3705ef333488060cadaebeef89ff352f786a2bba Mon Sep 17 00:00:00 2001 From: Amit Kalay <47650976+amitkalay@users.noreply.github.com> Date: Wed, 15 Jan 2025 23:22:40 +0000 Subject: [PATCH 4/5] minor renaming of files --- aoai_trial.py | 3 +-- custom_model_trial.py | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 custom_model_trial.py diff --git a/aoai_trial.py b/aoai_trial.py index 9c01499b..b354ac9c 100644 --- a/aoai_trial.py +++ b/aoai_trial.py @@ -1,7 +1,6 @@ - import os import base64 -from openai import AzureOpenAI +from openai import AzureOpenAI endpoint = os.getenv("ENDPOINT_URL", "https://azs-grok-aoai.openai.azure.com/") deployment = os.getenv("DEPLOYMENT_NAME", "azs-grok-gpt-4o") diff --git a/custom_model_trial.py b/custom_model_trial.py new file mode 100644 index 00000000..69dab404 --- /dev/null +++ b/custom_model_trial.py @@ -0,0 +1,49 @@ +import os +from dotenv import load_dotenv +from azure.ai.inference import ChatCompletionsClient +from azure.core.credentials import AzureKeyCredential +load_dotenv() + +api_key = os.getenv("AZURE_CREDENTIAL", '') +if not api_key: + raise Exception("A key should be provided to invoke the endpoint") + +client = ChatCompletionsClient( + endpoint='https://phi-3-5-2.eastus.models.ai.azure.com', + credential=AzureKeyCredential(api_key) +) + +model_info = client.get_model_info() +print("Model name:", model_info.model_name) +print("Model type:", model_info.model_type) +print("Model provider name:", model_info.model_provider_name) + +payload = { + "messages": [ + { + "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\n1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.\n2. 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.\n3. 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\nThese 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_tokens": 2048, + "temperature": 0.8, + "top_p": 0.1, + "presence_penalty": 0, + "frequency_penalty": 0 +} +response = client.complete(payload) + +print("Response:", response.choices[0].message.content) +print("Model:", response.model) +print("Usage:") +print("Prompt tokens:", response.usage.prompt_tokens) +print("Total tokens:", response.usage.total_tokens) +print("Completion tokens:", response.usage.completion_tokens) \ No newline at end of file From 02f64de09d197dd55fb7f00663ced5aff0e150dc Mon Sep 17 00:00:00 2001 From: Amit Kalay <47650976+amitkalay@users.noreply.github.com> Date: Wed, 15 Jan 2025 23:31:42 +0000 Subject: [PATCH 5/5] delete old file --- just_trials.py | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 just_trials.py diff --git a/just_trials.py b/just_trials.py deleted file mode 100644 index 2919b00c..00000000 --- a/just_trials.py +++ /dev/null @@ -1,49 +0,0 @@ -import os -from dotenv import load_dotenv -from azure.ai.inference import ChatCompletionsClient -from azure.core.credentials import AzureKeyCredential -load_dotenv() - -api_key = os.getenv("AZURE_CREDENTIAL", '') -if not api_key: - raise Exception("A key should be provided to invoke the endpoint") - -client = ChatCompletionsClient( - endpoint='https://phi-3-5-2.eastus.models.ai.azure.com', - credential=AzureKeyCredential(api_key) -) - -model_info = client.get_model_info() -print("Model name:", model_info.model_name) -print("Model type:", model_info.model_type) -print("Model provider name:", model_info.model_provider_name) - -payload = { - "messages": [ - { - "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\n1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.\n2. 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.\n3. 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\nThese 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_tokens": 2048, - "temperature": 0.8, - "top_p": 0.1, - "presence_penalty": 0, - "frequency_penalty": 0 -} -response = client.complete(payload) - -print("Response:", response.choices[0].message.content) -print("Model:", response.model) -print("Usage:") -print(" Prompt tokens:", response.usage.prompt_tokens) -print(" Total tokens:", response.usage.total_tokens) -print(" Completion tokens:", response.usage.completion_tokens) \ No newline at end of file