Skip to content

Commit 4da2f36

Browse files
authored
Todos parâmetros passado para variáveis
Adicionado também os parâmetros: MAX_TOKENS e TEMPERATURE
1 parent 3a7911c commit 4da2f36

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

openai/src/main/java/com/teste/openai/OpenaiApplication.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,53 @@
1212
public class OpenaiApplication {
1313

1414
private static String KEY = "sk-";
15+
private static String PROMPT = "O que e o chat GPT?";
16+
private static long MAX_TOKENS = 100;
17+
private static float TEMPERATURE = 1;
18+
private static String MODEL = "text-davinci-003";
1519

16-
public static void main(String[] args) throws Exception{
20+
21+
public static void main(String[] args){
1722

1823
try{
1924
DefaultHttpClient client = new DefaultHttpClient();
2025
HttpPost post = new HttpPost
2126
("https://api.openai.com/v1/completions");
2227

23-
StringEntity entity = new StringEntity("{\"model\" : \"text-davinci-003\",\"prompt\" : \"" +
24-
"O que e a nova rota da seda\"}");
28+
StringEntity entity = new StringEntity
29+
("{" +
30+
"\"model\" : " +
31+
"\"" +
32+
MODEL +
33+
"\"," +
34+
"\"prompt\" : \"" +
35+
PROMPT +
36+
"\"," +
37+
"\"max_tokens\" : " +
38+
MAX_TOKENS +
39+
"," +
40+
"\"temperature\" : " +
41+
TEMPERATURE +
42+
"}");
43+
2544
entity.setContentType("application/json");
2645
post.setHeader("Content-Type","application/json");
2746
post.setHeader("Authorization","Bearer "+KEY);
2847
post.setEntity(entity);
48+
2949
HttpResponse response = client.execute(post);
50+
3051
if(response.getStatusLine().getStatusCode() != 201)
3152
System.out.println("HTTP Error: "+response.getStatusLine().getStatusCode());
53+
3254
BufferedReader reader = new BufferedReader(
3355
new InputStreamReader(response.getEntity().getContent()));
56+
3457
String output;
3558
System.out.println("\n\nGPT Resposta: \n");
3659
while ( (output = reader.readLine()) != null)
3760
System.out.println(output);
61+
3862
client.getConnectionManager().shutdown();
3963

4064
}catch (Exception exception){System.out.println( exception.getMessage() );}

0 commit comments

Comments
 (0)