adamrushy / OpenAISwift

This is a wrapper library around the ChatGPT and OpenAI HTTP API
MIT License
1.62k stars 246 forks source link

OpenAISwift.Choice(text:) are not fully completed when I print response #3

Closed asimcanyagiz closed 1 year ago

asimcanyagiz commented 1 year ago

When I make successfully api call response back like this.

"success(OpenAISwift.OpenAI(object: "text_completion", model: "text-davinci-003", choices: [OpenAISwift.Choice(text: "ma\n\nShadows Of The Night\n\nThe night stretches long, ")]))"

that's my code

func aichange(){ openAPI.sendCompletion(with: "bana ingilizce şiir yaz", model: .gpt3(.davinci)) { result in // Result<OpenAI, OpenAIError> // switch on result to get the response or error

        if case let .success(response) = result {
            if let firstChoice = response.choices.first {
                print(result) 
            }
        }
        if case let .failure(error) = result {
            print(error.localizedDescription) // Hata mesajını yazdırır
        }
    }
}

The text "ma\n\nShadows Of The Night\n\nThe night stretches long, "

adamrushy commented 1 year ago

Ah, so you need to access firstChoice.text in your example you're accessing the first Choice but then printing result which is the full object.

asimcanyagiz commented 1 year ago

Yes but even like this its only write to terminal "ma", "Shadows Of The Night", "The night stretches long" in line by line. I think probably answer of api long than this because this answer doesn't mean anything.

My prompt to api ""bana ingilizce şiir yaz" is mean write to English poem

asimcanyagiz commented 1 year ago

I don't know what elements do but there is a character limit for AI responses

adamrushy commented 1 year ago

Aha! Thank you for reporting, I found the issue. We need to allow consumers to pass in max_tokens because the API defaults to 16. PR is coming now 👍🏼

adamrushy commented 1 year ago

New version released 1.1.1 - thanks again 👏🏼