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

Sending base64 encoded Image to GPT-4o via API in Unity #125

Open
Zaf01 opened this issue Jul 11, 2024 · 0 comments
Open

Sending base64 encoded Image to GPT-4o via API in Unity #125

Zaf01 opened this issue Jul 11, 2024 · 0 comments

Comments

@Zaf01
Copy link

Zaf01 commented Jul 11, 2024

Hi,

How could I possibly send a base64 encoded image to gpt 4o using the API? Currently for sending text requests and getting responses from ChatGPT I have this function:

//Method to send text requests to chatgpt
public async void AskChatGPT(string newText)
{
debugText.SetText("AskChatGpt called!");

    Debug.Log("AskChatGPT function called with input: " + newText);

    ChatMessage newMessage = new ChatMessage();
    newMessage.Content = newText;
    newMessage.Role = "user";
    

    messages.Add(newMessage);

    CreateChatCompletionRequest request = new CreateChatCompletionRequest();
    request.Messages = messages;
    request.Model = "gpt-4o";


    var response = await openAI.CreateChatCompletion(request);

    if (response.Choices != null && response.Choices.Count > 0)
    {
        var chatResponse = response.Choices[0].Message;

        messages.Add(chatResponse);

        Debug.Log(chatResponse.Content);

        waitingForResponse = true;
        OnResponse.Invoke(chatResponse.Content);

        Debug.Log("Reponse Finished");

        waitingForResponse = false;
    }
}

I have the images already encoded as base64, but would appreciate some insights on how to feed it to gpt 4o using the APIs and specify what we are sending is an Image data.

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