最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin4PV0评论

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));
Post a comment

comment list (0)

  1. No comments so far