OkGoDoIt / OpenAI-API-dotnet

An unofficial C#/.NET SDK for accessing the OpenAI GPT-3 API
https://www.nuget.org/packages/OpenAI/
Other
1.86k stars 430 forks source link

Call from Main? #170

Open JohnStraumann66 opened 1 year ago

JohnStraumann66 commented 1 year ago

When I try to specify a model: var varResponse = await api.Completions.CreateCompletionAsync(strPrompt, model: "gpt-3.5-turbo", max_tokens: maxTokens, temperature: itemp); or var varResponse = await api.Completions.CreateCompletionAsync(strPrompt, model: "gpt-4", max_tokens: maxTokens, temperature: itemp);

I get a response error:

An error occurred: Error at completions (https://api.openai.com/v1/completions) with HTTP status code: NotFound. Content: { "error": { "message": "This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?", "type": "invalid_request_error", "param": "model", "code": null } }

any tip on how to fix that?

bawkee commented 1 year ago

That is returned by OpenAI and it tells you that the models you specified (gpt3.5-turbo and gpt-4) are not compatible with the v1/completions endpoint. On their compatibility table they are, but on the playground, you can't do it. So I assume it is deprecated now, and I can't see the pricing for it either any more. The whole completion endpoint will become deprecated soon so you will have to use chat endpoint anyway.

OkGoDoIt commented 11 months ago

Hey @JohnStraumann66, sorry for the delayed reply. The Completions endpoint is legacy and not compatible with most of the models. Use the Chat endpoint instead. See https://github.com/OkGoDoIt/OpenAI-API-dotnet?tab=readme-ov-file#chat-api for details, but in your example:

var varResponse = await api.Chat.CreateChatCompletionAsync(new ChatRequest()
{
    Model = Model.GPT4,
    Temperature = itemp,
    MaxTokens = maxTokens,
    Messages = new ChatMessage[] {
        new ChatMessage(ChatMessageRole.User, strPrompt)
    }
})

If you really do want to use the legacy Completions API, then try the Model.ChatGPTTurboInstruct model. For example:

var varResponse = await api.Completions.CreateCompletionAsync(strPrompt, model: Model.ChatGPTTurboInstruct, max_tokens: maxTokens, temperature: itemp);