Skip to content

Commit

Permalink
IVYPORTAL-17857: Improve-the-OpenAI-Connector
Browse files Browse the repository at this point in the history
- Make the connector supports gpt-4o-mini
  • Loading branch information
mnhnam-axonivy committed Oct 29, 2024
1 parent 81fdabb commit ab64f81
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@
"type" : "SubProcessCall",
"name" : "openai",
"config" : {
"processCall" : "openai:chatGpt(String)",
"processCall" : "openai:chatGpt4oMini(String,Boolean,BigDecimal)",
"call" : {
"params" : [
{ "name" : "what", "type" : "String" }
{ "name" : "what", "type" : "String" },
{ "name" : "sendUserInfo", "type" : "Boolean" },
{ "name" : "temperature", "type" : "BigDecimal" }
],
"map" : {
"param.what" : "in.message"
"param.what" : "in.message",
"param.sendUserInfo" : "false",
"param.temperature" : "0"
}
},
"output" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ openaiData #class
com.openai.connector #namespace
message com.openai.api.v1.client.ChatCompletionRequestMessage #field
logitBias com.fasterxml.jackson.databind.JsonNode #field
logitBias 'Logit bias directly manipulates the logits. By adjusting the logit bias, one can promote or demote particular tokens' #fieldComment
answer String #field
temperature BigDecimal #field
temperature 'The temperature is used to control the randomness of the output. When you set it higher, you''ll get more random outputs. When you set it lower, towards 0, the values are more deterministic.' #fieldComment
86 changes: 83 additions & 3 deletions openai-connector/processes/openai.p.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
"tags" : "connector"
},
"visual" : {
"at" : { "x" : 96, "y" : 64 },
"at" : { "x" : 168, "y" : 176 },
"icon" : "res:/webContent/logo/OpenAI_Logo.png?small"
},
"connect" : { "id" : "f4", "to" : "f3" }
}, {
"id" : "f1",
"type" : "CallSubEnd",
"visual" : {
"at" : { "x" : 352, "y" : 64 }
"at" : { "x" : 424, "y" : 176 }
}
}, {
"id" : "f3",
Expand All @@ -74,9 +74,89 @@
"bodyInputType" : "ENTITY"
},
"visual" : {
"at" : { "x" : 224, "y" : 64 },
"at" : { "x" : 296, "y" : 176 },
"icon" : "res:/webContent/logo/OpenAI_Logo.png"
},
"connect" : { "id" : "f2", "to" : "f1" }
}, {
"id" : "f5",
"type" : "CallSubStart",
"name" : "chatGpt4oMini(String,Boolean,BigDecimal)",
"config" : {
"callSignature" : "chatGpt4oMini",
"input" : {
"params" : [
{ "name" : "what", "type" : "String" },
{ "name" : "sendUserInfo", "type" : "Boolean", "desc" : "Determine whether username of the login Ivy user should be send to OpenAI" },
{ "name" : "temperature", "type" : "BigDecimal", "desc" : "The temperature is used to control the randomness of the output. When you set it higher, you'll get more random outputs. When you set it lower, towards 0, the values are more deterministic." }
],
"map" : {
"out.message.content" : "param.what",
"out.message.role" : "com.openai.api.v1.client.ChatCompletionRequestMessage.RoleEnum.USER"
},
"code" : [
"import org.apache.commons.lang3.BooleanUtils;",
"",
"// If developer want to expose the username of an Ivy user to OpenAI, set the session user name to message",
"// Otherwise, set the alias String 'user' instead",
"out.message.name = BooleanUtils.isTrue(param.sendUserInfo) ? ivy.session.getSessionUserName() : \"user\";",
"",
"// If the input temperature is one of these invalid value:",
"// null, greater than 2, less than 0,",
"// set temperature = 0 by default",
"out.temperature = (param.temperature == null || param.temperature < 0 || param.temperature > 2) ? 0 : param.temperature;"
]
},
"result" : {
"params" : [
{ "name" : "answer", "type" : "String" }
],
"map" : {
"result.answer" : "in.answer"
}
},
"tags" : "connector"
},
"visual" : {
"at" : { "x" : 168, "y" : 280 },
"labelOffset" : { "x" : 25, "y" : 49 },
"icon" : "res:/webContent/logo/OpenAI_Logo.png?small"
},
"connect" : { "id" : "f7", "to" : "f6" }
}, {
"id" : "f6",
"type" : "RestClientCall",
"name" : "openai (OpenAI API)",
"config" : {
"path" : "/chat/completions",
"bodyObjectMapping" : {
"param.logitBias" : "in.logitBias",
"param.messages" : "[in.message]",
"param.model" : "com.axonivy.connector.openai.Model.GPT_4O_MINI.getValue()",
"param.temperature" : "in.temperature",
"param.user" : "in.message.name"
},
"clientId" : "6840e778-eb27-42a0-afdc-87588ffae871",
"clientErrorCode" : "ivy:error:rest:client",
"method" : "POST",
"statusErrorCode" : "ivy:error:rest:client",
"responseMapping" : {
"out.answer" : "result.choices.get(0).message.content"
},
"bodyObjectType" : "com.openai.api.v1.client.CreateChatCompletionRequest",
"resultType" : "com.openai.api.v1.client.CreateChatCompletionResponse",
"bodyInputType" : "ENTITY"
},
"visual" : {
"at" : { "x" : 296, "y" : 280 },
"icon" : "res:/webContent/logo/OpenAI_Logo.png"
},
"connect" : { "id" : "f9", "to" : "f8" }
}, {
"id" : "f8",
"type" : "CallSubEnd",
"visual" : {
"at" : { "x" : 424, "y" : 280 }
}
} ]
}
5 changes: 3 additions & 2 deletions openai-connector/src/com/axonivy/connector/openai/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@


public enum Model {
GPT_35("gpt-3.5-turbo"),
GPT_35_0301("gpt-3.5-turbo-0301");
GPT_35("gpt-3.5-turbo"), // deprecated
GPT_35_0301("gpt-3.5-turbo-0301"), // deprecated
GPT_4O_MINI("gpt-4o-mini");

private final String model;

Expand Down

0 comments on commit ab64f81

Please sign in to comment.