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

WARNING: Failed to retrieve data from OpenAI. Response code is 400 #3

Open
lowlune opened this issue Jan 10, 2024 · 1 comment
Open

Comments

@lowlune
Copy link

lowlune commented Jan 10, 2024

Function

Public Function GPT(ByVal strPrompt) As String
    
    'Purpose: This function is an example of how to create a UDF using the OpenAI API
    '         so that it can be called directly on a worksheet in Excel
    
    Dim oOpenAI As clsOpenAI
    Dim oMessages As New clsOpenAIMessages
    Dim oResponse As clsOpenAIResponse
    
    GPT = Empty
    
    Set oOpenAI = New clsOpenAI
    
    oOpenAI.API_KEY = API_KEY
    
    oMessages.AddUserMessage strPrompt

    Set oResponse = oOpenAI.ChatCompletion(oMessages)
    If Not oResponse Is Nothing Then
        GPT = oResponse.MessageContent
    End If
    
    Set oResponse = Nothing
    Set oOpenAI = Nothing
    Set oMessages = Nothing
End Function

Cell prompt

=GPT("As a marketing expert, your job is to figure out who would probably be most interested in a specific product or service, based on a short description. Please give a brief answer that includes the most likely characteristics of the customers. This should i"&"nclude things like their age, gender, how much money they make, what they're interested in, their habits, and what's important to them. This should all be related to the product and how it's meant to be used. Format your response exactly like this:
Targ"&"et Audience for [Instert Product or Service]
Target Audience Description:
Personality Attributes:
Age:
Income:
Interests:
Values:

This is the PRODUCT or SERVICE:"&A2)

Simpler prompts work:

=GPT("Say "&B8)
Cell B8 is "OK" and the response is "OK" so it works

or

=GPT("Say OK")

Any idea what causes the issue in longer prompts?

@lowlune
Copy link
Author

lowlune commented Jan 12, 2024

Token size is 3072, so that should not be issue. I managed to somehow get the cell to work, I think by removing \n (new lines), but the output was very broken. It contained \n everywhere.

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

1 participant