#OpenAi

1 messages · Page 1 of 1 (latest)

dull depot
#

help me

neat surgeBOT
#

<@&987246399047479336> please have a look, thanks.

#

You can use </chatgpt:1108714622413963314> to ask ChatGPT about your question while you wait for a human to respond.

#

Please don't ask to ask, nor only say hello, just ask your actual question right away, thanks cat_thumbs_up

If you want to read about the details of why this is better, check out:
https://dontasktoask.com/

Don't ask to ask, just ask

maiden mauve
#

what do u need help on

dull depot
#
package org.mycompany;

import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

public class OpenAIAPIClient {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://api.openai.com/v1/engines/davinci-codex/completions");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Authorization", "Bearer -------");
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setDoOutput(true);

            // Gönderilecek veriyi oluştur
            String inputJson = "{\"prompt\": \"Once upon a time\", \"max_tokens\": 100}";
            try (OutputStream os = conn.getOutputStream()) {
                byte[] input = inputJson.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
            }

            // Yanıtı oku
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

            System.out.println(response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}```
harsh terrace
#

yeah and?

dull depot
#

it is give IOException

harsh terrace
#

share it

#

also dont just catch all Exception

#

and instead some specific

dull depot
#
java.io.FileNotFoundException: https://api.openai.com/v1/engines/davinci-codex/completions
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1994)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1599)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:223)
    at org.mycompany.OpenAIAPIClient.main(OpenAIAPIClient.java:28)```
neat surgeBOT
# dull depot ``` java.io.FileNotFoundException: https://api.openai.com/v1/engines/davinci-cod...

Detected code, here are some useful tools:

Formatted code
java.io.FileNotFoundException : https : //api.openai.com/v1/engines/davinci-codex/completions
at java.base / sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java : 1994) at java.base / sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java : 1599) at java.base / sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java : 223) at org.mycompany.OpenAIAPIClient.main(OpenAIAPIClient.java : 28)
dense shale
#

Out of curiousity, did you ask chatGPT to generate you that code?

dull depot
#

yes

maiden mauve
#

bro knew

harsh terrace
#

also isnt new URL dprecated

dense shale
#

That's one "interesting" way to try to integrate with openAI.
And you want new URI("http://baeldung.com/a-guide-to-java-sockets").toURL().

harsh terrace
#

what about URI#create?

#

well seems like they are the same

#

This convenience factory method works as if by invoking the URI(String) constructor; any URISyntaxException thrown by the constructor is caught and wrapped in a new IllegalArgumentException object, which is then thrown.

real field
#

You can also use java.net.http.HttpClient

dense shale
#

Before trying to integrate with openAI I would recommend first reading up a bit more on how to set up those connections. As it stands that code really is not the way to go.

dull depot
#

I fixed the uri now it returns 403

harsh terrace
#

or some openai java pie

real field
dull depot
real field
#

403 = forbidden

dense shale
#

They don't pass one in conn.setRequestProperty("Authorization", "Bearer -------");

dull depot
#

------- = my api

dense shale
#

Which is seemingly not valid.

dull depot
#

I just created the API

harsh terrace
#

cna you maybe share the full 403 error

dull depot
# harsh terrace cna you maybe share the full 403 error
java.io.IOException: Server returned HTTP response code: 403 for URL: https://platform.openai.com/api-keys
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1998)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1599)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:223)
    at org.mycompany.OpenAIAPIClient.main(OpenAIAPIClient.java:28)
harsh terrace
#

huh

#

where is that URL coming from?

harsh terrace
#

yeah but you didnt use it in the code

dull depot
#

give exception

harsh terrace
#

?

dull depot
harsh terrace
#

formulate a full sentence

dull depot
#

First of all, I wanted to check if I would get an error, but if I continue with the code, the number of errors will most likely increase

dull depot
# harsh terrace first which are you trying to use: <https://platform.openai.com/docs/api-referen...
java.io.IOException: Server returned HTTP response code: 403 for URL: https://platform.openai.com/docs/api-reference
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1998)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1599)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:223)
    at org.mycompany.OpenAIAPIClient.main(OpenAIAPIClient.java:28)```
harsh terrace
#

thats not what I meant...

#

open the page

#

you are trying to use the api right?

#

what kind of endpoint do you want to use?

dull depot
#

i open

dull depot
harsh terrace
#

open the page with your browser

dull depot
harsh terrace
dull depot
harsh terrace
#

wdym?

#

which questions and answers?

dull depot
#

Just answer the questions I ask

harsh terrace
#

you mean you want to use chatgpt?

dull depot
harsh terrace
#

ok yeah then say that

#

openai got more than just chatgpt in their api

dull depot
#

Okay, so how can I do what I said?

harsh terrace
dull depot
#
java.io.IOException: Server returned HTTP response code: 403 for URL: https://platform.openai.com/docs/api-reference/chat
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1998)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1599)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:223)
    at org.mycompany.OpenAIAPIClient.main(OpenAIAPIClient.java:28)
harsh terrace
#

no

#

open the link in your browser

dull depot
#

opened

harsh terrace
#

its the documentation on how to use the api

#

read it

#

then apply these in your code

dull depot
#

i cant translate

harsh terrace
#

why not?

#

what do you need help with?

dull depot
#

I can't read the page because I can't do it in Turkish :/

harsh terrace
#

because I can't do it in Turkish
it is english?

dull depot
#

yes

harsh terrace
#

well and how are we supposed to help you with that then?

dull depot
#

idk

maiden mauve
#

i don’t think there’s an official page of that in turkish

harsh terrace
#

there shouldnt be one imo, the api json will still be english

#

and english is kinda a requirement for programming

dull depot
#

I translate it into Turkish with Java

maiden mauve
#

it will cause issues if u use google translate maybe

#

but u can try

#

some technical stuff can’t be translated

dull depot
maiden mauve
#

nice

#

just keep practicing but for now u need to be able to read the docs

harsh terrace
#

this is good practice to learn APIs if you want to do it manually, otherwise use a java library for openai api