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

Bad gateway/cf_bad_gateway/null on long token request #89

Closed
alexanderradahl opened this issue Apr 30, 2023 · 1 comment
Closed

Bad gateway/cf_bad_gateway/null on long token request #89

alexanderradahl opened this issue Apr 30, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@alexanderradahl
Copy link

Describe the bug

I'm working on a school project to test the differences in content created by GPT-3 vs. 4, but to get the quantity for testing, I need to run a script that creates the content for me and saves it to a JSON file. But it doesn't seem like GPT-4 is handling big requests very well.

When I try to get a request from OpenAI with GPT-4, it seems to timeout even when I've increased the timeout 600 seconds.
I get "null" on the content, and oftentimes I also get "null" on the error message.
The few times I was able to produce an error message, I got "502 cf_bad_gateway".

To Reproduce

The title and the outline are generated by OpenAI with GPT-4 before this final request is made.

I run the below code with the following parameters:
keyword = expensive champagne
title = The Ultimate Guide to the Top 10 Most Expensive Champagnes: Is It Worth the Splurge?
outline = 1. Introduction to Expensive Champagne
1.1 - The allure of luxury champagne
1.2 - The role of expensive champagne in celebrations and special events

  1. Factors Contributing to the High Price of Champagne
    2.1 - Production process and limited availability
    2.2 - Prestigious brand reputation
    2.3 - Aging and maturation

  2. Top Expensive Champagne Brands
    3.1 - Dom Pérignon
    3.2 - Krug
    3.3 - Louis Roederer Cristal
    3.4 - Armand de Brignac
    3.5 - Moët & Chandon

  3. The Taste of Luxury: What Sets Expensive Champagne Apart
    4.1 - Flavor profile and complexity
    4.2 - Fine bubbles and mouthfeel
    4.3 - Pairing expensive champagne with food

  4. The Role of Expensive Champagne in Popular Culture
    5.1 - Iconic moments in movies and television
    5.2 - Celebrity endorsements and collaborations
    5.3 - Expensive champagne in music and lyrics

  5. Investing in Expensive Champagne
    6.1 - Collecting and storing champagne
    6.2 - The potential for appreciation in value
    6.3 - Risks and rewards of investing in champagne

  6. The Experience: Sipping on Expensive Champagne
    7.1 - Champagne etiquette and rituals
    7.2 - Best glassware for enjoying luxury champagne
    7.3 - Creating memorable moments with expensive champagne

  7. Conclusion: The Enduring Appeal of Expensive Champagne
    8.1 - The timeless nature of luxury
    8.2 - The joy of indulging in life's finer pleasures

Code snippets

function get_article_content($open_ai, $article_outline, $article_title, $keyword) {
    $model = 'gpt-4';
    $retry = false;
    $content_chat_decoded = null;
    $error_message = null;

    do {
        $open_ai->setTimeout(300);
        $content_chat = $open_ai->chat([
            'model' => $model,
            'messages' => [
                [
                    "role" => "system",
                    "content" => "You're AI article writer and SEO expert, you write the most amazing content.
            Each article you write should contain the following:
            - The article should be at least 1500 words, ideally 2000 words in total.
            - Start the article with an introduction. The introduction should not have a heading."
                ],
                [
                    "role" => "user",
                    "content" => "{$article_outline}
            Title: {$article_title}
            SEO keyword: {$keyword}
            Write the article:"
                ],
            ],
            'temperature' => 0.7,
            'max_tokens' => 4000,
            'frequency_penalty' => 0,
            'presence_penalty' => 0,
        ]);

        $content_chat_decoded_raw = json_decode($content_chat);
        $content_chat_decoded = $content_chat_decoded_raw->choices[0]->message->content;

        // Check for any error in the response
        if (isset($content_chat_decoded_raw->error)) {
            $retry = true;
            $model = 'gpt-4-0314';

            // Store the error message
            $error_message = $content_chat_decoded_raw->error->message;
        } else {
            $retry = false;
        }

    } while ($retry);

    return [$content_chat_decoded, $error_message];
}

// 3. Write out the article, keeping in mind to SEO optimize for the keyword
list($content_chat_decoded, $error_message) = get_article_content($open_ai, $article_outline, $article_title, $keyword);
$article_content = $content_chat_decoded;

OS

Ubuntu 20

PHP version

PHP 7.1.1-1

Library version

openai v3.0.1

@alexanderradahl alexanderradahl added the bug Something isn't working label Apr 30, 2023
@orhanerday
Copy link
Owner

Could you please post this question on our Discord Server? This area is intended for Library-related inquiries. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants