#API Web Requests Questions

85 messages · Page 1 of 1 (latest)

tribal torrent
#

Howdy;

Would this be a good place for questions related to using the API via web requests? I apologize if not, and would love to be pointed in the right direction if i may otherwise.

I have a couple questions about using it as I'm not using any common languages to create AI requests; I'm constructing my scripts via what's called DenizenScript and I specifically can only make web requests. I can specify headers, send data, and i can typically use any web method such as patch/post/etc;

but my first actual question is regarding the Moderation Content Policy endpoint. I know to:

  • make a request to https://api.openai.com/v1/moderations via a POST method
  • provide my headers as required,
  • submit my prompt to be analyzed in a map with the key input, an example of what i'm capable and most familiar with is:
    {"input":"message to be analyzed here"}

should i be submitting several requests? or is there a format that I can cram this all into one request? My first idea was just to send them all separated by new-lines
does this endpoint have any specified costs towards my token allowance? if so, what can i expect to pay?

vernal sail
#

@tribal torrent Ideally it'd be segmented. It doesn't cost anything

tribal torrent
#

thanks,

vernal sail
#

I'd personally cram maybe a paragraph? Really depends on how big the payload is, how often you believe it'll trigger, and how easy it is to find the offending part I guess

tribal torrent
#

i don't have a lot of data to send yet so i might work with both to determine the differences

#

another specific question i have is if it's possible to utilize the Create Image Edit endpoint https://api.openai.com/v1/images/edits to edit images with my limitations i kind of forced upon myself
i know to send an image, a mask when it's not totally transparent, a prompt
but i really only have experience with sending application/json Content-Type data...
I have tools to read an image file and convert it to either base64 or binary, but every input i've tried seems to fail and respond with saying that an image parameter is required, like it completely discarded my input

#

my request currently looks like this:
{"image":"X","prompt":"moonman face","n":5,"size":"512x512"}
where i've tried replacing x with just base64, data:image/png;base64,<the base64 data here>, and a few other variations just guessing but nothing works

#

it declined my Content-Type of application/json so i kind of uneducatedly guessed to use it's recommended multipart/form-data per the response it gave about curls, i'm not fully knowledgeable with web requests and i can't use an actual form-data like javascript could

vernal sail
#

Is there no way to use an easier language that comes with the bells and whistles to skip all that?

#

You could just use curl

tribal torrent
#

i don't know how to SCgrin i'm proficient in only the language i'm working with and i'm trying kind of hard to restrict myself from using other APIs because i have all this configured through a ton of my discord interactions

#

i struggle really hard with learning new things, which is a personal problem semi-unrelated

tribal torrent
vernal sail
#

Once you have to start dealing with things such as Base64 you've gone too deep 😂

#

Almost all tools use curl afaik to make http repuesta

#

Requests*

tribal torrent
#

my code looks like this:

- ~fileread path:../../test.png save:image
- define image <entry[image].data.to_base64>
- definemap headers:
      Authorization: <secret[ai]>
      Content-Type: multipart/form-data
      User-Agent: B
- definemap data:
      image: <[image]>
      prompt: moonman face
      n: 5
      size: 512x512
- ~webget <[url]> data:<[data].to_json[native_types=true]> headers:<[headers]>
```as just a rough example of what it might look like i have to work with, maybe
vernal sail
#

Looks good to me. You're sending form data

#

Unfortunately I can't help more than that. I'm not familiar in the language you're using

#

Oh

tribal torrent
#

oh?

vernal sail
#

At the bottom you say .to_json

tribal torrent
#

yeah

vernal sail
#

But you're not sending JSON

tribal torrent
#

oh, um

#

i guess i don't understand, i've only ever sent data in that json format, i expected {"image":"image but base64","prompt":"moonman face","n":5,"size":"512x512"} to just uh, work

#

how would i send the data if it's not formatted like json?

vernal sail
#

It'd be nice but no 😅

tribal torrent
#

just like... raw text? separated by newlines or something?

vernal sail
#

I'm not too sure with your language. You're sending the information as form data

tribal torrent
#

is there a method of visually seeing what the raw text looks like being sent correctly to mimic it?

vernal sail
#

Maybe try and just remove the to_json? 🤷‍♂️

tribal torrent
#

i could try sending literally
image: <[image]> prompt: moonman face n: 5 size: 512x512

vernal sail
#

As an object, yeah

#

Or a datamap

#

Worth a shot lol

tribal torrent
#

do you have any references i can look at of what those look like in text?

#

im not sure i have a tool that converts my content into an object or a real datamap

vernal sail
#

Can you not just send the data as is without calling to_json?

tribal torrent
#

yeah, i can send it as raw text, i've just never used an api that hasn't explicitly required json formatting before

#

(not to say it doesn't exist obviously, just have little experience currently)

vernal sail
#

It's not requiring JSON for image edits

#

It's requiring a multipart form which is what you have

#

Try sending it raw 🤷‍♂️

tribal torrent
#

yeah, i just the regular response variating different formats of just raw base64, it might be something i have to give up on SCWglitchblush

tribal torrent
vernal sail
#

You're not actually sending any images?

#
curl https://api.openai.com/v1/images/edits \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -F image='@otter.png' \
  -F mask='@mask.png' \
  -F prompt="A cute baby sea otter wearing a beret" \
  -F n=2 \
  -F size="1024x1024"
#

There's a raw request

#

You can put that in your command prompt on windows

tribal torrent
#

well, i'm opening the literal file like as if i opened it in a text file, converting it to base64, and submitting it

vernal sail
#

And it'll work. Well, it'll fail unless you had those images

#

The image should just be the regular image

#

Not converted

tribal torrent
#

ehm, lemme see if i can reference how it's actually handled,

#

this is a the relevant code, but i honestly don't know enough java to explain how this works internally:
https://github.com/DenizenScript/Denizen-Core/blob/master/src/main/java/com/denizenscript/denizencore/scripts/commands/file/FileReadCommand.java#L86
this is the command that "loads" the image into a variable for me to send as data
it's converted into what we call a BinaryTag; it's identify format is a hex encoding of the byte set, in order.
Each byte is encoding as an individual big-endian hexadecimal pair, like "FF" for byte=255, "00" for byte=0, "0F" for 15, "F0" for 240, ... etc. it's raw data
and then .to_base64 is just

        tagProcessor.registerStaticTag(ElementTag.class, "to_base64", (attribute, object) -> {
            return new ElementTag(Base64.getEncoder().encodeToString(object.data));
        });

(ref: https://github.com/DenizenScript/Denizen-Core/blob/master/src/main/java/com/denizenscript/denizencore/objects/core/BinaryTag.java#L179)

for more context, the language i know and am working with is called DenizenScript, which is a scripting language that we write in and feed into a scripting engine that handles everything else in uh, java heh

#

im in knees-deep, but i understand if this is probably just out of scope lol

#

we've done ridiculous things like ordering pizzas via scripts and api's in the past, but some more complicated problems required external api's and i don't exactly have that knowledge SCgrin

vernal sail
#

Without going too deep into the code it seems like you want the FileInputStream. The code is being converted for further handling

#

I may be wrong but the apparent solution would to reverse the process

#

Or, again, just find a way to do it simply

tribal torrent
#

can you help me with what FileInputStream is? or is that uh

#

something i should have implemented into the java code specifically?

tribal torrent
vernal sail
#

Afaik you'd have to edit the java. For some reason they convert it immediately from the file into a format for further work

tribal torrent
#

we do it for explicitly use-case scenarios, it's not exactly something we even recommend in the language
but i can digress on that with the developer of the main software

#

my last question was regarding fine-tuning;
per the discussion above, i have pretty strong restrictions i'm just holding against myself at this point lol
is there any method of handling uploading the file it's requesting for using fine-tuning with my model with an application/json content-type request? im struggling to fully understand the documentation on how it works and how it should be handled

#

sincerely appreciate your help as well, if i may add SCgrin

#

if the same concept applies here im happy to disregard the question

vernal sail
#

It should be very simple to read a file, save it to as a File class in Java, and then send it in the form

#

Fine tuning is JSON

#

If you are uploading the JSON file you'd do it in the same way as an image

#

Afterwards you'd use JSON to communicate

#

Personally I'd just do it myself via Python, or Curl

#

If a framework is causing obstacles, it may be best to take matters into your own hands.

#

With all the time it would take to communicate the necessity, or even find a way to send it, one could have just used a separate service and tied it in with the framework

#

I mean, we're talking about maybe 10 lines of code inside a function to do what you want

#

In Java

#

In Python it would be 10 exactly

tribal torrent
#

i can most likely learn enough Curl to execute this;
a bit offtopic, but i don't need to uh,
i see pip install --upgrade openai followed by a Curl example; do you mind i ask if there's any pip install's i need to install for Curl or other than noted:

Additionally, the OpenAI CLI requires python 3.
?

vernal sail
#

Python would be the best bet. Curl is convenient as it comes with Windows

#

Pip is what python uses to install the packages

#

The CLI I believe is just a tool to configure your training file for fine tuning

tribal torrent
#

oh, i see

#

the rest of this is going to have to be me forcing myself to learn new things i think. thank you very much for the help