adamrushy / OpenAISwift

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

The operation couldn’t be completed. (OpenAISwift.OpenAIError error 2.) #95

Closed ChickenRei closed 11 months ago

YamikoHikariX commented 12 months ago

I get the same error. I use the sendChat command and supply an array of ChatMessages to it to provide the whole chat to GPT. It happens when there are lot of messages so I think the problem is when the tokens of all the provided ChatMessages exceeds the token limit of the model. In my case I use 3.5 turbo which has 4096 tokens. I coded it so that it counts each message's tokens using this encoder but even at 3500 tokens it gives this error. Maybe it's related to the amount of ChatMessages supplied?

Anyway, I tested it and at 93 messages which have 3183 tokens it replied. Above that it kept giving an error. That was just one test though

adamrushy commented 11 months ago

I believe this is related to the API and not the framework, feel free to provide more information though :]

YamikoHikariX commented 11 months ago

I think I found one of the causes of this error. I have several AI configurations in my app, each with different settings. In one of the configurations I accidentally set the topProbabilityMass to 9.0 instead of 0.9, which is outside of the allowed range for this value. So basically make sure all the values in the API call conform to the requirements of the API