#gpt-3.5-turbo

1 messages ยท Page 1 of 1 (latest)

pine plank
#

how to use api gpt3.5-turbo in java?

ashen heathBOT
#

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

ashen heathBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

To use the OpenAI GPT-3.5-turbo API in Java, you can make HTTP requests to the API endpoint using libraries like java.net.HttpURLConnection or higher-level libraries like OkHttp or Apache HttpClient. Here's an example using OkHttp library:

  1. Add the OkHttp dependency to your project. You can add it to your Maven or Gradle configuration file, or manually download the JAR file and add it to your project's classpath.

  2. Import the necessary classes in your Java code:

import okhttp3.*;
import java.io.IOException;
  1. Create a method to send a prompt and receive a completion from the GPT-3.5-turbo API:
public static String getGptResponse(String prompt) throws IOException {
    OkHttpClient client = new OkHttpClient();

    MediaType mediaType = MediaType.parse("application/json");
    RequestBody body = RequestBody.create(mediaType, "{\"prompt\": \"" + prompt + "\", \"max_tokens\": 100}");
    Request request = new Request.Builder()
            .url("https://api.openai.com/v1/engines/davinci-codex/completions")
            .post(body)
            .addHeader("Authorization", "Bearer YOUR_API_KEY")
            .addHeader("Content-Type", "application/json")
            .build();

    try (Response response = client.newCall(request).execute()) {
        return response.body().string();
    }
}

Replace "YOUR_API_KEY" with your actual OpenAI API key.

  1. Use the method to send a prompt and receive a completion:
public static void main(String[] args) throws IOException {
    String prompt = "Once upon a time";
    String response = getGptResponse(prompt);
    
    System.out.println(response);
}

The response will contain the completion generated by GPT-3.5-turbo.

Note: This is a basic example to get you started. You may need to handle exceptions, parse the JSON response, and modify the request parameters based on your specific use case.

pine plank
#

"error": {
"message": "The model davinci-codex does not exist or you do not have access to it.",
"type": "invalid_request_error",
"param": null,
"code": "model_not_found"
}

south elbow