Skip to content

Commit 5218e93

Browse files
committed
merge
2 parents 20630af + 84286cd commit 5218e93

File tree

664 files changed

+484051
-17838
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

664 files changed

+484051
-17838
lines changed

.config/dotnet-tools.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
"snippet-generator"
99
],
1010
"rollForward": false
11+
},
12+
"azure.sdk.tools.testproxy": {
13+
"version": "1.0.0-dev.20250922.2",
14+
"commands": [
15+
"test-proxy"
16+
],
17+
"rollForward": false
1118
}
1219
}
1320
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# This workflow validates changes made to the codegen folder by running code generation
2+
# and ensuring the process completes successfully without errors.
3+
name: CodeGen Validation
4+
5+
on:
6+
pull_request:
7+
paths:
8+
- 'codegen/**'
9+
- '.github/workflows/codegen-validation.yml'
10+
- 'scripts/Invoke-CodeGen.ps1'
11+
types: [opened, reopened, synchronize]
12+
workflow_dispatch:
13+
14+
jobs:
15+
validate-codegen:
16+
name: Validate Code Generation
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '22.x'
27+
28+
- name: Setup .NET
29+
uses: actions/setup-dotnet@v4
30+
with:
31+
# Use the version specified in global.json
32+
global-json-file: global.json
33+
34+
- name: Run CodeGen Script
35+
shell: pwsh
36+
run: |
37+
Write-Host "Running code generation validation..."
38+
./scripts/Invoke-CodeGen.ps1
39+
40+
if ($LASTEXITCODE -ne 0) {
41+
Write-Error "Code generation failed with exit code: $LASTEXITCODE"
42+
exit $LASTEXITCODE
43+
}
44+
45+
Write-Host "Code generation completed successfully!"
46+
47+
- name: Check for uncommitted changes
48+
run: |
49+
# Check if there are any changes to tracked files after code generation
50+
if ! git diff --quiet; then
51+
echo "::error::Code generation produced uncommitted changes. Please run the codegen script locally and commit the results."
52+
echo "Changed files:"
53+
git diff --name-only
54+
echo "Diff details:"
55+
git diff
56+
exit 1
57+
fi
58+
59+
# Also check for untracked files that might have been generated
60+
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
61+
echo "::error::Code generation produced untracked files. Please review and commit them if they should be included."
62+
echo "Untracked files:"
63+
git ls-files --others --exclude-standard
64+
exit 1
65+
fi
66+
67+
echo "No uncommitted changes detected - code generation is up to date!"

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Release History
22

3+
## 2.6.0-beta.1 (Unreleased)
4+
5+
### Features Added
6+
7+
- OpenAI.Chat:
8+
- Added the `Minimal` property to `ChatReasoningEffortLevel`
9+
10+
- OpenAI.Responses:
11+
- Added the `Minimal` property to `ResponseReasoningEffortLevel`
12+
313
## 2.5.0 (2025-09-23)
414

515
### Features Added

api/OpenAI.net8.0.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,7 @@ public class ChatOutputTokenUsageDetails : IJsonModel<ChatOutputTokenUsageDetail
19701970
public static ChatReasoningEffortLevel High { get; }
19711971
public static ChatReasoningEffortLevel Low { get; }
19721972
public static ChatReasoningEffortLevel Medium { get; }
1973+
public static ChatReasoningEffortLevel Minimal { get; }
19731974
public readonly bool Equals(ChatReasoningEffortLevel other);
19741975
[EditorBrowsable(EditorBrowsableState.Never)]
19751976
public override readonly bool Equals(object obj);
@@ -5637,6 +5638,7 @@ public class ResponseOutputTokenUsageDetails : IJsonModel<ResponseOutputTokenUsa
56375638
public static ResponseReasoningEffortLevel High { get; }
56385639
public static ResponseReasoningEffortLevel Low { get; }
56395640
public static ResponseReasoningEffortLevel Medium { get; }
5641+
public static ResponseReasoningEffortLevel Minimal { get; }
56405642
public readonly bool Equals(ResponseReasoningEffortLevel other);
56415643
[EditorBrowsable(EditorBrowsableState.Never)]
56425644
public override readonly bool Equals(object obj);

api/OpenAI.netstandard2.0.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,7 @@ public class ChatOutputTokenUsageDetails : IJsonModel<ChatOutputTokenUsageDetail
17241724
public static ChatReasoningEffortLevel High { get; }
17251725
public static ChatReasoningEffortLevel Low { get; }
17261726
public static ChatReasoningEffortLevel Medium { get; }
1727+
public static ChatReasoningEffortLevel Minimal { get; }
17271728
public readonly bool Equals(ChatReasoningEffortLevel other);
17281729
[EditorBrowsable(EditorBrowsableState.Never)]
17291730
public override readonly bool Equals(object obj);
@@ -4984,6 +4985,7 @@ public class ResponseOutputTokenUsageDetails : IJsonModel<ResponseOutputTokenUsa
49844985
public static ResponseReasoningEffortLevel High { get; }
49854986
public static ResponseReasoningEffortLevel Low { get; }
49864987
public static ResponseReasoningEffortLevel Medium { get; }
4988+
public static ResponseReasoningEffortLevel Minimal { get; }
49874989
public readonly bool Equals(ResponseReasoningEffortLevel other);
49884990
[EditorBrowsable(EditorBrowsableState.Never)]
49894991
public override readonly bool Equals(object obj);

codegen/generator/src/OpenAI.Library.Plugin.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.TypeSpec.Generator.ClientModel" Version="1.0.0-alpha.20250926.1" />
11+
<PackageReference Include="Microsoft.TypeSpec.Generator.ClientModel" Version="1.0.0-alpha.20251001.2" />
1212
</ItemGroup>
1313

1414
<!-- Copy output to package dist path for local execution and -->
@@ -22,6 +22,3 @@
2222
</Target>
2323

2424
</Project>
25-
26-
27-

codegen/generator/src/OpenAILibraryGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.ComponentModel.Composition;
32
using Microsoft.TypeSpec.Generator;
43
using Microsoft.TypeSpec.Generator.ClientModel;
@@ -16,11 +15,12 @@ public OpenAILibraryGenerator(GeneratorContext context) : base(context) { }
1615
protected override void Configure()
1716
{
1817
base.Configure();
18+
// This should be first, as it recomputes the type
19+
AddVisitor(new NonAbstractPublicTypesVisitor());
1920
AddVisitor(new ConstructorFixupVisitor());
2021
AddVisitor(new KindRenameVisitor());
2122
AddVisitor(new VisibilityVisitor());
2223
AddVisitor(new ContentInnerCollectionDefinedVisitor());
23-
AddVisitor(new NonAbstractPublicTypesVisitor());
2424
AddVisitor(new PageOrderRemovalVisitor(this));
2525
AddVisitor(new OmittedTypesVisitor());
2626
AddVisitor(new InvariantFormatAdditionalPropertiesVisitor());

codegen/generator/src/Visitors/NonAbstractPublicTypesVisitor.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.TypeSpec.Generator.ClientModel;
22
using Microsoft.TypeSpec.Generator.Primitives;
33
using Microsoft.TypeSpec.Generator.Providers;
4-
using System.Reflection;
54

65
namespace OpenAILibraryPlugin.Visitors;
76

@@ -17,16 +16,22 @@ protected override TypeProvider VisitType(TypeProvider type)
1716
&& type.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Abstract)
1817
&& type.CustomCodeView?.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Abstract) == false)
1918
{
19+
var serializationProviders = type.SerializationProviders;
20+
21+
// ensure we build the serialization attributes before we change the modifiers
22+
foreach (var serialization in serializationProviders)
23+
{
24+
_ = serialization.Attributes;
25+
}
26+
2027
// Keep types defined in custom code without 'abstract' non-abstract
28+
type.Update(modifiers: type.DeclarationModifiers & ~TypeSignatureModifiers.Abstract);
2129

22-
// To do: replace with this line when dependencies updated to include modifier support
23-
// type.Update(modifiers: type.DeclarationModifiers & ~TypeSignatureModifiers.Abstract);
24-
// To do: remove this reflection-based workaround for the above:
25-
FieldInfo privateModifiersInfo = typeof(TypeProvider)
26-
.GetField("_declarationModifiers", BindingFlags.Instance | BindingFlags.NonPublic)!;
27-
TypeSignatureModifiers privateValue = (TypeSignatureModifiers)privateModifiersInfo.GetValue(type)!;
28-
privateValue &= ~TypeSignatureModifiers.Abstract;
29-
privateModifiersInfo.SetValue(type, privateValue);
30+
// reset the serialization to pick up the new modifiers while keeping any serialization attributes
31+
foreach (var serialization in serializationProviders)
32+
{
33+
serialization.Update(attributes: serialization.Attributes, reset: true);
34+
}
3035
}
3136
return type;
3237
}

codegen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"dependencies": {
3131
"@open-ai/plugin": "file:",
3232
"@azure-tools/typespec-client-generator-core": "0.60.0",
33-
"@typespec/http-client-csharp": "1.0.0-alpha.20250926.1",
33+
"@typespec/http-client-csharp": "1.0.0-alpha.20251001.2",
3434
"@typespec/http": "1.4.0",
3535
"@typespec/openapi": "1.4.0"
3636
},
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SAMPLE: Analyzes image by passing a base64-encoded image through Responses API
2+
// PAGE: https://platform.openai.com/docs/guides/images-vision?api-mode=responses&format=base64-encoded#analyze-images
3+
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
4+
#pragma warning disable OPENAI001
5+
6+
#:package OpenAI@2.*
7+
#:property PublishAot=false
8+
9+
using OpenAI.Responses;
10+
11+
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
12+
OpenAIResponseClient client = new(model: "gpt-5", apiKey: key);
13+
14+
Uri imageUrl = new("https://openai-documentation.vercel.app/images/cat_and_otter.png");
15+
using HttpClient http = new();
16+
17+
// Download an image as stream
18+
using var stream = await http.GetStreamAsync(imageUrl);
19+
20+
OpenAIResponse response1 = (OpenAIResponse)client.CreateResponse([
21+
ResponseItem.CreateUserMessageItem([
22+
ResponseContentPart.CreateInputTextPart("What is in this image?"),
23+
ResponseContentPart.CreateInputImagePart(BinaryData.FromStream(stream), "image/png")
24+
])
25+
]);
26+
27+
Console.WriteLine($"From image stream: {response1.GetOutputText()}");
28+
29+
// Download an image as byte array
30+
byte[] bytes = await http.GetByteArrayAsync(imageUrl);
31+
32+
OpenAIResponse response2 = (OpenAIResponse)client.CreateResponse([
33+
ResponseItem.CreateUserMessageItem([
34+
ResponseContentPart.CreateInputTextPart("What is in this image?"),
35+
ResponseContentPart.CreateInputImagePart(BinaryData.FromBytes(bytes), "image/png")
36+
])
37+
]);
38+
39+
Console.WriteLine($"From byte array: {response2.GetOutputText()}");

0 commit comments

Comments
 (0)