Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

Make Wpf Chatclient Factory

БесплатноБез исполняемых скриптовНе проверен

Generates a provider-agnostic IChatClient factory that shares one SocketsHttpHandler across LLM SDKs (OpenAI, Ollama, Anthropic, Gemini) and includes a…

christian289от christian289★ 42 звезды на GitHub

Об этом скилле

WPF ChatClient Factory Generator

If $0 is empty, use the AskUserQuestion tool to ask: "Enter the factory class name (e.g., ChatClientFactory)". Do NOT proceed until a valid name is provided. Use the response as the factory name for all subsequent steps.

Generate $0 (implementing I$0): a provider-agnostic IChatClient factory that owns one shared SocketsHttpHandler (a single connection pool) reused by every LLM SDK, plus a MockChatClient so the chat UI runs with no provider or API key.

  • Replace {Namespace} with the project's root namespace.
  • Register the factory as a DI singleton — see "Required: singleton lifetime".

Full rationale in the sharing-httpclient-across-llm-sdks knowledge topic (fetch via WpfDevPackMcp get_wpf_topic): the socket-exhaustion anti-pattern, disposeHandler:false, the per-SDK injection cheat sheet, and the version-floor caveat. The mock is covered in hosting-extensions-ai-chatclient-in-wpf-mvvm.

⚠️ Verify SDK signatures with HandMirror first

Each LLM SDK exposes a different HttpClient injection point and these APIs are version-sensitive. Before emitting, verify the exact signatures with HandMirror (inspect_nuget_package / inspect_nuget_package_type) for whichever providers you include: OpenAI, OllamaSharp, Anthropic.SDK, Google.GenAI, System.ClientModel, Microsoft.Extensions.AI. Do not ship a provider arm you have not verified against the pinned package version.

Required Packages

<PackageReference Include="Microsoft.Extensions.AI" Version="10.*" />
<!-- OPTIONAL — add only the provider SDKs the user asked for: -->
<PackageReference Include="OpenAI" Version="2.*" />
<PackageReference Include="OllamaSharp" Version="5.*" />
<PackageReference Include="Anthropic.SDK" Version="5.*" />
<PackageReference Include="Google.GenAI" Version="1.*" />

Emit only the arms you installed. The canonical class below shows ALL provider arms for reference. A provider arm whose SDK package is not installed is a CS0246 build error — when emitting, keep the Provider.Mock arm, keep each arm whose package you added, and replace every other arm with => throw new NotSupportedException($"Install and wire the {s.Provider} SDK first."). The mock-only emission (no provider SDK at all) is the correct default when no provider was requested.

Usings: the snippets assume global using System.Net.Http;, global using Microsoft.Extensions.AI;, and global using System.Runtime.CompilerServices; (for [EnumeratorCancellation] in the mock) in GlobalUsings.cs. Provider-arm namespaces (e.g. the OpenAI client, System.ClientModel, OllamaSharp, Anthropic.SDK, Google.GenAI types) are version-sensitive — resolve the exact namespaces with HandMirror (inspect_nuget_package → list_namespaces) at emit time and add per-file usings for the arms you keep.

Version-floor caveat: a native SDK may pin Microsoft.Extensions.AI.Abstractions to a higher version than other consumers (e.g. an MCP client library). The bump is safe only when those other consumers depend on a [x, ) floor that accepts the higher version — verify the dependency is a floor, not an exact pin, before bumping.

Generated Code

Supporting types

namespace {Namespace}.Services;

public enum Provider { Mock, Ollama, OpenAI, AzureOpenAI, OpenAICompatible, Anthropic, Gemini }

public sealed record ChatSettings
{
    public Provider Provider { get; init; }
    public string ModelId { get; init; } = string.Empty;
    public string? BaseUrl { get; init; }
}

public interface I$0
{
    IChatClient Create(ChatSettings s, string? apiKey);
}

$0.cs

Every provider path reuses the same _shared handler. Connection pooling lives in SocketsHttpHandler (the pool), not in the per-call HttpClient wrapper — so calling Pooled() fresh on each Create() still reuses sockets. Only the injection shape differs per SDK (instance vs Func<HttpClient>).

namespace {Namespace}.Services;

public sealed class $0 : I$0
{
    // One handler == one connection pool shared by every provider for the app's lifetime.
    private readonly SocketsHttpHandler _shared = new()
    {
        PooledConnectionLifetime = TimeSpan.FromMinutes(15)
    };

    // Lightweight wrapper; disposeHandler:false keeps the shared pool alive when the
    // wrapper (or a chat client that owns it) is disposed.
    private HttpClient Pooled() => new(_shared, disposeHandler: false);

    public IChatClient Create(ChatSettings s, string? apiKey)
    {
        IChatClient inner = s.Provider switch
        {
            Provider.Mock              => new MockChatClient(),                 // no HttpClient
            Provider.Ollama            => CreateOllama(s),
            Provider.OpenAI
              or Provider.AzureOpenAI
              or Provider.OpenAICompatible => CreateOpenAiFamily(s, apiKey),
            Provider.Anth
Полный SKILL.md на GitHub

Установить Make Wpf Chatclient Factory в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл Make Wpf Chatclient Factory?

Generates a provider-agnostic IChatClient factory that shares one SocketsHttpHandler across LLM SDKs (OpenAI, Ollama, Anthropic, Gemini) and includes a MockChatClient for account-less development. Use when wiring multiple LLM providers behind Microsoft.Extensions.AI in a WPF app. Usage: /wpf-dev-pack:make-wpf-chatclient-factory <Name>

Как установить скилл Make Wpf Chatclient Factory?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл Make Wpf Chatclient Factory запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить Make Wpf Chatclient Factory с