pythonopenai-apiazure-openaigpt-4

How can I find out the location of the endpoint when using openai Python library and Azure OpenAI?


E.g., when I make a basic Azure OpenAI request, I don't see the endpoint in the response object:

#Note: This code sample requires OpenAI Python library version 1.0.0 or higher.
import json
import pprint
from openai import AzureOpenAI

client = AzureOpenAI(
  azure_endpoint = "https://xxxxxx.openai.azure.com/",
  api_key='xxxxxxxxxxxxxxxxxxxxx',
  api_version="2023-07-01-preview"
)

message_text = [{"role":"system","content":"You are an AI assistant that helps people find information."}]
completion = client.chat.completions.create(
  model="gpt-4xxxxxxxx", 
  messages = message_text,
  temperature=0.7,
  max_tokens=800,
  top_p=0.95,
  frequency_penalty=0,
  presence_penalty=0,
  stop=None
)

print('completion:\n')
pprint.pprint(completion)

# Convert Python object to JSON
json_data = json.dumps(completion, default=lambda o: o.__dict__, indent=4)

# Print JSON
print(json_data)

Looking at the output, the response object completion contains:

ChatCompletion(id='chatcmpl-xxxxxxxxx', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='Great! How can I assist you today?', role='assistant', function_call=None, tool_calls=None), content_filter_results={'hate': {'filtered': False, 'severity': 'safe'}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}})], created=1709313222, model='gpt-4', object='chat.completion', system_fingerprint='fp_xxxxx', usage=CompletionUsage(completion_tokens=9, prompt_tokens=18, total_tokens=27), prompt_filter_results=[{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}])

How can I find out the location of the endpoint when using openai Python library and Azure OpenAI?


I know that one may view the location on https://portal.azure.com/:

enter image description here

but I don't have access to all Azure OpenAI instances that I work with in my account.


Solution

  • As mentioned in the comments, AzureOpenAI is not the right SDK/library to get the information about the geo-location of your Azure OpenAI service instance. It is essentially a wrapper over OpenAI REST API.

    The functionality you are looking for is a control-plane activity and you will need to use Azure Resource Manager REST API for that. The correct SDK/library for that would be azure-ai-resources. You can learn more about it here: https://learn.microsoft.com/en-us/python/api/overview/azure/ai-resources-readme?view=azure-python-preview&preserve-view=true.