Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry after #51

Open
ahmadmayahi opened this issue Jul 3, 2023 · 3 comments
Open

retry after #51

ahmadmayahi opened this issue Jul 3, 2023 · 3 comments
Assignees

Comments

@ahmadmayahi
Copy link

At times, ChatGPT may display the following error message: "That model is currently overloaded with other requests." This issue arises due to the high volume of users attempting to access the API.

To address this problem, referring to the documentation, it is recommended to retry the request after a certain period of time. Adding a 'retryAfter' method, akin to Laravel's 'Http::retry()', could potentially resolve this issue.

@haydar
Copy link

haydar commented Jul 5, 2023

It was something I was thinking add a retry mechanism either. HTTP::retry() won't work because of package uses guzzle client not HTTP facade. Is there a retry-after param on response header in this sitution?

I will open a pr for this feature.

@giancarloerra
Copy link

Until we get this feature (great feature request), do you have any suggestions to deal correctly with HTTP error codes or error messages like the model overload?
Do I understand correctly that openai-php doesn't provide direct way to easily deal with errors?

@ahmadmayahi
Copy link
Author

@giancarloerra

I solved it by switching to Laravel's Http client which is built on top of Guzzle.

Actually, you don't need a package for OpenAI, Guzzle is more than enough. Because OpenAI API is very easy to use.

 return Http::withToken($token)
            ->baseUrl('https://api.openai.com/v1/')
            ->retry(5, 500)
            ->post('https://api.openai.com/v1/chat/completions',
                [
                    'model' => 'gpt-4',
                    'messages' => [
                        [
                            'role' => 'system',
                            'content' => 'You are a helpful assistant.',
                        ],
                        [
                            'role' => 'user',
                            'content' => $prompt,
                        ],
                    ],
                    'functions' => [
                        [
                            'name' => $function, 'parameters' => config('schema.'.$function),
                        ],
                    ],
                    'function_call' => [
                        'name' => $function,
                    ],
                    'temperature' => 0.6,
                    'top_p' => 1,
                ]
            )
            ->throw()
            ->json();

That's it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants