Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d43c4bb
Embedding support in Java Generator
iroqueta Oct 16, 2024
22a47c7
- Add Assitant Object support in Java Generator
iroqueta Nov 5, 2024
7ce5e6a
GXEmbedding module do not exists any more
iroqueta Nov 5, 2024
c9d3a4a
Implement CallResult External Object to use in Agent Object
iroqueta Nov 13, 2024
f893678
Merge branch 'master' into embedding-data-type
iroqueta Nov 13, 2024
27aa4bc
Change Saia URL to consider Embedding and Chat
iroqueta Nov 14, 2024
e4e1da5
Add support for chat and tool call messages
iroqueta Nov 15, 2024
5084733
Message was not added to CallResult
iroqueta Nov 19, 2024
0afbf8e
Json API was updated in master
iroqueta Nov 19, 2024
2a35adc
Merge branch 'master' into embedding-data-type
iroqueta Nov 19, 2024
a14331b
Change getmessages method in CallResult to getMessages
iroqueta Nov 20, 2024
e1e5190
Change callAssistant to callAgent
iroqueta Nov 22, 2024
88f77fa
Fix Build error in Github
iroqueta Nov 22, 2024
fd8af2e
Fix Build error in Github
iroqueta Nov 22, 2024
898abb1
Remove Assistant Test
iroqueta Nov 22, 2024
6a42965
Add Tool Calls support
iroqueta Nov 26, 2024
8d80ee5
TRN with Embedded fails when the PK is validated in Java
iroqueta Dec 2, 2024
a7fcc6d
Embedding must be initialized with empty values.
iroqueta Dec 3, 2024
d84e9ad
Add ToolCall y Stream support to Agent Object
iroqueta Dec 3, 2024
07bdd8f
Changes to better CallTools support.
iroqueta Dec 12, 2024
ac394fc
Avoid Exception procesing Agent response when Choices is not in the j…
iroqueta Feb 27, 2025
5202c24
Merge branch 'master' into embedding-data-type
iroqueta Mar 12, 2025
ca9cdce
Implements Embedding in MySQL
iroqueta Mar 14, 2025
e33217a
Add stream in chat Agent calls.
iroqueta Apr 4, 2025
174cba2
Implements support for multimodal content in Agent messages.
iroqueta May 7, 2025
78bbb25
Implements support for multimodal content in Agent messages.
iroqueta May 7, 2025
0fdb8df
Implements support for multimodal content in Agent messages.
iroqueta May 7, 2025
2232b63
Implements support for multimodal content in Agent messages.
iroqueta May 8, 2025
175cc47
Implements support for multimodal content in Agent messages.
iroqueta May 12, 2025
bc783a6
Merge branch 'master' into embedding-data-type
iroqueta May 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/src/main/java/com/genexus/db/ForEachCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public void setTimestamp(int index, java.sql.Timestamp value) throws SQLExceptio
public void setBLOBFile(int index, String fileName) throws SQLException {}
public void setBLOBFile(int index, String fileName, boolean isMultiMedia) throws SQLException {}
public void setBLOBFile(int index, String fileName, boolean isMultiMedia, boolean downloadContent) throws SQLException {}
public void setEmbedding(int index, Float[] value) throws SQLException {}

public void setVarchar(int index, String value, int length, boolean allowsNull) throws SQLException {}
public void setLongVarchar(int index, String value, boolean allowsNull) throws SQLException {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,11 @@ public byte[] getBytes(int columnIndex) throws SQLException
return stmt.getBytes(columnIndex);
}

public Float[] getGxembedding (int columnIndex) throws SQLException
{
return null;
}

public java.util.UUID getGUID(int columnIndex) throws SQLException
{
if (DEBUG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,9 @@ else if (file.exists() && !fileNameNew.startsWith(blobBasePath))
}
}
}


public void setEmbedding(int index, Float[] value) throws SQLException{
}
public void setBinaryStream(int index, java.io.InputStream value, int length) throws SQLException
{
if (DEBUG)
Expand Down
5 changes: 5 additions & 0 deletions android/src/main/java/com/genexus/db/driver/GXResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,11 @@ public byte[] getBytes(int columnIndex) throws SQLException
return result.getBytes(columnIndex);
}

public Float[] getGxembedding (int columnIndex) throws SQLException
{
return null;
}

public java.util.UUID getGUID(int columnIndex) throws SQLException
{
java.util.UUID value;
Expand Down
18 changes: 17 additions & 1 deletion common/src/main/java/com/genexus/GXExternalCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ public Vector getStruct()
}
return struct;
}


public ArrayList getExternalInstance() {
ArrayList list = new ArrayList();
for (T Item : this)
{
try
{
list.add(Item.getClass().getMethod("getExternalInstance", new Class[]{}).invoke(Item));
}
catch (Exception e)
{
e.printStackTrace();
}
}
return list;
}

}

4 changes: 4 additions & 0 deletions common/src/main/java/com/genexus/db/BufferIFieldGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public byte[] getBytes(int columnIndex) throws SQLException {
return ((byte[]) value[columnIndex - 1]);
}

public Float[] getGxembedding(int columnIndex) throws SQLException {
return ((Float[]) value[columnIndex - 1]);
}

public java.sql.Date getDate(int columnIndex) throws SQLException {
return ((java.sql.Date) value[columnIndex - 1]);
}
Expand Down
5 changes: 5 additions & 0 deletions common/src/main/java/com/genexus/db/CachedIFieldGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ public byte[] getBytes(int columnIndex) throws SQLException
else
return ((byte[][])value[index])[0];
}

public Float[] getGxembedding(int columnIndex) throws SQLException
{
return ((Float[][])value[getColumnIndex(columnIndex)])[0];
}

public java.sql.Date getDate(int columnIndex) throws SQLException
{
Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/com/genexus/db/IFieldGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ public interface IFieldGetter
String getMultimediaUri(int columnIndex) throws SQLException;
String getMultimediaUri(int columnIndex, boolean absPath) throws SQLException;
java.util.UUID getGUID(int columnIndex) throws SQLException;
Float[] getGxembedding(int columnIndex) throws SQLException;
}
1 change: 1 addition & 0 deletions common/src/main/java/com/genexus/db/IFieldSetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public interface IFieldSetter
public void setBLOBFile(int index, String fileName) throws SQLException;
public void setBLOBFile(int index, String fileName, boolean isMultiMedia) throws SQLException;
public void setBLOBFile(int index, String fileName, boolean isMultiMedia, boolean downloadContent) throws SQLException;
public void setEmbedding(int index, Float[] value) throws SQLException;

public void setVarchar(int index, String value, int length, boolean allowsNull) throws SQLException;
public void setLongVarchar(int index, String value, boolean allowsNull) throws SQLException;
Expand Down
30 changes: 30 additions & 0 deletions common/src/main/java/com/genexus/util/CallResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.genexus.util;

import com.genexus.GXBaseCollection;
import com.genexus.SdtMessages_Message;

public class CallResult {
private boolean success = true;
private boolean fail;
private final GXBaseCollection<SdtMessages_Message> messages = new GXBaseCollection<>();

public boolean success() {
return success;
}

public void setFail() {
fail = true;
success =false;
}

public boolean fail() {
return fail;
}

public void addMessage(SdtMessages_Message message) {
messages.add(message);
}
public GXBaseCollection<SdtMessages_Message> getMessages() {
return messages;
}
}
14 changes: 11 additions & 3 deletions common/src/main/java/com/genexus/util/GXProperties.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.genexus.util;

import java.util.LinkedHashMap;
import java.util.*;

import com.genexus.internet.IGxJSONSerializable;

Expand All @@ -10,8 +10,6 @@
import com.genexus.CommonUtil;
import com.genexus.SdtMessages_Message;
import com.genexus.GXBaseCollection;
import java.util.Iterator;
import java.util.Map;

public class GXProperties implements IGxJSONSerializable {
private LinkedHashMap < String, GXProperty > properties = new LinkedHashMap < > ();
Expand Down Expand Up @@ -118,6 +116,16 @@ public String toJSonString() {
return jObj.toString();
}

public ArrayList<GXProperty> getList() {
ArrayList<GXProperty> list = new ArrayList<>();
int i = 0;
while (count() > i) {
list.add(item(i));
i++;
}
return list;
}

public boolean fromJSonString(String s) {
return fromJSonString(s, null);
}
Expand Down
2 changes: 2 additions & 0 deletions java/client.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ ORQ_CLIENT_URL=
ORQ_SERVER_DIR=
TMPMEDIA_DIR=PrivateTempStorage
PRINT_LAYOUT_METADATA_DIR=LayoutMetadata
AI_PROVIDER=https://api.saia.ai/chat
AI_PROVIDER_API_KEY=xxx
HTTP_PROTOCOL=Unsecure
SAMESITE_COOKIE=Lax
StorageTimeZone= 1
Expand Down
80 changes: 77 additions & 3 deletions java/src/main/java/com/genexus/GXProcedure.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@
package com.genexus;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.genexus.db.Namespace;
import com.genexus.db.UserInformation;
import com.genexus.diagnostics.GXDebugInfo;
import com.genexus.diagnostics.GXDebugManager;
import com.genexus.internet.HttpClient;
import com.genexus.internet.HttpContext;
import com.genexus.mock.GXMockProvider;
import com.genexus.performance.ProcedureInfo;
import com.genexus.performance.ProceduresInfo;
import com.genexus.util.ReorgSubmitThreadPool;
import com.genexus.util.SubmitThreadPool;
import com.genexus.util.*;
import com.genexus.util.saia.OpenAIRequest;
import com.genexus.util.saia.OpenAIResponse;
import com.genexus.util.saia.SaiaService;
import org.json.JSONObject;

public abstract class GXProcedure implements IErrorHandler, ISubmitteable {
public abstract void initialize();
Expand All @@ -28,7 +35,8 @@ public abstract class GXProcedure implements IErrorHandler, ISubmitteable {
UserInformation ui=null;

private Date beginExecute;

private HttpClient client;

public static final int IN_NEW_UTL = -2;

public GXProcedure(int remoteHandle, ModelContext context, String location) {
Expand Down Expand Up @@ -257,4 +265,70 @@ protected void mockExecute() {
}
privateExecute( );
}

protected String callTool(String name, String arguments) {
return "";
}

protected String callAssistant(String agent, GXProperties properties, ArrayList<OpenAIResponse.Message> messages, CallResult result) {
return callAgent(agent, properties, messages, result);
}

protected ChatResult chatAgent(String agent, GXProperties properties, ArrayList<OpenAIResponse.Message> messages, CallResult result) {
callAgent(agent, true, properties, messages, result);
return new ChatResult(this, agent, properties, messages, result, client);
}

protected String callAgent(String agent, GXProperties properties, ArrayList<OpenAIResponse.Message> messages, CallResult result) {
return callAgent(agent, false, properties, messages, result);
}

protected String callAgent(String agent, boolean stream, GXProperties properties, ArrayList<OpenAIResponse.Message> messages, CallResult result) {
OpenAIRequest aiRequest = new OpenAIRequest();
aiRequest.setModel(String.format("saia:agent:%s", agent));
if (!messages.isEmpty())
aiRequest.setMessages(messages);
aiRequest.setVariables(properties.getList());
if (stream)
aiRequest.setStream(true);
client = new HttpClient();
OpenAIResponse aiResponse = SaiaService.call(aiRequest, client, result);
if (aiResponse != null && aiResponse.getChoices() != null) {
for (OpenAIResponse.Choice element : aiResponse.getChoices()) {
String finishReason = element.getFinishReason();
if (finishReason.equals("stop"))
return element.getMessage().getStringContent();
if (finishReason.equals("tool_calls")) {
messages.add(element.getMessage());
return processNotChunkedResponse(agent, stream, properties, messages, result, element.getMessage().getToolCalls());
}
}
} else if (client.getStatusCode() == 200) {
return "";
}
return "";
}

public String processNotChunkedResponse(String agent, boolean stream, GXProperties properties, ArrayList<OpenAIResponse.Message> messages, CallResult result, ArrayList<OpenAIResponse.ToolCall> toolCalls) {
for (OpenAIResponse.ToolCall tollCall : toolCalls) {
processToolCall(tollCall, messages);
}
return callAgent(agent, stream, properties, messages, result);
}

private void processToolCall(OpenAIResponse.ToolCall toolCall, ArrayList<OpenAIResponse.Message> messages) {
String result;
String functionName = toolCall.getFunction().getName();
try {
result = callTool(functionName, toolCall.getFunction().getArguments());
}
catch (Throwable e) {
result = String.format("Error calling tool %s", functionName);
}
OpenAIResponse.Message toolCallMessage = new OpenAIResponse.Message();
toolCallMessage.setRole("tool");
toolCallMessage.setStringContent(result);
toolCallMessage.setToolCallId(toolCall.getId());
messages.add(toolCallMessage);
}
}
5 changes: 5 additions & 0 deletions java/src/main/java/com/genexus/GXutil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.genexus.common.interfaces.SpecificImplementation;
import com.genexus.db.DataStoreProvider;
import com.genexus.db.GXEmbedding;
import com.genexus.internet.HttpContext;
import com.genexus.internet.StringCollection;
import com.genexus.platform.INativeFunctions;
Expand Down Expand Up @@ -1777,4 +1778,8 @@ public static String buildURLFromHttpClient(com.genexus.internet.HttpClient GXSo
return url.toString();
}

public static String embeddingToStr(GXEmbedding embedding) {
return embedding.toString();
}

}
3 changes: 3 additions & 0 deletions java/src/main/java/com/genexus/db/ForEachCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ public void setTimestamp(int index, java.sql.Timestamp value) throws SQLExceptio
public void setBLOBFile(int index, String fileName) throws SQLException {}
public void setBLOBFile(int index, String fileName, boolean isMultiMedia) throws SQLException {}
public void setBLOBFile(int index, String fileName, boolean isMultiMedia, boolean downloadContet) throws SQLException {}
public void setEmbedding(int index, Float[] value) throws SQLException {}

public void setVarchar(int index, String value, int length, boolean allowsNull) throws SQLException {}
public void setLongVarchar(int index, String value, boolean allowsNull) throws SQLException {}
Expand All @@ -339,6 +340,8 @@ public void setParameterRT(String name, String value)
boolean isLike = false;
if(value.equals("like"))
isLike = true;
else if (value.equals("Distance"))
value = ds.getDistanceFunction();
else if(!value.equals("=") && !value.equals(">") && !value.equals(">=")
&& !value.equals("<=") && !value.equals("<") && !value.equals("<>"))
{
Expand Down
Loading
Loading