Reputation: 497
I am calling an Azure OpenAI end point using openAI nuget package and I am able to connect to it when I am using CreateCompletionAsync method but when I use the CreateChatCompletionAsync method for the same URL I get 404:Resource not found error message
In the below code method 1 and method 2 are using CreateCompletionAsync which works fine but not method 3 and 4 which is using the CreatChatCompeletionAsync
using System;
using System.Threading.Tasks;
using OpenAI_API;
using OpenAI_API.Chat;
using OpenAI_API.Completions;
using OpenAI_API.Models;
using OpenAI_API.Moderation;
class Program
{
static async Task Main(string[] args)
{
APIAuthentication aPIAuthentication = new APIAuthentication("my_key");
//Initialize the OpenAI client for Azure
var api = OpenAIAPI.ForAzure("chatgpt", "ddic", aPIAuthentication);
//Method 1: this first call works to the same API end point
var prompt = "If I could fly";
var model = "ddic";
var result = await api.Completions.CreateCompletionAsync(prompt,model);
// Print the generated text to the console
Console.WriteLine(result);
//MEthod 2: this second call also works for the same epi endpoint
var completionRequest = new CompletionRequest();
string[] multiPrompt = { "Hello World", "Once upon a time" };
completionRequest.MultiplePrompts = multiPrompt;
completionRequest.Model = model;
completionRequest.user = ChatMessageRole.User;
var result1 = await api.Completions.CreateCompletionAsync(completionRequest);
//Method 3: for the next two call I get the folowing error
// (end_point) with HTTP status code: NotFound. Content: {"error":{"code":"404","message": "Resource not found"}}
var response = await api.Chat.CreateChatCompletionAsync (new ChatRequest()
{
Model = "ddic",
Temperature = 0.1,
MaxTokens = 50,
Messages = new ChatMessage[] {
new ChatMessage(ChatMessageRole.System, "you are an assistant that gives me information about products, including their cost."),
new ChatMessage(ChatMessageRole.User, "Tesla")
}
});
IList<ChatMessage> messages = new List<ChatMessage>
{
new ChatMessage(ChatMessageRole.System, "you are an assistant that gives me information about products, including their cost."),
new ChatMessage(ChatMessageRole.User, "Tesla")
};
//Method 4
var response1 = await api.Chat.CreateChatCompletionAsync(messages, "ddic");
var reply = response1.Choices[0].Message;
Console.WriteLine($"{reply.Role}: {reply.Content.Trim()}");
}
}
Upvotes: 0
Views: 1726
Reputation: 132
Create completions for chat messages with the ChatGPT (preview) and GPT-4 (preview) models. Chat completions are currently only available with api-version=2023-03-15-preview.
Upvotes: 0