Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,049 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm getting an 404 error the resources is not found, I want to call to my OpenAI resource. I don't know why I'm getting the error. I'll give the code below suggest if I'm missing anything
private async Task<string> TranslateTextWithOpenAI(string text, string targetLanguage)
{
var data = new
{
prompt = $"{text}\n\nTranslate this to {targetLanguage}." + OpenAIPrompt,
max_tokens = 200,
temperature = 0.7,
model = "text-davinci-003"
};
var content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json"); // this content is correct. - PDB
_httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", OpenAI_ApiKey);
var response = await _httpClient.PostAsync("https://myfoo.openai.azure.com/", content); // this call is failing - PDB
if (response.IsSuccessStatusCode)
{
var responseString = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<OpenAIResponse>(responseString);
return result.Choices[0].Text;
}
return null;
}
Hi
Jhope
Thanks for posting the question.
I think you are not passing the open ai completion endpoint correctly. let me give you an updated code let me know if it helps,
var data = new
{
prompt = $"{text}\n\nTranslate this to {targetLanguage}." + OpenAIPrompt,
max_tokens = 200,
temperature = 0.7
};
var dataJson = JsonSerializer.Serialize(data);
var content = new StringContent(dataJson, Encoding.UTF8, "application/json");
OpenAI_Endpoint = "https://{openairesource}.openai.azure.com/openai/deployments/test_chatgpt/completions?api-version=2023-09-15-preview";
httpClient.DefaultRequestHeaders.Add("api-key", OpenAI_ApiKey);
var response = await httpClient.PostAsync(OpenAI_Endpoint, content); // this call is failing - PDB
if (response.IsSuccessStatusCode)
{
var responseString = await response.Content.ReadAsStringAsync();
return responseString;
}
If this helps kindly accept the answer and thanks again.