Skip to content

Address M.E.AI API feedback #5860

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

Merged
merged 1 commit into from
Feb 10, 2025
Merged

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Feb 7, 2025

  • Remove DataContent.ContainsData. While ContainsData could be used to avoid lazily-instantiating a ReadOnlyMemory<byte> from a data URI, in all cases examined ContainsData was being used to guard accessing Data, in which case Data.HasValue is sufficient.
  • Make ToolMode optional. We'd previously said that an implementation could use null to imply None if it wanted, but with this being optional we'd want null to be the same as auto, so I added in an explicit null options. That matches as well with what various other client libs do.
  • Remove IChatClient/IEmbeddingGenerator.Metadata. GetService can be used instead, reducing what an implementer must implement and what's exposed to a consumer.
  • Add Complete{Streaming}Async for a single message. We have such accelerators in other places but not here, and it provides a natural grow-up from string to ChatMessage to IList<ChatMessage>.
  • Change UsageDetails.XxTokenCount properties from int? to long?. The AdditionalCounts is already based on longs, and in theory the token counts could exceed int, especially in a situation where UsageData is being used to sum many other call data.
  • Rename GenerateEmbeddingVectorAsync's TEmbedding to TEmbeddingElement. Everywhere else TEmbedding is used where it represents an Embedding, but here it represents a numerical element in an embedding vector.
  • Remove setters on FunctionCall/ResultContent for required ctor parameters. Having those setters goes against .NET design guidelines.
  • Remove FunctionResultContent.Name. It's unnecessary and is actually causing us to do more work in places.
Microsoft Reviewers: Open in CodeFlow

- Remove DataContent.ContainsData. While ContainsData could be used to avoid lazily-instantiating a `ReadOnlyMemory<byte>` from a data URI, in all cases examined ContainsData was being used to guard accessing Data, in which case Data.HasValue is sufficient.
- Make ToolMode optional. We'd previously said that an implementation could use null to imply None if it wanted, but with this being optional we'd want null to be the same as auto, so I added in an explicit null options. That matches as well with what various other client libs do.
- Remove IChatClient/IEmbeddingGenerator.Metadata. GetService can be used instead, reducing what an implementer must implement and what's exposed to a consumer.
- Add Complete{Streaming}Async for a single message. We have such accelerators in other places but not here, and it provides a natural grow-up from string to ChatMessage to `IList<ChatMessage>`.
- Change UsageDetails.XxTokenCount properties from int? to long?. The AdditionalCounts is already based on longs, and in theory the token counts could exceed int, especially in a situation where UsageData is being used to sum many other call data.
- Rename GenerateEmbeddingVectorAsync's TEmbedding to TEmbeddingElement. Everywhere else TEmbedding is used where it represents an Embedding, but here it represents a numerical element in an embedding vector.
- Remove setters on FunctionCall/ResultContent for required ctor parameters. Having those setters goes against .NET design guidelines.
- Remove FunctionResultContent.Name. It's unnecessary and is actually causing us to do more work in places.
@dotnet-comment-bot
Copy link
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.Caching.Hybrid Line 86 82.77 🔻
Microsoft.Extensions.AI.Ollama Line 80 78.2 🔻
Microsoft.Gen.MetadataExtractor Line 98 57.35 🔻
Microsoft.Gen.MetadataExtractor Branch 98 62.5 🔻

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.AI 88 89
Microsoft.Extensions.AI.Abstractions 83 85
Microsoft.Extensions.AI.AzureAIInference 91 92

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=944835&view=codecoverage-tab

Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

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

Great. Removal of Metadata is particularly nice - much cleaner to use the existing service location mechanism instead of having a parallel one.

@stephentoub stephentoub merged commit a0688e0 into dotnet:main Feb 10, 2025
6 checks passed
/// <returns>The response messages generated by the client.</returns>
public static Task<ChatCompletion> CompleteAsync(
this IChatClient client,
ChatMessage chatMessage,
Copy link
Member

@eiriktsarpalis eiriktsarpalis Feb 10, 2025

Choose a reason for hiding this comment

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

This new set of extensions can only be used in cases where the chat history consists of only that one message. How common is such a scenario? Could it lead callers into incorrectly assuming that they're appending a chat message to a log that is being encapsulated by the client?

Copy link
Member Author

Choose a reason for hiding this comment

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

This new set of extensions can only be used in cases where the chat history consists of only that one message. How common is such a scenario?

It's pretty common, for at least:

  • Getting started scenarios, where you want to send a single input
  • Non-chat scenarios, where you're sending input to have the LLM give you back a response as part of the logic of you're program.
  • IChatClient implementations where the state is stored server-side, ala assistants

It's no different from the existing string-based overloads that are helpful in similar circumstances but that are limited to TextContent; these overloads allow you to customize beyond that.

@@ -61,16 +64,14 @@ public JsonSerializerOptions ToolCallJsonSerializerOptions
}

/// <inheritdoc />
public ChatClientMetadata Metadata { get; }
Copy link
Member

Choose a reason for hiding this comment

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

Even if no longer part of IChatClient, it seems useful enough to surface as a property on the implementing class.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather we expose it as an extension property once those are possible.

@stephentoub stephentoub deleted the apireviewchanges branch February 10, 2025 13:30
@jeffhandley jeffhandley added the area-ai Microsoft.Extensions.AI libraries label Mar 7, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Apr 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-ai Microsoft.Extensions.AI libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants