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
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,29 @@ public class ChatFunctionToolJsonConverter : global::System.Text.Json.Serializat
if (__jsonProps.Contains("parameters")) __score2++;
if (__jsonProps.Contains("type")) __score2++;
var __score3 = 0;
if (__jsonProps.Contains("allowed_domains")) __score3++;
if (__jsonProps.Contains("engine")) __score3++;
if (__jsonProps.Contains("excluded_domains")) __score3++;
if (__jsonProps.Contains("max_results")) __score3++;
if (__jsonProps.Contains("max_total_results")) __score3++;
if (__jsonProps.Contains("parameters")) __score3++;
if (__jsonProps.Contains("search_context_size")) __score3++;
if (__jsonProps.Contains("type")) __score3++;
if (__jsonProps.Contains("user_location")) __score3++;
var __score4 = 0;
if (__jsonProps.Contains("allowed_domains")) __score4++;
if (__jsonProps.Contains("engine")) __score4++;
if (__jsonProps.Contains("excluded_domains")) __score4++;
if (__jsonProps.Contains("max_results")) __score4++;
if (__jsonProps.Contains("max_total_results")) __score4++;
if (__jsonProps.Contains("parameters")) __score4++;
if (__jsonProps.Contains("search_context_size")) __score4++;
if (__jsonProps.Contains("type")) __score4++;
if (__jsonProps.Contains("user_location")) __score4++;
var __bestScore = 0;
var __bestIndex = -1;
if (__score0 > __bestScore) { __bestScore = __score0; __bestIndex = 0; }
if (__score1 > __bestScore) { __bestScore = __score1; __bestIndex = 1; }
if (__score2 > __bestScore) { __bestScore = __score2; __bestIndex = 2; }
if (__score3 > __bestScore) { __bestScore = __score3; __bestIndex = 3; }
if (__score4 > __bestScore) { __bestScore = __score4; __bestIndex = 4; }

global::OpenRouter.ChatFunctionTool0? chatFunctionTool0 = default;
global::OpenRouter.DatetimeServerTool? datetimeServerTool = default;
global::OpenRouter.ChatSearchModelsServerTool? chatSearchModelsServerTool = default;
global::OpenRouter.OpenRouterWebSearchServerTool? openRouterWebSearchServerTool = default;
global::OpenRouter.ChatWebSearchShorthand? chatWebSearchShorthand = default;
if (__bestIndex >= 0)
Expand Down Expand Up @@ -90,6 +95,21 @@ public class ChatFunctionToolJsonConverter : global::System.Text.Json.Serializat
}
}
else if (__bestIndex == 2)
{
try
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::OpenRouter.ChatSearchModelsServerTool), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::OpenRouter.ChatSearchModelsServerTool> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::OpenRouter.ChatSearchModelsServerTool).Name}");
chatSearchModelsServerTool = global::System.Text.Json.JsonSerializer.Deserialize(__rawJson, typeInfo);
}
catch (global::System.Text.Json.JsonException)
{
}
catch (global::System.InvalidOperationException)
{
}
}
else if (__bestIndex == 3)
{
try
{
Expand All @@ -104,7 +124,7 @@ public class ChatFunctionToolJsonConverter : global::System.Text.Json.Serializat
{
}
}
else if (__bestIndex == 3)
else if (__bestIndex == 4)
{
try
{
Expand All @@ -121,7 +141,7 @@ public class ChatFunctionToolJsonConverter : global::System.Text.Json.Serializat
}
}

if (chatFunctionTool0 == null && datetimeServerTool == null && openRouterWebSearchServerTool == null && chatWebSearchShorthand == null)
if (chatFunctionTool0 == null && datetimeServerTool == null && chatSearchModelsServerTool == null && openRouterWebSearchServerTool == null && chatWebSearchShorthand == null)
{
try
{
Expand Down Expand Up @@ -149,6 +169,19 @@ public class ChatFunctionToolJsonConverter : global::System.Text.Json.Serializat
{
}

try
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::OpenRouter.ChatSearchModelsServerTool), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::OpenRouter.ChatSearchModelsServerTool> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::OpenRouter.ChatSearchModelsServerTool).Name}");
chatSearchModelsServerTool = global::System.Text.Json.JsonSerializer.Deserialize(__rawJson, typeInfo);
}
catch (global::System.Text.Json.JsonException)
{
}
catch (global::System.InvalidOperationException)
{
}

try
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::OpenRouter.OpenRouterWebSearchServerTool), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::OpenRouter.OpenRouterWebSearchServerTool> ??
Expand Down Expand Up @@ -181,6 +214,8 @@ public class ChatFunctionToolJsonConverter : global::System.Text.Json.Serializat

datetimeServerTool,

chatSearchModelsServerTool,

openRouterWebSearchServerTool,

chatWebSearchShorthand
Expand Down Expand Up @@ -210,6 +245,12 @@ public override void Write(
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::OpenRouter.DatetimeServerTool).Name}");
global::System.Text.Json.JsonSerializer.Serialize(writer, value.DatetimeServerTool!, typeInfo);
}
else if (value.IsChatSearchModelsServerTool)
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::OpenRouter.ChatSearchModelsServerTool), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::OpenRouter.ChatSearchModelsServerTool?> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::OpenRouter.ChatSearchModelsServerTool).Name}");
global::System.Text.Json.JsonSerializer.Serialize(writer, value.ChatSearchModelsServerTool!, typeInfo);
}
else if (value.IsOpenRouterWebSearchServerTool)
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::OpenRouter.OpenRouterWebSearchServerTool), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::OpenRouter.OpenRouterWebSearchServerTool?> ??
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#nullable enable

namespace OpenRouter.JsonConverters
{
/// <inheritdoc />
public sealed class ChatSearchModelsServerToolTypeJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenRouter.ChatSearchModelsServerToolType>
{
/// <inheritdoc />
public override global::OpenRouter.ChatSearchModelsServerToolType Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenRouter.ChatSearchModelsServerToolTypeExtensions.ToEnum(stringValue) ?? default;
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenRouter.ChatSearchModelsServerToolType)numValue;
}
case global::System.Text.Json.JsonTokenType.Null:
{
return default(global::OpenRouter.ChatSearchModelsServerToolType);
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenRouter.ChatSearchModelsServerToolType value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

writer.WriteStringValue(global::OpenRouter.ChatSearchModelsServerToolTypeExtensions.ToValueString(value));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#nullable enable

namespace OpenRouter.JsonConverters
{
/// <inheritdoc />
public sealed class ChatSearchModelsServerToolTypeNullableJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenRouter.ChatSearchModelsServerToolType?>
{
/// <inheritdoc />
public override global::OpenRouter.ChatSearchModelsServerToolType? Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenRouter.ChatSearchModelsServerToolTypeExtensions.ToEnum(stringValue);
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenRouter.ChatSearchModelsServerToolType)numValue;
}
case global::System.Text.Json.JsonTokenType.Null:
{
return default(global::OpenRouter.ChatSearchModelsServerToolType?);
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenRouter.ChatSearchModelsServerToolType? value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(global::OpenRouter.ChatSearchModelsServerToolTypeExtensions.ToValueString(value.Value));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class MessagesRequestToolsItemsJsonConverter : global::System.Text.Json.S
var __score6 = 0;
if (__jsonProps.Contains("parameters")) __score6++;
if (__jsonProps.Contains("type")) __score6++;
var __score7 = 0;
if (__jsonProps.Contains("parameters")) __score7++;
if (__jsonProps.Contains("type")) __score7++;
var __bestScore = 0;
var __bestIndex = -1;
if (__score0 > __bestScore) { __bestScore = __score0; __bestIndex = 0; }
Expand All @@ -72,13 +75,15 @@ public class MessagesRequestToolsItemsJsonConverter : global::System.Text.Json.S
if (__score4 > __bestScore) { __bestScore = __score4; __bestIndex = 4; }
if (__score5 > __bestScore) { __bestScore = __score5; __bestIndex = 5; }
if (__score6 > __bestScore) { __bestScore = __score6; __bestIndex = 6; }
if (__score7 > __bestScore) { __bestScore = __score7; __bestIndex = 7; }

global::OpenRouter.MessagesRequestToolsItems0? messagesRequestToolsItems0 = default;
global::OpenRouter.MessagesRequestToolsItems1? messagesRequestToolsItems1 = default;
global::OpenRouter.MessagesRequestToolsItems2? messagesRequestToolsItems2 = default;
global::OpenRouter.MessagesRequestToolsItems3? messagesRequestToolsItems3 = default;
global::OpenRouter.MessagesRequestToolsItems4? messagesRequestToolsItems4 = default;
global::OpenRouter.DatetimeServerTool? datetimeServerTool = default;
global::OpenRouter.ChatSearchModelsServerTool? chatSearchModelsServerTool = default;
global::OpenRouter.OpenRouterWebSearchServerTool? openRouterWebSearchServerTool = default;
if (__bestIndex >= 0)
{
Expand Down Expand Up @@ -173,6 +178,21 @@ public class MessagesRequestToolsItemsJsonConverter : global::System.Text.Json.S
}
}
else if (__bestIndex == 6)
{
try
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::OpenRouter.ChatSearchModelsServerTool), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::OpenRouter.ChatSearchModelsServerTool> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::OpenRouter.ChatSearchModelsServerTool).Name}");
chatSearchModelsServerTool = global::System.Text.Json.JsonSerializer.Deserialize(__rawJson, typeInfo);
}
catch (global::System.Text.Json.JsonException)
{
}
catch (global::System.InvalidOperationException)
{
}
}
else if (__bestIndex == 7)
{
try
{
Expand All @@ -189,7 +209,7 @@ public class MessagesRequestToolsItemsJsonConverter : global::System.Text.Json.S
}
}

if (messagesRequestToolsItems0 == null && messagesRequestToolsItems1 == null && messagesRequestToolsItems2 == null && messagesRequestToolsItems3 == null && messagesRequestToolsItems4 == null && datetimeServerTool == null && openRouterWebSearchServerTool == null)
if (messagesRequestToolsItems0 == null && messagesRequestToolsItems1 == null && messagesRequestToolsItems2 == null && messagesRequestToolsItems3 == null && messagesRequestToolsItems4 == null && datetimeServerTool == null && chatSearchModelsServerTool == null && openRouterWebSearchServerTool == null)
{
try
{
Expand Down Expand Up @@ -269,6 +289,19 @@ public class MessagesRequestToolsItemsJsonConverter : global::System.Text.Json.S
{
}

try
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::OpenRouter.ChatSearchModelsServerTool), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::OpenRouter.ChatSearchModelsServerTool> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::OpenRouter.ChatSearchModelsServerTool).Name}");
chatSearchModelsServerTool = global::System.Text.Json.JsonSerializer.Deserialize(__rawJson, typeInfo);
}
catch (global::System.Text.Json.JsonException)
{
}
catch (global::System.InvalidOperationException)
{
}

try
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::OpenRouter.OpenRouterWebSearchServerTool), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::OpenRouter.OpenRouterWebSearchServerTool> ??
Expand Down Expand Up @@ -296,6 +329,8 @@ public class MessagesRequestToolsItemsJsonConverter : global::System.Text.Json.S

datetimeServerTool,

chatSearchModelsServerTool,

openRouterWebSearchServerTool
);

Expand Down Expand Up @@ -347,6 +382,12 @@ public override void Write(
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::OpenRouter.DatetimeServerTool).Name}");
global::System.Text.Json.JsonSerializer.Serialize(writer, value.DatetimeServerTool!, typeInfo);
}
else if (value.IsChatSearchModelsServerTool)
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::OpenRouter.ChatSearchModelsServerTool), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::OpenRouter.ChatSearchModelsServerTool?> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::OpenRouter.ChatSearchModelsServerTool).Name}");
global::System.Text.Json.JsonSerializer.Serialize(writer, value.ChatSearchModelsServerTool!, typeInfo);
}
else if (value.IsOpenRouterWebSearchServerTool)
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::OpenRouter.OpenRouterWebSearchServerTool), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::OpenRouter.OpenRouterWebSearchServerTool?> ??
Expand Down
Loading
Loading