Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9.0.1 #687

Merged
merged 11 commits into from
Dec 4, 2024
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,4 @@ MigrationBackup/
FodyWeavers.xsd

# JetBrains IDEs
.idea
.idea
4 changes: 2 additions & 2 deletions OpenAI.SDK/Betalgo.Ranul.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageIcon>Betalgo-Ranul-OpenAI-icon.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>OpenAI SDK by Betalgo</Title>
<Version>9.0.0</Version>
<Version>9.0.1</Version>
<Authors>Tolga Kayhan, Betalgo</Authors>
<Company>Betalgo Up Ltd.</Company>
<Product>OpenAI .NET library by Betalgo Ranul</Product>
Expand Down Expand Up @@ -70,7 +70,7 @@
<PackageReference Include="System.Net.Http.Json" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.0.0-preview.9.24525.1" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.0.1-preview.1.24570.5" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public string MessageModify(string threadId, string messageId)
return $"{AssistantPrefix}/threads/{threadId}/messages/{messageId}{AzureVersionQueryString}";
}

public string MessageList(string threadId, PaginationRequest? messageListRequest)
public string MessageList(string threadId, MessageListRequest? messageListRequest)
{
var url = $"{AssistantPrefix}/threads/{threadId}/messages{AzureVersionQueryString}";

Expand Down
2 changes: 1 addition & 1 deletion OpenAI.SDK/EndpointProviders/IOpenAiEndpointProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal interface IOpenAIEndpointProvider
string MessageCreate(string threadId);
string MessageRetrieve(string threadId, string messageId);
string MessageModify(string threadId, string messageId);
string MessageList(string threadId, PaginationRequest? messageListRequest);
string MessageList(string threadId, MessageListRequest? messageListRequest);
string RunCreate(string threadId);
string RunRetrieve(string threadId, string runId);
string RunModify(string threadId, string runId);
Expand Down
2 changes: 1 addition & 1 deletion OpenAI.SDK/EndpointProviders/OpenAiEndpointProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public string MessageModify(string threadId, string messageId)
return $"{_apiVersion}/threads/{threadId}/messages/{messageId}";
}

public string MessageList(string threadId, PaginationRequest? messageListRequest)
public string MessageList(string threadId, MessageListRequest? messageListRequest)
{
var url = $"{_apiVersion}/threads/{threadId}/messages";

Expand Down
2 changes: 1 addition & 1 deletion OpenAI.SDK/Interfaces/IMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface IMessageService
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<MessageListResponse> ListMessages(string threadId, PaginationRequest? request = null, CancellationToken cancellationToken = default);
Task<MessageListResponse> ListMessages(string threadId, MessageListRequest? request = null, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve a message.
Expand Down
8 changes: 3 additions & 5 deletions OpenAI.SDK/Managers/OpenAIChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ public partial class OpenAIService : IChatClient
ChatClientMetadata IChatClient.Metadata => _chatMetadata ??= new(nameof(OpenAIService), _httpClient.BaseAddress, _defaultModelId);

/// <inheritdoc />
TService? IChatClient.GetService<TService>(object? key) where TService : class
{
return this as TService;
}
object? IChatClient.GetService(Type serviceType, object? serviceKey) =>
serviceKey is null && serviceType?.IsInstanceOfType(this) is true ? this : null;

/// <inheritdoc />
void IDisposable.Dispose()
Expand Down Expand Up @@ -155,14 +153,14 @@ private ChatCompletionCreateRequest CreateRequest(IList<ChatMessage> chatMessage
request.TopP = options.TopP;
request.FrequencyPenalty = options.FrequencyPenalty;
request.PresencePenalty = options.PresencePenalty;
request.Seed = (int?)options.Seed;
request.StopAsList = options.StopSequences;

// Non-strongly-typed properties from additional properties
request.LogitBias = options.AdditionalProperties?.TryGetValue(nameof(request.LogitBias), out var logitBias) is true ? logitBias : null;
request.LogProbs = options.AdditionalProperties?.TryGetValue(nameof(request.LogProbs), out bool logProbs) is true ? logProbs : null;
request.N = options.AdditionalProperties?.TryGetValue(nameof(request.N), out int n) is true ? n : null;
request.ParallelToolCalls = options.AdditionalProperties?.TryGetValue(nameof(request.ParallelToolCalls), out bool parallelToolCalls) is true ? parallelToolCalls : null;
request.Seed = options.AdditionalProperties?.TryGetValue(nameof(request.Seed), out int seed) is true ? seed : null;
request.ServiceTier = options.AdditionalProperties?.TryGetValue(nameof(request.ServiceTier), out string? serviceTier) is true ? serviceTier : null!;
request.User = options.AdditionalProperties?.TryGetValue(nameof(request.User), out string? user) is true ? user : null!;
request.TopLogprobs = options.AdditionalProperties?.TryGetValue(nameof(request.TopLogprobs), out int topLogprobs) is true ? topLogprobs : null;
Expand Down
7 changes: 5 additions & 2 deletions OpenAI.SDK/Managers/OpenAIEmbeddingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ public partial class OpenAIService : IEmbeddingGenerator<string, Embedding<float
{
private EmbeddingGeneratorMetadata? _embeddingMetadata;

/// <inheritdoc />
EmbeddingGeneratorMetadata IEmbeddingGenerator<string, Embedding<float>>.Metadata =>
_embeddingMetadata ??= new(nameof(OpenAIService), _httpClient.BaseAddress, _defaultModelId);

TService? IEmbeddingGenerator<string, Embedding<float>>.GetService<TService>(object? key) where TService : class =>
this as TService;
/// <inheritdoc />
object? IEmbeddingGenerator<string, Embedding<float>>.GetService(Type serviceType, object? serviceKey) =>
serviceKey is null && serviceType?.IsInstanceOfType(this) is true ? this : null;

/// <inheritdoc />
async Task<GeneratedEmbeddings<Embedding<float>>> IEmbeddingGenerator<string, Embedding<float>>.GenerateAsync(IEnumerable<string> values, EmbeddingGenerationOptions? options, CancellationToken cancellationToken)
{
var response = await this.Embeddings.CreateEmbedding(new()
Expand Down
2 changes: 1 addition & 1 deletion OpenAI.SDK/Managers/OpenAIMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<MessageResponse> CreateMessage(string threadId, MessageCreateR
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<MessageListResponse> ListMessages(string threadId, PaginationRequest? request = null, CancellationToken cancellationToken = default)
public async Task<MessageListResponse> ListMessages(string threadId, MessageListRequest? request = null, CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(threadId))
{
Expand Down
24 changes: 24 additions & 0 deletions OpenAI.SDK/ObjectModels/RequestModels/PaginationRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Text;
using System.Text.Json.Serialization;

namespace Betalgo.Ranul.OpenAI.ObjectModels.RequestModels;
Expand Down Expand Up @@ -83,4 +84,27 @@ public class PaginationRequest

return string.Join("&", build);
}
}

public class MessageListRequest:PaginationRequest
{
/// <summary>
/// extension to base PaginationRequest to add supported runID parameter
/// Filter messages by the run ID that generated them.
/// https://platform.openai.com/docs/api-reference/messages/listMessages#messages-listmessages-run_id
/// </summary>
[JsonPropertyName("run_ID")]
public string? RunId { get; set; }

public override string? GetQueryParameters()
{
// get querystring from base class
var querystring = base.GetQueryParameters();
if (string.IsNullOrWhiteSpace(RunId))
{
return querystring;
}
return querystring == null ? $"run_id={WebUtility.UrlEncode(RunId)}" : $"{querystring}&run_id={WebUtility.UrlEncode(RunId)}";
}

}
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ Due to time constraints, not all methods have been thoroughly tested or fully do
Needless to say, I cannot accept responsibility for any damage caused by using the library.

## Changelog
### 9.0.1
- Message list now accept RunId
- Upgraded to Microsoft.Extensions.AI version 9.0.1, which resolves the "Method not found: '!!0" error when used alongside other SDKs with different versions.

### 9.0.0
- .NET 9 support added.
- ⚠️ Support for .NET 6 and .NET 7 has ended.
Expand Down
Loading