最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

azure openai - Getting "cannot convert" errors when initializing OpenAIClient variable - Stack Overflow

programmeradmin11浏览0评论

I am trying to get started using the Azure OpenAI tools to integrate OpenAI functionality into an application. But I have stranded at the first hurdle. Initializing the OpenAIClient object requires two parameters, endpoint url and key for my Azure AI subscription.

using Azure;
using Azure.AI.OpenAI; 
using OpenAI;
using OpenAI.Chat;

string endpoint = "/";
string key = "MYKEYVALUES";

OpenAIClient azureClient = new(
  new Uri(endpoint),
  new AzureKeyCredential(key));

However, I get an error for each of the two variables in the constructor:

  • new Uri(endpoint): Cannot convert from 'System.Uri' to 'System.ClientModel.ApiKeyCredential'
  • new AzureKeyCredential(key): Cannot convert from Azure.AzureKeyCredential to OpenAi.OpenAIClientOptions

These are basic setup steps included in several introductory tutorials/quickstarts on this, so most likely a super-basic issue. But would very much appreciate help to understand and fix this.

I am trying to get started using the Azure OpenAI tools to integrate OpenAI functionality into an application. But I have stranded at the first hurdle. Initializing the OpenAIClient object requires two parameters, endpoint url and key for my Azure AI subscription.

using Azure;
using Azure.AI.OpenAI; 
using OpenAI;
using OpenAI.Chat;

string endpoint = "https://MYURL.openai.azure/";
string key = "MYKEYVALUES";

OpenAIClient azureClient = new(
  new Uri(endpoint),
  new AzureKeyCredential(key));

However, I get an error for each of the two variables in the constructor:

  • new Uri(endpoint): Cannot convert from 'System.Uri' to 'System.ClientModel.ApiKeyCredential'
  • new AzureKeyCredential(key): Cannot convert from Azure.AzureKeyCredential to OpenAi.OpenAIClientOptions

These are basic setup steps included in several introductory tutorials/quickstarts on this, so most likely a super-basic issue. But would very much appreciate help to understand and fix this.

Share Improve this question asked Nov 18, 2024 at 19:13 Proposition JoeProposition Joe 4814 gold badges10 silver badges25 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

The reason you are getting this error is because the constructor you are using is for AzureOpenAIClient and not OpenAIClient.

Please change your code to

AzureOpenAIClient azureClient = new(
  new Uri(endpoint),
  new AzureKeyCredential(key));
发布评论

评论列表(0)

  1. 暂无评论