Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 3 additions & 4 deletions dotnet/src/dotnetcore/Providers/AI/Model/GXAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ protected string CallAgent(string assistant, GXProperties gxproperties, IList ch
{
GXLogging.Debug(log, "Calling Agent: ", assistant);

List<ChatMessage> chatMessagesList = chatMessages!=null ? chatMessages.Cast<ChatMessage>().ToList() :null;
ChatCompletionResult chatCompletion = AgentService.AgentHandlerInstance.CallAgent(assistant, chatMessagesList, gxproperties, context).GetAwaiter().GetResult();
ChatCompletionResult chatCompletion = AgentService.AgentHandlerInstance.CallAgent(assistant, chatMessages, gxproperties, context).GetAwaiter().GetResult();

if (chatCompletion != null && chatCompletion.Choices != null)
{
Expand All @@ -54,8 +53,8 @@ protected string CallAgent(string assistant, GXProperties gxproperties, IList ch
case ChatCompletionResult.FINISH_REASON_STOP:
return choice.Message.Content;
case ChatCompletionResult.FINISH_REASON_TOOL_CALLS:
chatMessagesList.Add(choice.Message);
return ProcessChatResponse(choice, stream, assistant, gxproperties, chatMessagesList, result);
chatMessages.Add(choice.Message);
return ProcessChatResponse(choice, stream, assistant, gxproperties, chatMessages, result);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static string AddChatToUrl(string url)
uriBuilder.Path += "chat";
return uriBuilder.Uri.ToString();
}
internal async Task<ChatCompletionResult> CallAgent(string assistant, List<Chat.ChatMessage> messages, GXProperties properties, IGxContext context)
internal async Task<ChatCompletionResult> CallAgent(string assistant, IList messages, GXProperties properties, IGxContext context)
{
try
{
Expand Down
8 changes: 8 additions & 0 deletions dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,15 @@ public void AddObjectProperty(string name, object prop)
}
public string ToJSonString()
{
#if NETCORE
string json = JSONHelper.DefaultSerialize(ExternalInstance);
if (json!=null)
return json;
else
return new JArray().ToString();
#else
return string.Empty;
#endif
}
public string ToJSonString(bool includeState)
{
Expand Down
27 changes: 26 additions & 1 deletion dotnet/src/dotnetframework/GxClasses/Helpers/JSONHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ internal override string WriteNullableJSON(Dictionary<string, object> kbObject)
});
}

internal override string DefaultSerialize<T>(T value)
{
if (value != null)
{
return JsonSerializer.Serialize(value);
}
return null;
}

internal override bool IsJsonString(string jobject)
{
try
Expand Down Expand Up @@ -229,6 +238,9 @@ internal static GXJsonSerializer Instance
internal abstract string WriteJSON<T>(T kbObject) where T : class;

internal abstract string WriteNullableJSON(Dictionary<string, object> kbObject);
#if NETCORE
internal abstract string DefaultSerialize<T>(T value) where T : class;
#endif
}

public class JSONHelper
Expand Down Expand Up @@ -328,7 +340,20 @@ public static string Serialize<T>(T kbObject) where T : class
{
return Serialize<T>(kbObject, Encoding.UTF8);
}

#if NETCORE
public static string DefaultSerialize<T>(T value) where T : class
{
try
{
return GXJsonSerializer.Instance.DefaultSerialize<T>(value);
}
catch (Exception ex)
{
GXLogging.Error(log, "DefaultSerialize error ", ex);
return null;
}
}
#endif
public static string Serialize<T>(T kbObject, Encoding encoding) where T : class
{
return Serialize<T>(kbObject, encoding, null);
Expand Down
Loading
Loading