Skip to content

Commit f6261ff

Browse files
committed
fix: Fixed Streaming issue.
1 parent 48dbf5e commit f6261ff

6 files changed

Lines changed: 289 additions & 597 deletions

File tree

src/helpers/FixOpenApiSpec/Program.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,14 @@
33
using Microsoft.OpenApi.Readers;
44

55
var path = args[0];
6-
var text = await File.ReadAllTextAsync(path);
6+
var jsonOrYaml = await File.ReadAllTextAsync(path);
77

8-
text = text.Replace("description: *run_temperature_description", "description: empty");
9-
text = text.Replace("description: &run_temperature_description ", "description: ");
8+
var openApiDocument = new OpenApiStringReader().Read(jsonOrYaml, out var diagnostics);
109

11-
text = text.Replace("description: *run_top_p_description", "description: empty");
12-
text = text.Replace("description: &run_top_p_description ", "description: ");
10+
openApiDocument.Components.Schemas["MessageStreamEvent"]!.Discriminator.Mapping["error"] = "#/components/schemas/ErrorEvent";
1311

14-
var openApiDocument = new OpenApiStringReader().Read(text, out var diagnostics);
15-
openApiDocument.Components.Schemas["ParallelToolCalls"]!.Default = null;
16-
openApiDocument.Components.Schemas["ParallelToolCalls"]!.Nullable = true;
17-
18-
openApiDocument.Components.Schemas["CreateEmbeddingRequest"]!.Properties["dimensions"].Nullable = true;
19-
20-
text = openApiDocument.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
21-
_ = new OpenApiStringReader().Read(text, out diagnostics);
12+
jsonOrYaml = openApiDocument.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
13+
_ = new OpenApiStringReader().Read(jsonOrYaml, out diagnostics);
2214

2315
if (diagnostics.Errors.Count > 0)
2416
{
@@ -30,4 +22,4 @@
3022
Environment.Exit(1);
3123
}
3224

33-
await File.WriteAllTextAsync(path, text);
25+
await File.WriteAllTextAsync(path, jsonOrYaml);

src/libs/Anthropic/Generated/Anthropic.Models.MessageStreamEventDiscriminatorType.g.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public enum MessageStreamEventDiscriminatorType
3636
///
3737
/// </summary>
3838
Ping,
39+
/// <summary>
40+
///
41+
/// </summary>
42+
Error,
3943
}
4044

4145
/// <summary>
@@ -57,6 +61,7 @@ public static string ToValueString(this MessageStreamEventDiscriminatorType valu
5761
MessageStreamEventDiscriminatorType.ContentBlockDelta => "content_block_delta",
5862
MessageStreamEventDiscriminatorType.ContentBlockStop => "content_block_stop",
5963
MessageStreamEventDiscriminatorType.Ping => "ping",
64+
MessageStreamEventDiscriminatorType.Error => "error",
6065
_ => throw new global::System.ArgumentOutOfRangeException(nameof(value), value, null),
6166
};
6267
}
@@ -74,6 +79,7 @@ public static string ToValueString(this MessageStreamEventDiscriminatorType valu
7479
"content_block_delta" => MessageStreamEventDiscriminatorType.ContentBlockDelta,
7580
"content_block_stop" => MessageStreamEventDiscriminatorType.ContentBlockStop,
7681
"ping" => MessageStreamEventDiscriminatorType.Ping,
82+
"error" => MessageStreamEventDiscriminatorType.Error,
7783
_ => null,
7884
};
7985
}

src/libs/Anthropic/Generated/JsonConverters.MessageStreamEvent.g.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,49 +29,49 @@ public class MessageStreamEventJsonConverter : global::System.Text.Json.Serializ
2929
start = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo);
3030
}
3131
global::Anthropic.MessageDeltaEvent? delta = default;
32-
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.MessageStart)
32+
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.MessageDelta)
3333
{
3434
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::Anthropic.MessageDeltaEvent), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Anthropic.MessageDeltaEvent> ??
3535
throw new global::System.InvalidOperationException($"Cannot get type info for {nameof(global::Anthropic.MessageDeltaEvent)}");
3636
delta = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo);
3737
}
3838
global::Anthropic.MessageStopEvent? stop = default;
39-
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.MessageStart)
39+
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.MessageStop)
4040
{
4141
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::Anthropic.MessageStopEvent), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Anthropic.MessageStopEvent> ??
4242
throw new global::System.InvalidOperationException($"Cannot get type info for {nameof(global::Anthropic.MessageStopEvent)}");
4343
stop = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo);
4444
}
4545
global::Anthropic.ContentBlockStartEvent? contentBlockStart = default;
46-
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.MessageStart)
46+
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.ContentBlockStart)
4747
{
4848
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::Anthropic.ContentBlockStartEvent), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Anthropic.ContentBlockStartEvent> ??
4949
throw new global::System.InvalidOperationException($"Cannot get type info for {nameof(global::Anthropic.ContentBlockStartEvent)}");
5050
contentBlockStart = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo);
5151
}
5252
global::Anthropic.ContentBlockDeltaEvent? contentBlockDelta = default;
53-
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.MessageStart)
53+
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.ContentBlockDelta)
5454
{
5555
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::Anthropic.ContentBlockDeltaEvent), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Anthropic.ContentBlockDeltaEvent> ??
5656
throw new global::System.InvalidOperationException($"Cannot get type info for {nameof(global::Anthropic.ContentBlockDeltaEvent)}");
5757
contentBlockDelta = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo);
5858
}
5959
global::Anthropic.ContentBlockStopEvent? contentBlockStop = default;
60-
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.MessageStart)
60+
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.ContentBlockStop)
6161
{
6262
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::Anthropic.ContentBlockStopEvent), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Anthropic.ContentBlockStopEvent> ??
6363
throw new global::System.InvalidOperationException($"Cannot get type info for {nameof(global::Anthropic.ContentBlockStopEvent)}");
6464
contentBlockStop = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo);
6565
}
6666
global::Anthropic.PingEvent? ping = default;
67-
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.MessageStart)
67+
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.Ping)
6868
{
6969
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::Anthropic.PingEvent), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Anthropic.PingEvent> ??
7070
throw new global::System.InvalidOperationException($"Cannot get type info for {nameof(global::Anthropic.PingEvent)}");
7171
ping = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo);
7272
}
7373
global::Anthropic.ErrorEvent? error = default;
74-
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.MessageStart)
74+
if (discriminator?.Type == global::Anthropic.MessageStreamEventDiscriminatorType.Error)
7575
{
7676
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::Anthropic.ErrorEvent), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Anthropic.ErrorEvent> ??
7777
throw new global::System.InvalidOperationException($"Cannot get type info for {nameof(global::Anthropic.ErrorEvent)}");

src/libs/Anthropic/generate.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
dotnet tool install --global autosdk.cli --prerelease
22
rm -rf Generated
33
curl -o openapi.yaml https://raw.githubusercontent.com/davidmigloz/langchain_dart/main/packages/anthropic_sdk_dart/oas/anthropic_openapi_curated.yaml
4-
#dotnet run --project ../../helpers/FixOpenApiSpec openapi.yaml
5-
#if [ $? -ne 0 ]; then
6-
# echo "Failed, exiting..."
7-
# exit 1
8-
#fi
4+
dotnet run --project ../../helpers/FixOpenApiSpec openapi.yaml
5+
if [ $? -ne 0 ]; then
6+
echo "Failed, exiting..."
7+
exit 1
8+
fi
99
autosdk generate openapi.yaml \
1010
--namespace Anthropic \
1111
--clientClassName AnthropicApi \

0 commit comments

Comments
 (0)