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

Incorporate further ApiView feedback #42

Closed
wants to merge 5 commits into from

Conversation

trrwilson
Copy link
Collaborator

This PR touches many files, but the volume comes primarily from bulk pattern application.

Changes include:

  • Per SCM guidance, nullable reference type support is added to the project and a first pass has been made across the public surface; this isn't 100% complete, particularly in the internal details, but it's the majority and allows a clear look at the pattern changes.
  • Name properties have been been updated to use a more specific name -- either FunctionName or ParticipantName -- in cases where the question of "what is this the name of" isn't trivially inferable from the type.
  • Public setters on request types have been removed, replaced with init for types where required/init are an intended initialization pattern.
  • ChatMessageContent's type conversions to string and (new) Uri are now explicit.
  • ChatRequestAssistantMessage now uses "text" for its content constructor parameter name.
  • CreatedAt is now present on GeneratedImageCollection (in addition to its emplacement on GeneratedImage).
  • ImageQuality and ImageStyle are renamed with the consistent Generated* prefix.
  • OpenAIClientOptions now derives from the appropriate PipelineClientOptions type.
  • GetLegacyCompletionClient is removed from OpenAIClient.

@@ -23,7 +23,7 @@ public partial class Assistant
/// <item><b>Values</b> can be a maximum of 512 characters in length.</item>
/// </list>
/// </remarks>
public IReadOnlyDictionary<string, string> Metadata { get; }
public IReadOnlyDictionary<string, string>? Metadata { get; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in .NET collections should never be null. The guidelines say they should be empty

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is likely 100% intended, but just to explicitly check: since OpenAI provides empty collections on some response array properties and null on others, us standardizing means we'll lose any parallel distinction. I'm not aware of any case where there's the potential for a "minimal pair" with null and empty meaning different things (and I'd be very sad if we found one), but I can't categorically rule out the possibility, either. Do you have any concerns on that front? If not, I'll ensure we're empty across the board.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR updated with a pass across collections.

{
GeneratedImage IJsonModel<GeneratedImage>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
{
var format = options.Format == "W" ? ((IPersistableModel<GeneratedImage>)this).GetFormatFromOptions(options) : options.Format;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 5 lines of code are repeated a lot. Should we have one helper somewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll abstract it. Most of it will hopefully move back into generated code in the not-too-distant term, but we're still going to have custom implementations and there's no good reason to not de-dupe it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR updated, the internal static ModelSerializationHelpers class abstracts the repeated patterns across IJsonModel<T> and IPersistableModel<T>.

Text = text;
Words = words;
Segments = segments;
Text = text!;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Text be declared as nullable here? Why use the null-forgiving operator (!)?

@@ -141,13 +124,13 @@ public ImageClient(string model, ApiKeyCredential credential = default, OpenAICl

options ??= new();

using MultipartFormDataBinaryContent content = options.ToMultipartContent(fileStream, fileName, prompt, _clientConnector.Model, imageCount);
using MultipartFormDataBinaryContent content = options.ToMultipartContent(fileStream, fileName, prompt, _clientConnector.Model!, imageCount);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious on this one -- how do we know _clientConnector.Model will never be null? If it won't ever be null, should its type be non-nullable?

: base(ChatRole.Assistant, content)
/// <param name="text"> Optional text content associated with the message. </param>
public ChatRequestAssistantMessage(ChatFunctionCall functionCall, string? text = null)
: base(ChatRole.Assistant, text)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's preferable to call it "content" like we did originally, because it's not that we're being inconsistent, but rather that we're representing a subtle but arguably important distinction. This is how I think about it:

  • All the different kinds of message have some form of "content", and we should consistently refer to it as such, regardless of how it is represented (string, array, etc.). This is important in order to align with the REST API and the documentation.
  • In some cases, the content can be an array of "content parts", where a content part can be plain text, an image URL, and possibly other things in the future. We should consistently use "text" when talking about "plain text content parts".

What do you think?

@trrwilson
Copy link
Collaborator Author

Closing this PR in favor of the replacements mentioned above -- those pull apart the aims of this one better informed by the further discussion we've had.

@trrwilson trrwilson closed this Mar 28, 2024
@trrwilson trrwilson deleted the user/travisw/more-apiview-feedback branch May 17, 2024 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants