OpenAI's DALLE-2 usage in TouchDesigner

As some of you may already know, as of tonight OpenAI is offering API usage for DALLE-2.

I’m having a hard time trying to make a request through the DAT operators. Can someone help me accomplish this task? [I’m not exactly sure where and how I am supposed to include the prompt, to be more precise.]

Here’s the documentation: OpenAI API

1 Like

Anyone? I’m sure it is super simple, but I haven’t been able to.

Use the second input of the WebClient DAT to pass the data, explained on the following page: https://docs.derivative.ca/Web_Client_DAT

The error message you get back from OpenAI API’s is indeed stating that it is not receiving anything in the body.

From the following page: OpenAI API

Try to add another table DAT with the following:

{
  "prompt": "A cute baby sea otter",
  "n": 2,
  "size": "1024x1024"
}
prompt | A cute baby sea otter
n | 2
size | 1024x1024

I hope this helps,

Best,
Michel

Hey, Michel! Thank you very much for your response.

I’ve already tried what you sugested, and this is the result:

HTTP/1.1 400 BAD REQUEST
Date: Sat, 05 Nov 2022 22:34:19 GMT
Content-Type: application/json
Content-Length: 191
Connection: keep-alive
Access-Control-Allow-Origin: *
OpenAI-Version: 2020-10-01
OpenAI-Organization: user-k23mfoh3dpkhqbj0lw7osoc2
X-Request-ID: bcd5d933be69e66c0c41f861af0aea45
OpenAI-Processing-Ms: 85
Strict-Transport-Security: max-age=15724800; includeSubDomains
{
  "error": {
    "code": null,
    "message": "Your request contained invalid JSON: Expecting value: line 1 column 1 (char 0)",
    "param": null,
    "type": "invalid_request_error"
  }
}

What may be happening? I’ve also tried to pass it has text, same result.

What if you pass the same JSON in a text DAT directly ?

Keep the first input as-is, then on the second input connect a text DAT with the following:

{
  "prompt": "A cute baby sea otter",
  "n": 2,
  "size": "1024x1024"
}

This is valid JSON.

Now I’m getting this error message:

{
  "error": {
    "code": "billing_hard_limit_reached",
    "message": "Billing hard limit has been reached",
    "param": null,
    "type": "invalid_request_error"
  }
}

Still something wrong with the request, it seems. From what I’ve checked, my OpenAI account is working just fine. [Credits, status, etc.]

Hey @uisato

I had no issues getting it to work on my end. It could be that you were rate limited.

Here are two “cute” baby sea otters.


Just add your token after the "Bearer " string in the table1 TableDAT of the file here and it should get you going.

Take time to compare the settings of the WebClient DAT webclient1 with the one in your file, to understand which settings you might have missing.

openAI_API_TEST.toe (4.1 KB)

If it doesn’t work, I’d suggest getting support from OpenAI.

Best,
Michel

1 Like

You were right! There was an issue with my account. Already solved!

Thank you very much, Michel :heart:

Hey, Michel! If you don’t mind, I’ve got a little question regarding DATs.

I’d like to change the prompt not from the request text, but from the ‘prompt1’ DAT.

Is there any way to accomplish that? I thought about including the famous op(‘prompt1’).text in the request text but that’s not possible I think.

Thank you very much in advance for your help! :heart:

Hey,

There is a few ways to get the result you want but I wasn’t happy with any of those really.

What I’ve ended up doing is build the JSON out of some custom parameters.

In the attached file, you have the Prompt parameters on the custom COMP PromptBuilder.

When you change any of the parameters, it updates the underlying JSON. You can then execute your request to the OpenAI API.

In the attached example, prompt1 text is referenced in the prompt parameter so this should be pretty plug n play with your screenshot above.

If you have additional parameters to pass or want to customize the JSON, you can add custom parameters to the PromptBuilder page, or tweak the python code in the Parameter Execute DAT at PromptBuilder/..

Best,
Michel
openAI_API_TEST_Par_To_PromptJSON.toe (4.8 KB)

1 Like