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

API updates (current as of 2024-06-14) #56

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Release History

## 2.0.0-beta.5 (Unreleased)

## Features Added

- API updates, current to [openai/openai-openapi@dd73070b](https://github.com/openai/openai-openapi/commit/dd73070b1d507645d24c249a63ebebd3ec38c0cb) ()
- This includes `MaxResults` for Assistants `FileSearchToolDefinition`, `ParallelToolCallsEnabled` for function tools in Assistants and Chat, and `FileChunkingStrategy` for Assistants VectorStores

## Breaking Changes

**Assistants**:
- `InputQuote` is removed from Assistants `TextAnnotation` and `TextAnnotationUpdate`, per [openai/openai-openapi@dd73070b](https://github.com/openai/openai-openapi/commit/dd73070b1d507645d24c249a63ebebd3ec38c0cb) ()

## 2.0.0-beta.4 (2024-06-10)

## Features Added
Expand Down
32 changes: 28 additions & 4 deletions api/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ namespace OpenAI.Assistants {
public IDictionary<string, string> Metadata { get; }
public string ModelOverride { get; init; }
public float? NucleusSamplingFactor { get; init; }
public bool? ParallelToolCallsEnabled { get; init; }
public AssistantResponseFormat ResponseFormat { get; init; }
public float? Temperature { get; init; }
public ToolConstraint ToolConstraint { get; init; }
Expand Down Expand Up @@ -292,6 +293,7 @@ namespace OpenAI.Assistants {
}
public class FileSearchToolDefinition : ToolDefinition {
public FileSearchToolDefinition();
public int? MaxResults { get; init; }
}
public class FileSearchToolResources {
public FileSearchToolResources();
Expand Down Expand Up @@ -368,7 +370,6 @@ namespace OpenAI.Assistants {
public class MessageTextContentAnnotation {
public int EndIndex { get; }
public string InputFileId { get; }
public string InputQuote { get; }
public string OutputFileId { get; }
public int StartIndex { get; }
public string TextToReplace { get; }
Expand Down Expand Up @@ -563,7 +564,6 @@ namespace OpenAI.Assistants {
public class TextAnnotation {
public int EndIndex { get; }
public string InputFileId { get; }
public string InputQuote { get; }
public string OutputFileId { get; }
public int StartIndex { get; }
public string TextToReplace { get; }
Expand All @@ -572,13 +572,13 @@ namespace OpenAI.Assistants {
public int ContentIndex { get; }
public int? EndIndex { get; }
public string InputFileId { get; }
public string InputQuote { get; }
public string OutputFileId { get; }
public int? StartIndex { get; }
public string TextToReplace { get; }
}
public class ThreadInitializationMessage : MessageCreationOptions {
public ThreadInitializationMessage(IEnumerable<MessageContent> content);
public static implicit operator ThreadInitializationMessage(string initializationMessage);
}
public class ThreadMessage {
public string AssistantId { get; }
Expand Down Expand Up @@ -611,6 +611,7 @@ namespace OpenAI.Assistants {
public IReadOnlyDictionary<string, string> Metadata { get; }
public string Model { get; }
public float? NucleusSamplingFactor { get; }
public bool? ParallelToolCallsEnabled { get; init; }
public IReadOnlyList<RequiredAction> RequiredActions { get; }
public AssistantResponseFormat ResponseFormat { get; }
public DateTimeOffset? StartedAt { get; }
Expand All @@ -635,9 +636,10 @@ namespace OpenAI.Assistants {
public static ToolConstraint Required { get; }
}
public abstract class ToolDefinition {
protected ToolDefinition(string type);
protected ToolDefinition();
public static CodeInterpreterToolDefinition CreateCodeInterpreter();
public static FileSearchToolDefinition CreateFileSearch();
public static FileSearchToolDefinition CreateFileSearch(int? maxResults = null);
public static FunctionToolDefinition CreateFunction(string name, string description = null, BinaryData parameters = null);
}
public class ToolOutput {
Expand Down Expand Up @@ -839,11 +841,15 @@ namespace OpenAI.Chat {
protected ChatClient();
public virtual ClientPipeline Pipeline { get; }
public virtual ClientResult<ChatCompletion> CompleteChat(IEnumerable<ChatMessage> messages, ChatCompletionOptions options = null);
public virtual ClientResult<ChatCompletion> CompleteChat(params ChatMessage[] messages);
public virtual ClientResult CompleteChat(BinaryContent content, RequestOptions options = null);
public virtual Task<ClientResult<ChatCompletion>> CompleteChatAsync(IEnumerable<ChatMessage> messages, ChatCompletionOptions options = null);
public virtual Task<ClientResult<ChatCompletion>> CompleteChatAsync(params ChatMessage[] messages);
public virtual Task<ClientResult> CompleteChatAsync(BinaryContent content, RequestOptions options = null);
public virtual ResultCollection<StreamingChatCompletionUpdate> CompleteChatStreaming(IEnumerable<ChatMessage> messages, ChatCompletionOptions options = null);
public virtual ResultCollection<StreamingChatCompletionUpdate> CompleteChatStreaming(params ChatMessage[] messages);
public virtual AsyncResultCollection<StreamingChatCompletionUpdate> CompleteChatStreamingAsync(IEnumerable<ChatMessage> messages, ChatCompletionOptions options = null);
public virtual AsyncResultCollection<StreamingChatCompletionUpdate> CompleteChatStreamingAsync(params ChatMessage[] messages);
}
public class ChatCompletionOptions {
public ChatCompletionOptions();
Expand All @@ -853,6 +859,7 @@ namespace OpenAI.Chat {
public bool? IncludeLogProbabilities { get; init; }
public IDictionary<int, int> LogitBiases { get; }
public int? MaxTokens { get; init; }
public bool? ParallelToolCallsEnabled { get; init; }
public float? PresencePenalty { get; init; }
public ChatResponseFormat ResponseFormat { get; init; }
public long? Seed { get; init; }
Expand Down Expand Up @@ -885,6 +892,7 @@ namespace OpenAI.Chat {
public string SystemFingerprint { get; }
public IReadOnlyList<ChatToolCall> ToolCalls { get; }
public ChatTokenUsage Usage { get; }
public override string ToString();
}
[Obsolete("This field is marked as deprecated.")]
public class ChatFunction {
Expand Down Expand Up @@ -916,6 +924,7 @@ namespace OpenAI.Chat {
public static UserChatMessage CreateUserMessage(string content);
public static UserChatMessage CreateUserMessage(IEnumerable<ChatMessageContentPart> contentParts);
public static UserChatMessage CreateUserMessage(params ChatMessageContentPart[] contentParts);
public static implicit operator ChatMessage(string userMessage);
}
public class ChatMessageContentPart {
public BinaryData ImageBytes { get; }
Expand All @@ -927,6 +936,8 @@ namespace OpenAI.Chat {
public static ChatMessageContentPart CreateImageMessageContentPart(Uri imageUri, ImageChatMessageContentPartDetail? imageDetail = null);
public static ChatMessageContentPart CreateImageMessageContentPart(BinaryData imageBytes, string imageBytesMediaType, ImageChatMessageContentPartDetail? imageDetail = null);
public static ChatMessageContentPart CreateTextMessageContentPart(string text);
public static implicit operator ChatMessageContentPart(string content);
public override string ToString();
}
public readonly struct ChatMessageContentPartKind : IEquatable<ChatMessageContentPartKind> {
public ChatMessageContentPartKind(string value);
Expand Down Expand Up @@ -1481,6 +1492,7 @@ namespace OpenAI.VectorStores {
}
public class VectorStoreCreationOptions {
public VectorStoreCreationOptions();
public FileChunkingStrategy ChunkingStrategy { get; init; }
public VectorStoreExpirationPolicy ExpirationPolicy { get; init; }
public IList<string> FileIds { get; init; }
public IDictionary<string, string> Metadata { get; }
Expand All @@ -1492,6 +1504,17 @@ namespace OpenAI.VectorStores {
public IDictionary<string, string> Metadata { get; }
public string Name { get; init; }
}
public abstract class FileChunkingStrategy {
protected FileChunkingStrategy();
public static FileChunkingStrategy Auto { get; }
public static FileChunkingStrategy Unknown { get; }
public static FileChunkingStrategy CreateStaticStrategy(int maxTokensPerChunk, int overlappingTokenCount);
}
public class StaticFileChunkingStrategy : FileChunkingStrategy {
public StaticFileChunkingStrategy(int maxTokensPerChunk, int overlappingTokenCount);
public int MaxTokensPerChunk { get; }
public int OverlappingTokenCount { get; }
}
public class VectorStore {
public DateTimeOffset CreatedAt { get; }
public VectorStoreExpirationPolicy ExpirationPolicy { get; }
Expand Down Expand Up @@ -1533,6 +1556,7 @@ namespace OpenAI.VectorStores {
public required int Days { get; init; }
}
public class VectorStoreFileAssociation {
public FileChunkingStrategy ChunkingStrategy { get; }
public DateTimeOffset CreatedAt { get; }
public string FileId { get; }
public VectorStoreFileAssociationError? LastError { get; }
Expand Down
1 change: 0 additions & 1 deletion examples/Assistants/Example02_FunctionCalling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ PageableCollection<ThreadMessage> messages
foreach (TextAnnotation annotation in contentItem.TextAnnotations)
{
Console.WriteLine($"* File ID used by file_search: {annotation.InputFileId}");
Console.WriteLine($"* file_search quote from file: {annotation.InputQuote}");
Console.WriteLine($"* File ID created by code_interpreter: {annotation.OutputFileId}");
Console.WriteLine($"* Text to replace: {annotation.TextToReplace}");
Console.WriteLine($"* Message content index range: {annotation.StartIndex}-{annotation.EndIndex}");
Expand Down
1 change: 0 additions & 1 deletion examples/Assistants/Example02_FunctionCallingAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ AsyncPageableCollection<ThreadMessage> messages
foreach (TextAnnotation annotation in contentItem.TextAnnotations)
{
Console.WriteLine($"* File ID used by file_search: {annotation.InputFileId}");
Console.WriteLine($"* file_search quote from file: {annotation.InputQuote}");
Console.WriteLine($"* File ID created by code_interpreter: {annotation.OutputFileId}");
Console.WriteLine($"* Text to replace: {annotation.TextToReplace}");
Console.WriteLine($"* Message content index range: {annotation.StartIndex}-{annotation.EndIndex}");
Expand Down
1 change: 0 additions & 1 deletion examples/Assistants/Example04_AllTheTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ PageableCollection<ThreadMessage> messages
foreach (TextAnnotation annotation in contentItem.TextAnnotations)
{
Console.WriteLine($"* File ID used by file_search: {annotation.InputFileId}");
Console.WriteLine($"* file_search quote from file: {annotation.InputQuote}");
Console.WriteLine($"* File ID created by code_interpreter: {annotation.OutputFileId}");
Console.WriteLine($"* Text to replace: {annotation.TextToReplace}");
Console.WriteLine($"* Message content index range: {annotation.StartIndex}-{annotation.EndIndex}");
Expand Down
1 change: 1 addition & 0 deletions src/Custom/Assistants/AssistantClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ private static BinaryContent CreateThreadAndRunProtocolContent(
runOptions.MaxCompletionTokens,
runOptions.TruncationStrategy,
runOptions.ToolConstraint,
runOptions.ParallelToolCallsEnabled,
runOptions.ResponseFormat,
serializedAdditionalRawData: null);
return internalRequest.ToBinaryContent();
Expand Down
28 changes: 28 additions & 0 deletions src/Custom/Assistants/FileSearchToolDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace OpenAI.Assistants;

[CodeGenModel("AssistantToolsFileSearch")]
[CodeGenSuppress(nameof(FileSearchToolDefinition))]
public partial class FileSearchToolDefinition : ToolDefinition
{
public int? MaxResults
{
get => _fileSearch.InternalMaxNumResults;
init => _fileSearch.InternalMaxNumResults = value;
}

/// <summary>
/// Creates a new instance of <see cref="FileSearchToolDefinition"/>.
/// </summary>
public FileSearchToolDefinition()
: base("file_search")
{
_fileSearch = new InternalAssistantToolsFileSearchFileSearch();
}

[CodeGenMember("FileSearch")]
private InternalAssistantToolsFileSearchFileSearch _fileSearch;
}
9 changes: 6 additions & 3 deletions src/Custom/Assistants/FunctionToolDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ public BinaryData Parameters
/// </summary>
[SetsRequiredMembers]
public FunctionToolDefinition(string name, string description = null, BinaryData parameters = null)
: this("function", null, new InternalFunctionDefinition(description, name, parameters, null))
{}
: base("function")
{
Argument.AssertNotNullOrEmpty(name, nameof(name));
_internalFunction = new(description, name, parameters, null);
}

/// <summary>
/// Creates a new instance of <see cref="FunctionToolDefinition"/>.
/// </summary>
public FunctionToolDefinition()
: base("function", null)
: base("function")
{
_internalFunction = new InternalFunctionDefinition();
}
Expand Down
3 changes: 0 additions & 3 deletions src/Custom/Assistants/GeneratorStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
[CodeGenModel("AssistantToolsCode")]
public partial class CodeInterpreterToolDefinition : ToolDefinition { }

[CodeGenModel("AssistantToolsFileSearch")]
public partial class FileSearchToolDefinition : ToolDefinition { }

[CodeGenModel("ThreadMessageStatus")]
public readonly partial struct MessageStatus { }

Expand Down
5 changes: 4 additions & 1 deletion src/Custom/Assistants/Internal/GeneratorStubs.Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,7 @@ internal partial class InternalThreadObjectToolResources { }
internal partial class InternalThreadObjectToolResourcesCodeInterpreter { }

[CodeGenModel("ThreadObjectToolResourcesFileSearch")]
internal partial class InternalThreadObjectToolResourcesFileSearch { }
internal partial class InternalThreadObjectToolResourcesFileSearch { }

[CodeGenModel("AssistantToolsFileSearchTypeOnly")]
internal readonly partial struct InternalAssistantToolsFileSearchTypeOnly { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OpenAI.Assistants;

[CodeGenModel("AssistantToolsFileSearchFileSearch")]
internal partial class InternalAssistantToolsFileSearchFileSearch
{
[CodeGenMember("MaxNumResults")]
internal int? InternalMaxNumResults { get; set; }
}
6 changes: 0 additions & 6 deletions src/Custom/Assistants/MessageTextContentAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ public class MessageTextContentAnnotation
private readonly MessageContentTextAnnotationsFileCitationObject _fileSearchCitation;
private readonly MessageContentTextAnnotationsFilePathObject _codeCitation;

/// <summary>
/// The specific quote cited from the file identified by <see cref="InputFileId"/>, as generated by the
/// <c>file_search</c> tool.
/// </summary>
public string InputQuote => _fileSearchCitation?.FileCitation?.Quote;

/// <summary>
/// The ID of the file cited by the <c>file_search</c> tool for this annotation.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions src/Custom/Assistants/RunCreationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ private set
}
}

/// <summary>
/// Whether to enable parallel function calling during tool use.
/// </summary>
/// <remarks>
/// Assumed <c>true</c> if not otherwise specified.
/// </remarks>
[CodeGenMember("ParallelToolCalls")]
public bool? ParallelToolCallsEnabled { get; init; }

/// <summary>
/// A run-specific collection of tool definitions that will override the assistant-level defaults. If not provided,
/// the assistant's defined tools will be used. Available tools include:
Expand Down
6 changes: 0 additions & 6 deletions src/Custom/Assistants/Streaming/TextAnnotationUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ public class TextAnnotationUpdate
/// </summary>
public int ContentIndex => _fileSearchCitation?.Index ?? _codeCitation?.Index ?? -1;

/// <summary>
/// The specific quote cited from the file identified by <see cref="InputFileId"/>, as generated by the
/// <c>file_search</c> tool.
/// </summary>
public string InputQuote => _fileSearchCitation?.FileCitation?.Quote;

/// <summary>
/// The ID of the file cited by the <c>file_search</c> tool for this annotation.
/// </summary>
Expand Down
6 changes: 0 additions & 6 deletions src/Custom/Assistants/TextAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ public class TextAnnotation
private readonly MessageContentTextAnnotationsFileCitationObject _fileSearchCitation;
private readonly MessageContentTextAnnotationsFilePathObject _codeCitation;

/// <summary>
/// The specific quote cited from the file identified by <see cref="InputFileId"/>, as generated by the
/// <c>file_search</c> tool.
/// </summary>
public string InputQuote => _fileSearchCitation?.FileCitation?.Quote;

/// <summary>
/// The ID of the file cited by the <c>file_search</c> tool for this annotation.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Custom/Assistants/ThreadRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ public partial class ThreadRun
/// </summary>
[CodeGenMember("TopP")]
public float? NucleusSamplingFactor { get; }

/// <summary>
/// Whether parallel function calling is enabled during tool use for the thread.
/// </summary>
/// <remarks>
/// Assumed <c>true</c> if not otherwise specified.
/// </remarks>
[CodeGenMember("ParallelToolCalls")]
public bool? ParallelToolCallsEnabled { get; init; }

}
14 changes: 12 additions & 2 deletions src/Custom/Assistants/ToolDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ public abstract partial class ToolDefinition
{
public static CodeInterpreterToolDefinition CreateCodeInterpreter()
=> new CodeInterpreterToolDefinition();
public static FileSearchToolDefinition CreateFileSearch()
=> new FileSearchToolDefinition();
public static FileSearchToolDefinition CreateFileSearch(int? maxResults = null)
{
return new FileSearchToolDefinition()
{
MaxResults = maxResults
};
}
public static FunctionToolDefinition CreateFunction(string name, string description = null, BinaryData parameters = null)
=> new FunctionToolDefinition(name, description, parameters);

protected ToolDefinition(string type)
{
Type = type;
}
}
9 changes: 9 additions & 0 deletions src/Custom/Chat/ChatCompletionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,13 @@ public ChatCompletionOptions()
/// </summary>
[CodeGenMember("FunctionCall")]
public ChatFunctionChoice FunctionChoice { get; init; }

/// <summary>
/// Whether to enable parallel function calling during tool use.
/// </summary>
/// <remarks>
/// Assumed <c>true</c> if not otherwise specified.
/// </remarks>
[CodeGenMember("ParallelToolCalls")]
public bool? ParallelToolCallsEnabled { get; init; }
}
Loading
Loading