fafrd / aquarium

AI-controlled Linux Containers
GNU General Public License v3.0
662 stars 38 forks source link

GPT 3.5 turbo #4

Closed vio1ator closed 1 year ago

vio1ator commented 1 year ago

I've asked GPT-4 to modify the genDialogue() function to use gpt-3.5-turbo instead. Seems to work fine for me. I'm not familiar with Go can someone take a look and see if it looks good?

func genDialogue(aiPrompt string) (string, error) {
    apiKey := os.Getenv("OPENAI_API_KEY")
    if apiKey == "" {
        return "", errors.New("undefined env var OPENAI_API_KEY")
    }

    ctx := context.Background()
    client := gpt3.NewClient(apiKey)

    messages := []gpt3.ChatCompletionRequestMessage{
        {
            Role:    "user",
            Content: aiPrompt,
        },
    }

    logger.Debugf("### Sending request to OpenAI:\n%s\n\n", aiPrompt)

    request := gpt3.ChatCompletionRequest{
        Model:        "gpt-3.5-turbo",
        Messages:     messages,
        MaxTokens:    tokens,
        Temperature:  gpt3.Float32Ptr(0.0),
    }

    resp, err := client.ChatCompletion(ctx, request)
    if err != nil {
        logger.Debugf("### ERROR from OpenAI:\n%s\n\n", err)
        return "", err
    }

    trimmedResponse := strings.TrimSpace(resp.Choices[0].Message.Content)
    logger.Debugf("### Received response from OpenAI:\n%s\n\n\n", trimmedResponse)
    return trimmedResponse, nil
}
ttulttul commented 1 year ago

So far so good. Using GPT-3.5 greatly improved the output.

fafrd commented 1 year ago

Oh hell yea. I'll incorporate this into the codebase today

ttulttul commented 1 year ago

Note that the check for using too many tokens isn't correct for 3.5. I'm working on a patch.

ttulttul commented 1 year ago

Actor c4cc41ce fatal error: [400:invalid_request_error] This model's maximum context Setting up libpython3.10-dev:arm64 (3.10.6-1~22.04.2ubuntu1) ... length is 4097 tokens. However, your messages resulted in 5382 tokens. Please reduce the Setting up python3-pip (22.0.2+dfsg-1ubuntu0.2) ... length of the messages. Setting up python3.10-dev (3.10.6-1~22.04.2ubuntu1) ... c4cc41ce: cleaning up container

fafrd commented 1 year ago

Completed this @ttulttul- sorry if I preempted you

ttulttul commented 1 year ago

No worries!