-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathChatBot Project .java
More file actions
21 lines (20 loc) · 1004 Bytes
/
ChatBot Project .java
File metadata and controls
21 lines (20 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
public class ChatBot {
public static void main(String[] LOL) {
try {
HttpClient httpClient = HttpClients.createDefault();
HttpPost request = new HttpPost("https://api.openai.com/v1/engines/davinci/completions");
request.addHeader("Authorization", "Bearer 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");
StringEntity entity = new StringEntity("{\"prompt\": \"Translate the following English text to French: 'Hello, how are you?'\"}");
request.setEntity(entity);
HttpResponse response = httpClient.execute(request);
System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
} catch (Exception e) {
e.printStackTrace();
}
}
}