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

ApiView: port smaller set of feedback changes #47

Merged
merged 5 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 11 additions & 5 deletions .dotnet/src/Custom/Assistants/Assistant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,22 @@
Description = internalAssistant.Description;
DefaultModel = internalAssistant.Model;
DefaultInstructions = internalAssistant.Instructions;
Metadata = internalAssistant.Metadata;
DefaultTools = GetToolsFromInternalTools(internalAssistant.Tools);
Metadata = internalAssistant.Metadata ?? new Dictionary<string, string>();
}

if (internalAssistant.Tools != null)
private static IReadOnlyList<ToolDefinition> GetToolsFromInternalTools(IReadOnlyList<BinaryData>? internalTools)

Check warning on line 40 in .dotnet/src/Custom/Assistants/Assistant.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
if (internalTools is not null)
{
List<ToolDefinition> tools = [];
foreach (BinaryData unionToolDefinitionData in internalAssistant.Tools)
foreach (BinaryData unionToolDefinitionData in internalTools)
{
tools.Add(ToolDefinition.DeserializeToolDefinition(JsonDocument.Parse(unionToolDefinitionData).RootElement));
using JsonDocument toolDocument = JsonDocument.Parse(unionToolDefinitionData);
tools.Add(ToolDefinition.DeserializeToolDefinition(toolDocument.RootElement));
}
DefaultTools = tools;
return tools;
}
return [];
}
}
12 changes: 6 additions & 6 deletions .dotnet/src/Custom/Assistants/AssistantClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,10 @@ internal static Internal.Models.CreateRunRequest CreateInternalCreateRunRequest(
options ??= new();
return new(
assistantId,
options.OverrideModel,
options.OverrideInstructions,
options.ModelOverride,
options.InstructionsOverride,
options.AdditionalInstructions,
ToInternalBinaryDataList(options.OverrideTools),
ToInternalBinaryDataList(options.ToolsOverride),
options.Metadata,
serializedAdditionalRawData: null);
}
Expand All @@ -645,9 +645,9 @@ internal static Internal.Models.CreateThreadAndRunRequest CreateInternalCreateTh
return new Internal.Models.CreateThreadAndRunRequest(
assistantId,
internalThreadOptions,
runOptions?.OverrideModel,
runOptions.OverrideInstructions,
ToInternalBinaryDataList(runOptions?.OverrideTools),
runOptions?.ModelOverride,
runOptions.InstructionsOverride,
ToInternalBinaryDataList(runOptions?.ToolsOverride),
runOptions?.Metadata,
serializedAdditionalRawData: null);
}
Expand Down
9 changes: 3 additions & 6 deletions .dotnet/src/Custom/Assistants/AssistantCreationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using OpenAI.ClientShared.Internal;
using System.ClientModel.Internal;

using System.Collections.Generic;

namespace OpenAI.Assistants;
Expand All @@ -13,16 +10,16 @@ public partial class AssistantCreationOptions
/// <summary>
/// An optional display name for the assistant.
/// </summary>
public string Name { get; set; }
public string Name { get; init; }
/// <summary>
/// A description to associate with the assistant.
/// </summary>
public string Description { get; set; }
public string Description { get; init; }

/// <summary>
/// Default instructions for the assistant to use when creating messages.
/// </summary>
public string Instructions { get; set; }
public string Instructions { get; init; }

/// <summary>
/// A collection of default tool definitions to enable for the assistant. Available tools include:
Expand Down
11 changes: 4 additions & 7 deletions .dotnet/src/Custom/Assistants/AssistantModificationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using OpenAI.ClientShared.Internal;
using System.ClientModel.Internal;

using System.Collections.Generic;

namespace OpenAI.Assistants;
Expand All @@ -13,22 +10,22 @@ public partial class AssistantModificationOptions
/// <summary>
/// The new model that the assistant should use when creating messages.
/// </summary>
public string Model { get; }
public string Model { get; init; }

/// <summary>
/// A new, friendly name for the assistant. Its <see cref="Assistant.Id"/> will remain unchanged.
/// </summary>
public string Name { get; }
public string Name { get; init; }

/// <summary>
/// A new description to associate with the assistant.
/// </summary>
public string Description { get; }
public string Description { get; init; }

/// <summary>
/// New, default instructions for the assistant to use when creating messages.
/// </summary>
public string Instructions { get; }
public string Instructions { get; init; }

/// <summary>
/// A new collection of default tool definitions to enable for the assistant. Available tools include:
Expand Down
2 changes: 1 addition & 1 deletion .dotnet/src/Custom/Assistants/AssistantThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class AssistantThread
internal AssistantThread(Internal.Models.ThreadObject internalThread)
{
Id = internalThread.Id;
Metadata = internalThread.Metadata;
Metadata = internalThread.Metadata ?? new Dictionary<string, string>();
CreatedAt = internalThread.CreatedAt;
}

Expand Down
1 change: 0 additions & 1 deletion .dotnet/src/Custom/Assistants/CodeInterpreterToolInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

Expand Down
14 changes: 5 additions & 9 deletions .dotnet/src/Custom/Assistants/FunctionToolDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
using System;
using System.ClientModel.Internal;

using System.ClientModel;
using System.ClientModel.Primitives;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using OpenAI.ClientShared.Internal;

namespace OpenAI.Assistants;

public partial class FunctionToolDefinition : ToolDefinition
{
public required string Name { get; set; }
public string Description { get; set; }
public BinaryData Parameters { get; set; }
public required string FunctionName { get; init; }
public string Description { get; init; }
public BinaryData Parameters { get; init; }

[SetsRequiredMembers]
public FunctionToolDefinition(string name, string description = null, BinaryData parameters = null)
{
Name = name;
FunctionName = name;
Description = description;
Parameters = parameters;
}
Expand Down Expand Up @@ -74,7 +70,7 @@ internal override void WriteDerived(Utf8JsonWriter writer, ModelReaderWriterOpti
writer.WriteString("type"u8, "function"u8);
writer.WritePropertyName("function"u8);
writer.WriteStartObject();
writer.WriteString("name"u8, Name);
writer.WriteString("name"u8, FunctionName);
if (Optional.IsDefined(Description))
{
writer.WriteString("description"u8, Description);
Expand Down
10 changes: 3 additions & 7 deletions .dotnet/src/Custom/Assistants/FunctionToolInfo.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
using System;
using System.ClientModel.Internal;

using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;
using OpenAI.ClientShared.Internal;

namespace OpenAI.Assistants;

public partial class FunctionToolInfo : ToolInfo
{
public string Name { get; }
public string FunctionName { get; }
public string Description { get; }
public BinaryData Parameters { get; }

internal FunctionToolInfo(string name, string description, BinaryData parameters)
{
Name = name;
FunctionName = name;
Description = description;
Parameters = parameters;
}
Expand Down Expand Up @@ -68,7 +64,7 @@ internal override void WriteDerived(Utf8JsonWriter writer, ModelReaderWriterOpti
writer.WriteString("type"u8, "function"u8);
writer.WritePropertyName("function"u8);
writer.WriteStartObject();
writer.WriteString("name"u8, Name);
writer.WriteString("name"u8, FunctionName);
if (Optional.IsDefined(Description))
{
writer.WriteString("description"u8, Description);
Expand Down
3 changes: 0 additions & 3 deletions .dotnet/src/Custom/Assistants/MessageContent.Serialization.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.ClientModel.Internal;

using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

Expand Down
3 changes: 0 additions & 3 deletions .dotnet/src/Custom/Assistants/MessageCreationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using OpenAI.ClientShared.Internal;
using System.ClientModel.Internal;

using System.Collections.Generic;

namespace OpenAI.Assistants;
Expand Down
1 change: 0 additions & 1 deletion .dotnet/src/Custom/Assistants/MessageImageFileContent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

Expand Down
3 changes: 1 addition & 2 deletions .dotnet/src/Custom/Assistants/MessageTextContent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Text.Json;
Expand All @@ -18,7 +17,7 @@ public class MessageTextContent : MessageContent
internal MessageTextContent(string text, IReadOnlyList<TextContentAnnotation> annotations)
{
Text = text;
Annotations = annotations;
Annotations = annotations ?? [];
}

internal override void WriteDerived(Utf8JsonWriter writer, ModelReaderWriterOptions options)
Expand Down
5 changes: 2 additions & 3 deletions .dotnet/src/Custom/Assistants/RequiredFunctionToolCall.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

namespace OpenAI.Assistants;

public partial class RequiredFunctionToolCall : RequiredToolCall
{
public string Name { get; }
public string FunctionName { get; }
public string Arguments { get; }

internal RequiredFunctionToolCall(string id, string name, string arguments)
: base(id)
{
Name = name;
FunctionName = name;
Arguments = arguments;
}

Expand Down
1 change: 0 additions & 1 deletion .dotnet/src/Custom/Assistants/RequiredToolCall.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

Expand Down
1 change: 0 additions & 1 deletion .dotnet/src/Custom/Assistants/RetrievalToolDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

Expand Down
1 change: 0 additions & 1 deletion .dotnet/src/Custom/Assistants/RetrievalToolInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

Expand Down
15 changes: 5 additions & 10 deletions .dotnet/src/Custom/Assistants/RunCreationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using OpenAI.ClientShared.Internal;
using System.ClientModel.Internal;

using System.Collections.Generic;

namespace OpenAI.Assistants;
Expand All @@ -10,26 +7,24 @@ namespace OpenAI.Assistants;
/// </summary>
public partial class RunCreationOptions
{


/// <summary>
/// A run-specific model name that will override the assistant's defined model. If not provided, the assistant's
/// selection will be used.
/// </summary>
public string OverrideModel { get; set; }
public string ModelOverride { get; init; }

/// <summary>
/// A run specific replacement for the assistant's default instructions that will override the assistant-level
/// instructions. If not specified, the assistant's instructions will be used.
/// </summary>
public string OverrideInstructions { get; set; }
public string InstructionsOverride { get; init; }

/// <summary>
/// Run-specific additional instructions that will be appended to the assistant-level instructions solely for this
/// run. Unlike <see cref="OverrideInstructions"/>, the assistant's instructions are preserved and these additional
/// run. Unlike <see cref="InstructionsOverride"/>, the assistant's instructions are preserved and these additional
/// instructions are concatenated.
/// </summary>
public string AdditionalInstructions { get; set; }
public string AdditionalInstructions { get; init; }

/// <summary>
/// A run-specific collection of tool definitions that will override the assistant-level defaults. If not provided,
Expand All @@ -51,7 +46,7 @@ public partial class RunCreationOptions
/// </list>
/// </para>
/// </summary>
public IList<ToolDefinition> OverrideTools { get; } = new ChangeTrackingList<ToolDefinition>();
public IList<ToolDefinition> ToolsOverride { get; } = new ChangeTrackingList<ToolDefinition>();

/// <summary>
/// An optional key/value mapping of additional, supplemental data items to attach to the <see cref="ThreadRun"/>.
Expand Down
2 changes: 0 additions & 2 deletions .dotnet/src/Custom/Assistants/RunError.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using OpenAI.Chat;

namespace OpenAI.Assistants;

public partial class RunError
Expand Down
3 changes: 0 additions & 3 deletions .dotnet/src/Custom/Assistants/RunModificationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using OpenAI.ClientShared.Internal;
using System.ClientModel.Internal;

using System.Collections.Generic;

namespace OpenAI.Assistants;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.ClientModel.Internal;

using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Text.Json;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.ClientModel.Internal;

using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

Expand Down
3 changes: 0 additions & 3 deletions .dotnet/src/Custom/Assistants/ThreadCreationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using OpenAI.ClientShared.Internal;
using System.ClientModel.Internal;

using System.Collections.Generic;

namespace OpenAI.Assistants;
Expand Down
3 changes: 0 additions & 3 deletions .dotnet/src/Custom/Assistants/ThreadInitializationMessage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using OpenAI.ClientShared.Internal;
using System.ClientModel.Internal;

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

Expand Down
4 changes: 2 additions & 2 deletions .dotnet/src/Custom/Assistants/ThreadMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ internal ThreadMessage(Internal.Models.MessageObject internalMessage)
AssistantId = internalMessage.AssistantId;
ThreadId = internalMessage.ThreadId;
RunId = internalMessage.RunId;
Metadata = internalMessage.Metadata;
FileIds = internalMessage.FileIds;
Metadata = internalMessage.Metadata ?? new Dictionary<string, string>();
FileIds = internalMessage.FileIds ?? [];
CreatedAt = internalMessage.CreatedAt;
Role = convertedRole;
ContentItems = content;
Expand Down
Loading
Loading