diff --git a/openai-assistant/res/variables.yaml b/openai-assistant/res/variables.yaml index fab9759..93116c0 100644 --- a/openai-assistant/res/variables.yaml +++ b/openai-assistant/res/variables.yaml @@ -5,9 +5,9 @@ Variables: # [password] apiKey: '' # chatGPT request timeout in seconds - connectTimeoutSeconds: 30 + connectTimeoutSeconds: 60 # chatGPT read timeout in seconds - readTimeoutSeconds: 30 + readTimeoutSeconds: 60 # tokens to spend on analyzation and response; at max 4097 maxTokens: 1024 # base uri to use for chatGPT calls diff --git a/openai-assistant/src/com/axonivy/connector/openai/assistant/ChatGptClientFactory.java b/openai-assistant/src/com/axonivy/connector/openai/assistant/ChatGptClientFactory.java index 5b67d67..f57ef7b 100644 --- a/openai-assistant/src/com/axonivy/connector/openai/assistant/ChatGptClientFactory.java +++ b/openai-assistant/src/com/axonivy/connector/openai/assistant/ChatGptClientFactory.java @@ -13,7 +13,7 @@ public class ChatGptClientFactory { private interface Defaults { - String OPENAI_V1 = "https://api.openai.com/v1"; + String OPENAI_V1 = "http://127.0.0.1:5000"; int TIMEOUT = 30; } diff --git a/openai-assistant/src/com/axonivy/connector/openai/assistant/ChatGptRequest.java b/openai-assistant/src/com/axonivy/connector/openai/assistant/ChatGptRequest.java index 910a8b9..30b0960 100644 --- a/openai-assistant/src/com/axonivy/connector/openai/assistant/ChatGptRequest.java +++ b/openai-assistant/src/com/axonivy/connector/openai/assistant/ChatGptRequest.java @@ -1,5 +1,6 @@ package com.axonivy.connector.openai.assistant; +import java.util.Map; import java.util.function.Supplier; import javax.ws.rs.client.Entity; @@ -41,16 +42,26 @@ public String getModels() { return read(resp); } - public String ask(String context, String question) { - WebTarget chat = client.get().path("chat/completions"); - ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode(); - arrayNode.add(message("system", SYSTEM_PROMPT)); - arrayNode.add(message("user", String.format("%s \n\n %s", context, question))); - ObjectNode request = completion().set("messages", arrayNode); - var payload = Entity.entity(request, MediaType.APPLICATION_JSON); - Response resp = chat.request().post(payload); - return read(resp); - } +// public String ask(String context, String question) { +// WebTarget chat = client.get().path("chat/completions"); +// ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode(); +// arrayNode.add(message("system", SYSTEM_PROMPT)); +// arrayNode.add(message("user", String.format("%s \n\n %s", context, question))); +// ObjectNode request = completion().set("messages", arrayNode); +// var payload = Entity.entity(request, MediaType.APPLICATION_JSON); +// Response resp = chat.request().post(payload); +// return read(resp); +// } + + public String ask(String context, String question) { + WebTarget chat = client.get().path(""); + ObjectNode request = JsonNodeFactory.instance.objectNode(); + request.put("process_json", context); + request.put("request", question); + var payload = Entity.entity(request, MediaType.APPLICATION_JSON); + Response resp = chat.request().post(payload); + return resp.readEntity(JsonNode.class).toPrettyString(); + } private ObjectNode message(String role, String content) { return JsonNodeFactory.instance.objectNode().put("role", role).put("content", content);