-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split clone method from ai-assitant from test class
- Loading branch information
1 parent
7e6148c
commit c3f2c1f
Showing
2 changed files
with
39 additions
and
30 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
openai-connector-test/src/com/axonivy/connector/openai/mock/utils/AiAssistanceUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.axonivy.connector.openai.mock.utils; | ||
|
||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import com.fasterxml.jackson.databind.node.JsonNodeFactory; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
public class AiAssistanceUtils { | ||
private static ObjectNode completion() { | ||
ObjectNode request = JsonNodeFactory.instance.objectNode(); | ||
request.put("model", "gpt-3.5-turbo"); | ||
request.put("temperature", 1); | ||
request.put("top_p", 1); | ||
request.put("frequency_penalty", 0); | ||
request.put("presence_penalty", 0); | ||
request.put("max_tokens", 1024); | ||
return request; | ||
} | ||
|
||
private static ObjectNode message(String role, String content) { | ||
return JsonNodeFactory.instance.objectNode().put("role", role).put("content", content); | ||
} | ||
|
||
public static Entity<JsonNode> buildPayloadFromQuestion(String question, boolean includeSystemPrompt) { | ||
ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode(); | ||
if (includeSystemPrompt) { | ||
arrayNode.add(message("system", "SYSTEM_PROMT")); | ||
} | ||
arrayNode.add(message("user", question)); | ||
ObjectNode request = completion().set("messages", arrayNode); | ||
return Entity.entity(request, MediaType.APPLICATION_JSON); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters