Skip to content

Commit

Permalink
MARP-961: add local server to demo
Browse files Browse the repository at this point in the history
  • Loading branch information
linhpd-axonivy committed Oct 3, 2024
1 parent fd1a8fb commit ba8e589
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions openai-assistant/res/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ba8e589

Please sign in to comment.