Skip to main content

OllamaEndpoint

Namespace: Wisej.AI.Endpoints

Assembly: Wisej.AI

Represents an endpoint that connects to Ollama services, providing functionalities for chat and embeddings.

public class OllamaEndpoint : SmartHttpEndpoint

This class extends the SmartHttpEndpoint to interact with Ollama endpoints. It provides methods to construct API URLs, add options to messages, and handle responses.

Constructors​

OllamaEndpoint()​

Initializes a new instance of the OllamaEndpoint class with default settings.

Properties​

EmbeddingModel​

String: Gets or sets the embedding model used by the endpoint. (Default: "all-minilm")

MaxContextTokens​

Int32: Gets or sets the maximum number of tokens the context window for the specified Model can hold. (Default: 8192)

Methods​

AddOptions(message, session)​

Adds options to the message for the current session.

ParameterTypeDescription
messageObjectThe dynamic message object to which options are added.
sessionSmartSessionThe current session containing model options.

Throws:

AskEmbeddingsAsync(inputs)​

Asynchronously requests embeddings for the specified inputs.

ParameterTypeDescription
inputsString[]An array of input strings for which embeddings are requested.

Returns: Task<Embedding>. A task representing the asynchronous operation, with a result of type Embedding.

Throws:

BuildEmbeddingsPayload(inputs)​

Builds the payload for the embeddings request.

ParameterTypeDescription
inputsString[]An array of input strings for which the payload is built.

Returns: Object. An object representing the payload for the embeddings request.

Throws:

GetApiURL()​

Constructs the API URL for chat interactions.

Returns: String. A string representing the chat API URL.

GetEmbeddingsURL()​

Constructs the API URL for embeddings interactions.

Returns: String. A string representing the embeddings API URL.

ReadAssistantMessage(response, message)​

Reads the assistant's message from the response and updates the message object.

ParameterTypeDescription
responseResponseThe response received from the API.
messageMessageThe message object to be updated with the assistant's response.

Throws:

ReadEmbeddingsResponse(response)​

Reads the embeddings response and extracts the embeddings data.

ParameterTypeDescription
responseResponseThe response received from the API.

Returns: Single[][]. A jagged array of floats representing the embeddings.

Throws:

ReadUsage(message, reply)​

Reads the usage statistics from the reply and updates the message usage.

ParameterTypeDescription
messageMessageThe message object to be updated with usage statistics.
replyObjectThe dynamic reply object containing usage information.