• 07-08-2024, 15:22:40
    #1
    Merhabalar, asp.net c# web tabanlı projemde open ai entegrasyonu yapmaya çalışırken aşağıdaki hatayı alıyorum.

    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 } }



    Projemdeki kodlar bu şekilde

    var openAiApiKey = "";

    APIAuthentication aPIAuthentication = new APIAuthentication(openAiApiKey);
    OpenAIAPI openAiApi = new OpenAIAPI(aPIAuthentication);


    try
    {
    string prompt = "Nasılsın";
    string model = "gpt-4";
    int maxTokens = 50;

    var completionRequest = new CompletionRequest
    {
    Prompt = prompt,
    Model = model,
    MaxTokens = maxTokens


    };

    var completionResult = await openAiApi.Completions.CreateCompletionAsync(comple tionRequest);
    var generatedText = completionResult.Completions[0].Text; //completionResult.Choices[0].Text.Trim();

    lblUyari.Text = generatedText;
    }
    catch (Exception ex)
    {
    lblUyari.Text = ex.Message;
  • 07-08-2024, 15:26:24
    #2
    İstek attığın url sonuna "?" ekleyip dener misin
  • 07-08-2024, 16:35:26
    #3
    using OpenAI_API;
    using OpenAI_API.Chat;

    var openAiApiKey = "";

    APIAuthentication aPIAuthentication = new APIAuthentication(openAiApiKey);
    OpenAIAPI openAiApi = new OpenAIAPI(aPIAuthentication);

    try
    {
    string prompt = "Nasılsın";
    string model = "gpt-4";
    int maxTokens = 50;

    var chatRequest = new ChatRequest
    {
    Messages = new List<ChatMessage>
    {
    new ChatMessage
    {
    Role = "user",
    Content = prompt
    }
    },
    Model = model,
    MaxTokens = maxTokens
    };

    var chatResult = await openAiApi.Chat.CreateChatCompletionAsync(chatReque st);
    var generatedText = chatResult.Choices[0].Message.Content;

    lblUyari.Text = generatedText;
    }
    catch (Exception ex)
    {
    lblUyari.Text = ex.Message;
    }



    tekrar denermisin
  • 07-08-2024, 17:11:13
    #4
    Parzil07 adlı üyeden alıntı: mesajı görüntüle
    using OpenAI_API;
    using OpenAI_API.Chat;

    var openAiApiKey = "";

    APIAuthentication aPIAuthentication = new APIAuthentication(openAiApiKey);
    OpenAIAPI openAiApi = new OpenAIAPI(aPIAuthentication);

    try
    {
    string prompt = "Nasılsın";
    string model = "gpt-4";
    int maxTokens = 50;

    var chatRequest = new ChatRequest
    {
    Messages = new List<ChatMessage>
    {
    new ChatMessage
    {
    Role = "user",
    Content = prompt
    }
    },
    Model = model,
    MaxTokens = maxTokens
    };

    var chatResult = await openAiApi.Chat.CreateChatCompletionAsync(chatReque st);
    var generatedText = chatResult.Choices[0].Message.Content;

    lblUyari.Text = generatedText;
    }
    catch (Exception ex)
    {
    lblUyari.Text = ex.Message;
    }



    tekrar denermisin
    Teşekkür ederim hocam, ufak bir değişiklikle halloldu