diff --git a/.gitignore b/.gitignore index e7d60a9b..3acf1985 100644 --- a/.gitignore +++ b/.gitignore @@ -363,4 +363,4 @@ MigrationBackup/ FodyWeavers.xsd # JetBrains IDEs -.idea \ No newline at end of file +.idea diff --git a/OpenAI.SDK/Betalgo.Ranul.OpenAI.csproj b/OpenAI.SDK/Betalgo.Ranul.OpenAI.csproj index a660524b..e9d87061 100644 --- a/OpenAI.SDK/Betalgo.Ranul.OpenAI.csproj +++ b/OpenAI.SDK/Betalgo.Ranul.OpenAI.csproj @@ -10,7 +10,7 @@ Betalgo-Ranul-OpenAI-icon.png true OpenAI SDK by Betalgo - 9.0.0 + 9.0.1 Tolga Kayhan, Betalgo Betalgo Up Ltd. OpenAI .NET library by Betalgo Ranul @@ -70,7 +70,7 @@ - + \ No newline at end of file diff --git a/OpenAI.SDK/EndpointProviders/AzureOpenAiEndpointProvider.cs b/OpenAI.SDK/EndpointProviders/AzureOpenAiEndpointProvider.cs index 1380faf2..11233535 100644 --- a/OpenAI.SDK/EndpointProviders/AzureOpenAiEndpointProvider.cs +++ b/OpenAI.SDK/EndpointProviders/AzureOpenAiEndpointProvider.cs @@ -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}"; diff --git a/OpenAI.SDK/EndpointProviders/IOpenAiEndpointProvider.cs b/OpenAI.SDK/EndpointProviders/IOpenAiEndpointProvider.cs index 908fbd1e..53880570 100644 --- a/OpenAI.SDK/EndpointProviders/IOpenAiEndpointProvider.cs +++ b/OpenAI.SDK/EndpointProviders/IOpenAiEndpointProvider.cs @@ -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); diff --git a/OpenAI.SDK/EndpointProviders/OpenAiEndpointProvider.cs b/OpenAI.SDK/EndpointProviders/OpenAiEndpointProvider.cs index f1b0bc61..24070bfe 100644 --- a/OpenAI.SDK/EndpointProviders/OpenAiEndpointProvider.cs +++ b/OpenAI.SDK/EndpointProviders/OpenAiEndpointProvider.cs @@ -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"; diff --git a/OpenAI.SDK/Interfaces/IMessageService.cs b/OpenAI.SDK/Interfaces/IMessageService.cs index 95771b2c..8c58a306 100644 --- a/OpenAI.SDK/Interfaces/IMessageService.cs +++ b/OpenAI.SDK/Interfaces/IMessageService.cs @@ -22,7 +22,7 @@ public interface IMessageService /// /// /// - Task ListMessages(string threadId, PaginationRequest? request = null, CancellationToken cancellationToken = default); + Task ListMessages(string threadId, MessageListRequest? request = null, CancellationToken cancellationToken = default); /// /// Retrieve a message. diff --git a/OpenAI.SDK/Managers/OpenAIChatClient.cs b/OpenAI.SDK/Managers/OpenAIChatClient.cs index 57ba3117..cd2d0f64 100644 --- a/OpenAI.SDK/Managers/OpenAIChatClient.cs +++ b/OpenAI.SDK/Managers/OpenAIChatClient.cs @@ -17,10 +17,8 @@ public partial class OpenAIService : IChatClient ChatClientMetadata IChatClient.Metadata => _chatMetadata ??= new(nameof(OpenAIService), _httpClient.BaseAddress, _defaultModelId); /// - TService? IChatClient.GetService(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; /// void IDisposable.Dispose() @@ -155,6 +153,7 @@ private ChatCompletionCreateRequest CreateRequest(IList 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 @@ -162,7 +161,6 @@ private ChatCompletionCreateRequest CreateRequest(IList chatMessage 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; diff --git a/OpenAI.SDK/Managers/OpenAIEmbeddingGenerator.cs b/OpenAI.SDK/Managers/OpenAIEmbeddingGenerator.cs index 4b7e5717..38c84ee1 100644 --- a/OpenAI.SDK/Managers/OpenAIEmbeddingGenerator.cs +++ b/OpenAI.SDK/Managers/OpenAIEmbeddingGenerator.cs @@ -6,12 +6,15 @@ public partial class OpenAIService : IEmbeddingGenerator EmbeddingGeneratorMetadata IEmbeddingGenerator>.Metadata => _embeddingMetadata ??= new(nameof(OpenAIService), _httpClient.BaseAddress, _defaultModelId); - TService? IEmbeddingGenerator>.GetService(object? key) where TService : class => - this as TService; + /// + object? IEmbeddingGenerator>.GetService(Type serviceType, object? serviceKey) => + serviceKey is null && serviceType?.IsInstanceOfType(this) is true ? this : null; + /// async Task>> IEmbeddingGenerator>.GenerateAsync(IEnumerable values, EmbeddingGenerationOptions? options, CancellationToken cancellationToken) { var response = await this.Embeddings.CreateEmbedding(new() diff --git a/OpenAI.SDK/Managers/OpenAIMessageService.cs b/OpenAI.SDK/Managers/OpenAIMessageService.cs index 9713d0ed..a2773302 100644 --- a/OpenAI.SDK/Managers/OpenAIMessageService.cs +++ b/OpenAI.SDK/Managers/OpenAIMessageService.cs @@ -34,7 +34,7 @@ public async Task CreateMessage(string threadId, MessageCreateR /// /// /// - public async Task ListMessages(string threadId, PaginationRequest? request = null, CancellationToken cancellationToken = default) + public async Task ListMessages(string threadId, MessageListRequest? request = null, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(threadId)) { diff --git a/OpenAI.SDK/ObjectModels/RequestModels/PaginationRequest.cs b/OpenAI.SDK/ObjectModels/RequestModels/PaginationRequest.cs index 73fbfbf3..5b12ac9e 100644 --- a/OpenAI.SDK/ObjectModels/RequestModels/PaginationRequest.cs +++ b/OpenAI.SDK/ObjectModels/RequestModels/PaginationRequest.cs @@ -1,4 +1,5 @@ using System.Net; +using System.Text; using System.Text.Json.Serialization; namespace Betalgo.Ranul.OpenAI.ObjectModels.RequestModels; @@ -83,4 +84,27 @@ public class PaginationRequest return string.Join("&", build); } +} + +public class MessageListRequest:PaginationRequest +{ + /// + /// 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 + /// + [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)}"; + } + } \ No newline at end of file diff --git a/Readme.md b/Readme.md index 32cf8f9a..64d41ad1 100644 --- a/Readme.md +++ b/Readme.md @@ -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.