Skip to content

Commit 774de86

Browse files
authored
Merge pull request #719 from betalgo/dev
9.0.4
2 parents 7265fa4 + 3c6a0bb commit 774de86

File tree

4 files changed

+49
-48
lines changed

4 files changed

+49
-48
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,61 @@
1-
# For most projects, this workflow file will not need changing; you simply need
2-
# to commit it to your repository.
3-
#
4-
# You may wish to alter this file to override the set of languages analyzed,
5-
# or to provide custom queries or build logic.
6-
#
7-
# ******** NOTE ********
8-
# We have attempted to detect the languages in your repository. Please check
9-
# the `language` matrix defined below to confirm you have the correct set of
10-
# supported CodeQL languages.
11-
#
12-
name: "CodeQL"
1+
name: "CodeQL Auto Language"
132

143
on:
154
push:
16-
branches: [ master ]
5+
branches: [ master ]
176
pull_request:
18-
# The branches below must be a subset of the branches above
19-
branches: [ master ]
7+
branches: [ master ]
208
schedule:
21-
- cron: '34 21 * * 2'
9+
- cron: '17 19 * * 6'
2210

2311
jobs:
12+
create-matrix:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
matrix: ${{ steps.set-matrix.outputs.languages }}
16+
steps:
17+
- name: Get languages from repo
18+
id: set-matrix
19+
uses: advanced-security/set-codeql-language-matrix@v1
20+
with:
21+
access-token: ${{ secrets.GITHUB_TOKEN }}
22+
endpoint: ${{ github.event.repository.languages_url }}
23+
2424
analyze:
25+
needs: create-matrix
26+
if: ${{ needs.create-matrix.outputs.matrix != '[]' }}
2527
name: Analyze
26-
runs-on: windows-latest
28+
runs-on: ubuntu-latest
2729
permissions:
2830
actions: read
2931
contents: read
3032
security-events: write
3133

3234
strategy:
3335
fail-fast: false
34-
matrix:
35-
language: [ 'csharp' ]
36-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37-
# Learn more about CodeQL language support at https://git.io/codeql-language-support
36+
matrix:
37+
language: ${{ fromJSON(needs.create-matrix.outputs.matrix) }}
3838

3939
steps:
4040
- name: Checkout repository
41-
uses: actions/checkout@v2
41+
uses: actions/checkout@v3
4242

4343
# Initializes the CodeQL tools for scanning.
4444
- name: Initialize CodeQL
45-
uses: github/codeql-action/init@v2
45+
uses: github/codeql-action/init@v3
4646
with:
4747
languages: ${{ matrix.language }}
48-
# If you wish to specify custom queries, you can do so here or in a config file.
49-
# By default, queries listed here will override any specified in a config file.
50-
# Prefix the list here with "+" to use these queries and those in the config file.
51-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
52-
48+
5349
- name: Set up dotnet
5450
uses: actions/setup-dotnet@v1
5551
with:
5652
dotnet-version: '9.0.*'
57-
53+
5854
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
59-
# If this step fails, then you should remove it and run the build manually (see below)
6055
- name: Autobuild
61-
uses: github/codeql-action/autobuild@v2
62-
63-
# ℹ️ Command-line programs to run using the OS shell.
64-
# 📚 https://git.io/JvXDl
65-
66-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
67-
# and modify them (or add more) to build your code if your project
68-
# uses a compiled language
69-
70-
#- run: |
71-
# make bootstrap
72-
# make release
56+
uses: github/codeql-action/autobuild@v3
7357

7458
- name: Perform CodeQL Analysis
75-
uses: github/codeql-action/analyze@v2
59+
uses: github/codeql-action/analyze@v3
60+
with:
61+
category: "/language:${{matrix.language}}"

OpenAI.SDK/Betalgo.Ranul.OpenAI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageIcon>Betalgo-Ranul-OpenAI-icon.png</PackageIcon>
1111
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1212
<Title>OpenAI SDK by Betalgo</Title>
13-
<Version>9.0.3</Version>
13+
<Version>9.0.4</Version>
1414
<Authors>Tolga Kayhan, Betalgo</Authors>
1515
<Company>Betalgo Up Ltd.</Company>
1616
<Product>OpenAI .NET library by Betalgo Ranul</Product>
@@ -70,7 +70,7 @@
7070
<PackageReference Include="System.Net.Http.Json" Version="9.0.0" />
7171
</ItemGroup>
7272
<ItemGroup>
73-
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.4.0-preview.1.25207.5" />
73+
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.5.0" />
7474
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
7575
</ItemGroup>
7676
</Project>

OpenAI.SDK/Managers/OpenAIChatClient.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ namespace Betalgo.Ranul.OpenAI.Managers;
1111

1212
public partial class OpenAIService : IChatClient
1313
{
14+
private static readonly AIJsonSchemaTransformCache s_schemaTransformCache = new(new()
15+
{
16+
// https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#supported-schemas
17+
DisallowAdditionalProperties = true,
18+
RequireAllProperties = true,
19+
MoveDefaultKeywordToDescription = true,
20+
});
21+
1422
private ChatClientMetadata? _chatMetadata;
1523

1624
/// <inheritdoc />
@@ -43,7 +51,8 @@ async Task<ChatResponse> IChatClient.GetResponseAsync(IEnumerable<ChatMessage> m
4351
{
4452
Role = new(choice.Message.Role),
4553
AuthorName = choice.Message.Name,
46-
RawRepresentation = choice
54+
RawRepresentation = choice,
55+
MessageId = response.Id
4756
};
4857

4958
PopulateContents(choice.Message, m.Contents);
@@ -91,6 +100,7 @@ async IAsyncEnumerable<ChatResponseUpdate> IChatClient.GetStreamingResponseAsync
91100
ModelId = response.Model,
92101
RawRepresentation = response,
93102
ResponseId = response.Id,
103+
MessageId = response.Id,
94104
Role = choice.Delta.Role is not null ? new(choice.Delta.Role) : null
95105
};
96106

@@ -118,6 +128,7 @@ async IAsyncEnumerable<ChatResponseUpdate> IChatClient.GetStreamingResponseAsync
118128
FinishReason = choice.FinishReason is not null ? new(choice.FinishReason) : null,
119129
ModelId = response.Model,
120130
ResponseId = response.Id,
131+
MessageId = response.Id,
121132
Role = choice.Delta.Role is not null ? new(choice.Delta.Role) : null
122133
};
123134
}
@@ -150,12 +161,12 @@ private ChatCompletionCreateRequest CreateRequest(IEnumerable<ChatMessage> chatM
150161
request.PresencePenalty = options.PresencePenalty;
151162
request.Seed = (int?)options.Seed;
152163
request.StopAsList = options.StopSequences;
164+
request.ParallelToolCalls = options.AllowMultipleToolCalls;
153165

154166
// Non-strongly-typed properties from additional properties
155167
request.LogitBias = options.AdditionalProperties?.TryGetValue(nameof(request.LogitBias), out var logitBias) is true ? logitBias : null;
156168
request.LogProbs = options.AdditionalProperties?.TryGetValue(nameof(request.LogProbs), out bool logProbs) is true ? logProbs : null;
157169
request.N = options.AdditionalProperties?.TryGetValue(nameof(request.N), out int n) is true ? n : null;
158-
request.ParallelToolCalls = options.AdditionalProperties?.TryGetValue(nameof(request.ParallelToolCalls), out bool parallelToolCalls) is true ? parallelToolCalls : null;
159170
request.ServiceTier = options.AdditionalProperties?.TryGetValue(nameof(request.ServiceTier), out string? serviceTier) is true ? serviceTier : null!;
160171
request.User = options.AdditionalProperties?.TryGetValue(nameof(request.User), out string? user) is true ? user : null!;
161172
request.TopLogprobs = options.AdditionalProperties?.TryGetValue(nameof(request.TopLogprobs), out int topLogprobs) is true ? topLogprobs : null;
@@ -309,7 +320,8 @@ private ChatCompletionCreateRequest CreateRequest(IEnumerable<ChatMessage> chatM
309320

310321
private static PropertyDefinition CreateParameters(AIFunction f)
311322
{
312-
return JsonSerializer.Deserialize<PropertyDefinition>(f.JsonSchema) ?? new();
323+
JsonElement openAISchema = s_schemaTransformCache.GetOrCreateTransformedSchema(f);
324+
return JsonSerializer.Deserialize<PropertyDefinition>(openAISchema) ?? new();
313325
}
314326

315327
private static void PopulateContents(ObjectModels.RequestModels.ChatMessage source, IList<AIContent> destination)

Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ Due to time constraints, not all methods have been thoroughly tested or fully do
117117
Needless to say, I cannot accept responsibility for any damage caused by using the library.
118118

119119
## Changelog
120+
### 9.0.4
121+
- Updated `Microsoft.Extensions.AI` to version `9.5.0`
122+
120123
### 9.0.3
121124
- Updated `Microsoft.Extensions.AI` to version `9.4.0-preview.1.25207.5`
122125
- Added new models to the model list

0 commit comments

Comments
 (0)