AssistantModel Class

Assembly: CodeEffects.Rule.Repository.dll
Namespace: CodeEffects.Rule.Repository

Summary

Represents one large language model that you register for the AI Assistant and the AI Rule Editor: its key, its connection, and the limits and prices that belong to it.

Syntax

public class AssistantModel

Remarks

Add one instance to Models of AssistantSettings for each model that users may pick from. You build the connection yourself, with your vendor's own package (Anthropic's, OpenAI's, Azure's, or any other that implements Microsoft.Extensions.AI.IChatClient), and assign it to ChatClient. The repository references no vendor.

Key and ChatClient are required. Every other property is optional.

Constructors

  • AssistantModel()

    Initializes a new instance of the AssistantModel class with the default values of all properties.

Properties

  • CacheWritePricePerMillion

    Type: System.Nullable<System.Decimal>

    Gets or sets the price of a million input tokens that the vendor writes to its prompt cache, for vendors that bill them apart (Anthropic bills them above the input price). When it is null, those tokens are priced at InputPricePerMillion. The default value is null.

  • CachedInputPricePerMillion

    Type: System.Nullable<System.Decimal>

    Gets or sets the price of a million input tokens that the vendor reads from its prompt cache, which is a fraction of the input price (see your vendor's price list). When it is null, cached tokens are priced at InputPricePerMillion, so the cost shown is too high when the vendor caches. The default value is null.

  • ChatClient

    Type: Microsoft.Extensions.AI.IChatClient

    Gets or sets the connection to the model, which you build with your vendor's package. Required: a model without it is refused.

  • ContextBudget

    Type: System.Int32

    Gets or sets the most characters of a conversation that are sent to the model in one call, at roughly four characters to a token. Beyond it, the oldest tool answers are left out, and the model may call the tool again. The words of the person and of the model are always sent. The default value is 400000, which suits models with a context of 128,000 tokens or more. Lower it for a smaller model.

  • DisplayName

    Type: System.String

    Gets or sets the name that the model picker shows, for example "Claude Sonnet". When it is empty, the picker shows Key. The default value is null.

  • InputPricePerMillion

    Type: System.Nullable<System.Decimal>

    Gets or sets the vendor's price of a million input tokens, in your currency, taken from the vendor's price list or your contract: no vendor's API reports it. Together with OutputPricePerMillion it lets the Usage tab show costs to users who hold the AiConversationViewAll permission. When either price is null, no cost is shown. The default value is null.

  • Key

    Type: System.String

    Gets or sets the model's key. Required. The repository stores it with every message that the model writes, so keep it stable across releases of your application. It may contain letters, digits, dot, dash, and underscore, and be at most 128 characters long. Keys are compared without regard to case, and two models in one Models list cannot share a key.

  • MaxOutputTokens

    Type: System.Nullable<System.Int32>

    Gets or sets the most tokens that one answer of the model may have. It is sent as MaxOutputTokens of the chat options. Some vendors require a value, and all accept the default. The default value is 8192.

  • ModelId

    Type: System.String

    Gets or sets the model ID that is sent with every call. When it is null or empty, the call leaves the choice to the ChatClient, which usually has an ID of its own. The default value is null.

  • OutputPricePerMillion

    Type: System.Nullable<System.Decimal>

    Gets or sets the price of a million output tokens. See InputPricePerMillion. The default value is null.

  • PromptCache

    Type: System.Boolean

    Gets or sets whether the repository asks the vendor to cache the prompt, where the vendor needs to be asked. Today that is Anthropic's, which the repository recognizes from the metadata of the ChatClient. A cached prompt is billed at a fraction of the input price and gives the same answer. Vendors that cache by themselves, such as OpenAI, are not affected. The default value is true.

  • ReadsFiles

    Type: System.Collections.Generic.ISet<System.String>

    Gets or sets the content types that the model takes as files, for example application/pdf. What a model reads depends on its vendor and on the API that the ChatClient uses, and no API reports it, so you say it. The default is a case-insensitive set of DefaultFileTypes.

    Remarks

    Plain text files (text/plain, text/markdown, text/csv, application/json, application/xml, and text/xml) are always sent as text and need not be listed. A file of any other type that the selected model does not read is not sent, and the conversation shows a warning that names the registered models that do read it.

Static Fields

  • DefaultFileTypes

    Type: System.Collections.Generic.IReadOnlyCollection<System.String>

    The content types that every major vendor reads as files: application/pdf, image/png, image/jpeg, image/gif, and image/webp.

    Example

      using System;
      using System.Collections.Generic;
      using CodeEffects.Rule.Repository;
      using Microsoft.Extensions.AI;
    
      var model = new AssistantModel
      {
      	Key = "claude.sonnet",
      	ChatClient = chatClient, // the IChatClient you built with your vendor's package
      	ModelId = "my-model-id",
      	InputPricePerMillion = 3m,
      	OutputPricePerMillion = 15m,
      	ReadsFiles = new HashSet<string>(AssistantModel.DefaultFileTypes, StringComparer.OrdinalIgnoreCase) { "text/html" }
      };
    

Ask on Stack Overflow - Yes, it's still active
Ask in GitHub Discussions

p102

l097 --

l102

p101

×