mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 08:18:00 +00:00
Added tool calling support (#731)
Co-authored-by: krut_ni <nils.kruthoff@dlr.de> Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
266 files changed
+11186
-740
No files matched your search
@@ -0,0 +1,41 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AIStudio.Provider.OpenAI;
|
||||
|
||||
internal static class ChatCompletionContent
|
||||
{
|
||||
public static string? GetText(JsonElement? content)
|
||||
{
|
||||
if (content is not { } value)
|
||||
return null;
|
||||
|
||||
if (value.ValueKind is JsonValueKind.String)
|
||||
return value.GetString();
|
||||
|
||||
if (value.ValueKind is not JsonValueKind.Array)
|
||||
return null;
|
||||
|
||||
var text = new StringBuilder();
|
||||
foreach (var chunk in value.EnumerateArray())
|
||||
{
|
||||
if (chunk.ValueKind is JsonValueKind.String)
|
||||
{
|
||||
text.Append(chunk.GetString());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (chunk.ValueKind is not JsonValueKind.Object ||
|
||||
!chunk.TryGetProperty("type", out var type) ||
|
||||
type.ValueKind is not JsonValueKind.String ||
|
||||
!string.Equals(type.GetString(), "text", StringComparison.Ordinal) ||
|
||||
!chunk.TryGetProperty("text", out var textElement) ||
|
||||
textElement.ValueKind is not JsonValueKind.String)
|
||||
continue;
|
||||
|
||||
text.Append(textElement.GetString());
|
||||
}
|
||||
|
||||
return text.Length == 0 ? null : text.ToString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user