Using SmartEndpoint
Overview
The SmartEndpoint
serves as the interface between Wisej.AI and the AI server that hosts the language model. This component is responsible for managing the communication and data exchange with the AI backend. Wisej.AI is designed with broad compatibility in mind and can work with virtually any AI endpoint, enabling seamless integration with various AI models and servers.
How to Use
The easiest way to configure an AI endpoint is by selecting it through the Wisej.AI Wizard, which guides you through the setup process with a user-friendly interface. Alternatively, you can directly instantiate and use any of the available SmartEndpoint
implementations in your code.
var openAI = new OpenAIEndpoint {
ApiKey = "...",
Model = "gpt-41"
};
var prompt = new SmartPrompt("You are a great C# coder");
C.WriteLine(
(await prompt.AskAsync(openAI, "Write a bubble sort method.")).Text);
API Key
There are several ways to set the API key on an endpoint:
ApiKey Property: Directly set the API key using the ApiKey property in your code.
ApiKey.json File: Store the API key in a JSON configuration file named ApiKey.json.
Environment Variables: Set the API key using environment variables for more secure and flexible configuration.
However, when an endpoint is used by a service as a default AI provider, it will need to read its API key either from the ApiKey.json
file or from the environment variables. This is because the service relies on these configurations for default settings. Alternatively, you can re-register the service using an instance of the endpoint created by code and set the ApiKey
property directly.
static Program() {
Application.Services
.AddOrReplaceService<IEmbeddingGenerationService>(
new DefaultEmbeddingGenerationService(new OpenAIEndpoint {ApiKey = "..."}));
}
Model Options
AI models typically support a variety of configuration options that allow you to tailor their behavior. Some options, such as temperature
, are commonly found across many models and have standardized meanings. Others may serve similar purposes but can differ slightly in their naming conventions or implementation details, depending on the specific model or provider. Additionally, certain options may be unique to a particular model, offering specialized features or controls that are not available elsewhere. It is important to consult the documentation for each AI model to understand the available options and how they affect the model's output.
The SmartEndpoint
class exposes a dynamic object called ModelOptions
, which you can use to configure any option supported by the selected AI model. This flexible approach allows you to set both standard and model-specific options without the need for predefined properties, ensuring compatibility with a wide range of models and features. Simply assign the desired configuration values to the ModelOptions
object to customize the behavior of the AI model in your application.
this.opanAIEndpoint1.ModelOptions.temperature = 0.5f;
this.opanAIEndpoint1.ModelOptions.frequency_penalty = 2;
Last updated