Skip to content
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
5 changes: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Agent Notes

- Client providers use `IClientProvider` for configuration-driven creation of chat, speech-to-text, and text-to-speech clients.
- `IClientProvider` and `IClientFactory` are the canonical provider/factory APIs; do not add chat-only compatibility abstractions.
- Provider-created clients should expose the bound provider options through `GetService(typeof(object), "options")` and typed options requests.
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ var grok = app.Services.GetRequiredKeyedService<IChatClient>("Grok");
Changing the `appsettings.json` file will automatically update the client
configuration without restarting the application.

The same provider resolution can also create speech clients from configuration
through `IClientFactory`:

```csharp
var section = host.Configuration.GetRequiredSection("AI:Clients:OpenAI");
var factory = app.Services.GetRequiredService<IClientFactory>();
var chat = factory.CreateChatClient(section);
var speechToText = factory.CreateSpeechToTextClient(section);
var textToSpeech = factory.CreateTextToSpeechClient(section);
```

There's also a simpler `Chat` class for streamlined creation of chat messages, which can
be used instead of creating an array of `ChatMessage` using `ChatRole.[System|Assistant|User]`:

Expand Down
4 changes: 1 addition & 3 deletions src/Extensions.Console/JsonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ static class JsonExtensions
{
static readonly JsonSerializerOptions options = new JsonSerializerOptions(JsonSerializerDefaults.Web);

/// <summary>
/// Recursively truncates long strings in an object before serialization and optionally excludes additional properties.
/// </summary>
/// <summary>Recursively truncates long strings in an object before serialization and optionally excludes additional properties.</summary>
public static string ToShortJsonString(this object? value, int? maxStringLength = 100, bool includeAdditionalProperties = true)
{
if (value is null)
Expand Down
14 changes: 3 additions & 11 deletions src/Extensions/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

namespace Devlooped.Extensions.AI;

/// <summary>
/// Collection of <see cref="ChatMessage"/> for more convenient usage
/// in fluent construction of chat messages.
/// </summary>
/// <summary>Collection of <see cref="ChatMessage"/> for more convenient usage in fluent construction of chat messages.</summary>
[DebuggerTypeProxy(typeof(ChatDebugView))]
[DebuggerDisplay("Count = {messages.Count}")]
public class Chat : IList<ChatMessage>
Expand All @@ -27,10 +24,7 @@ public ChatMessage this[int index]
/// <summary>Gets a value indicating whether the chat is read-only.</summary>
public bool IsReadOnly => ((ICollection<ChatMessage>)messages).IsReadOnly;

/// <summary>
/// Adds a message to the list of chat messages.
/// For use with collection initializer syntax.
/// </summary>
/// <summary>Adds a message to the list of chat messages. For use with collection initializer syntax.</summary>
public void Add(ChatMessage message) => messages.Add(message);

/// <summary>Clears all messages from the chat.</summary>
Expand All @@ -46,9 +40,7 @@ public ChatMessage this[int index]
/// <param name="messages">The messages to add</param>
public void AddRange(IEnumerable<ChatMessage> messages) => this.messages.AddRange(messages);

/// <summary>
/// Adds a message to the list of chat messages.
/// </summary>
/// <summary>Adds a message to the list of chat messages.</summary>
/// <param name="role">The message role</param>
/// <param name="message">The message text</param>
/// <remarks>
Expand Down
147 changes: 0 additions & 147 deletions src/Extensions/ChatClientFactoryExtensions.cs

This file was deleted.

160 changes: 0 additions & 160 deletions src/Extensions/ChatClientProviders.cs

This file was deleted.

8 changes: 2 additions & 6 deletions src/Extensions/ChatExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@

namespace Devlooped.Extensions.AI;

/// <summary>
/// Provides usability overloads for the <see cref="IChatClient"/> interface.
/// </summary>
/// <summary>Provides usability overloads for the <see cref="IChatClient"/> interface.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class ChatExtensions
{
extension(IChatClient client)
{
/// <summary>
/// Allows passing a <see cref="Chat"/> instance to the chat client
/// </summary>
/// <summary>Allows passing a <see cref="Chat"/> instance to the chat client</summary>
/// <param name="chat">The chat messages in a single object.</param>
/// <param name="options">The optional chat options.</param>
/// <param name="cancellation">Optional cancellation token.</param>
Expand Down
Loading
Loading