SmartHttpEndpoint

Wisej.AI.Endpoints.SmartHttpEndpoint

Namespace: Wisej.AI.Endpoints

Assembly: Wisej.AI (3.5.0.0)

Represents an abstract base class for a smart HTTP endpoint, providing common functionality for HTTP-based communication.

public class SmartHttpEndpoint : SmartEndpoint

This class is designed to facilitate communication with HTTP endpoints by managing authentication, headers, and retry logic. It provides methods for sending requests and handling responses, including error detection and retry mechanisms.

Constructors

SmartHttpEndpoint()

Initializes a new instance of the SmartHttpEndpoint class.

Properties

ApiKey

String: Gets or sets the API key used for authentication. (Default: null)

Authentication

String: Gets or sets the authentication scheme used for requests. (Default: "Bearer")

Headers

NameValueCollection: Gets or sets the collection of additional headers to be included in requests.

MaxRetries

Int32: Gets or sets the maximum number of retry attempts for failed requests. (Default: 10)

RetryDelay

Int32: Gets or sets the delay between retry attempts in milliseconds. (Default: 10000)

URL

String: Gets or sets the base URL of the endpoint. (Default: null)

The URL should not end with a trailing slash. If a trailing slash is present, it will be removed.

Methods

AskAsync(session, messages)

Asynchronously sends a request to the endpoint and returns the response message.

Parameter
Type
Description

session

The session managing the AI interaction.

messages

The list of messages to be sent.

Returns: Task<Message>. A task representing the asynchronous operation, with a Message as the result.

The implementation of this method should call session.Usage.Add(assistantMessage.Usage) to keep track of the input and output tokens utilized at the session level.

**Throws:** * [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) Thrown when *session* or *messages* is null.

AskEmbeddingsAsync(inputs)

Asynchronously requests embeddings for the specified inputs.

Parameter
Type
Description

inputs

The array of input strings for which embeddings are requested.

Returns: Task<Embedding>. A task representing the asynchronous operation, with an Embedding as the result.

This method sends the inputs to the embeddings endpoint and returns the resulting embeddings.Throws:

BuildPayload(session, messages)

Builds the payload for the request.

Parameter
Type
Description

session

The session managing the AI interaction.

messages

The list of messages to be included in the payload.

Returns: Object. The constructed payload object.

Throws:

CreateContent(data)

Creates the HTTP content from the given data.

Parameter
Type
Description

data

The data to be serialized into the content.

Returns: HttpContent. The created HttpContent.

DetectContextLimitExceeded(response)

Detects if the context limit has been exceeded in the response.

Parameter
Type
Description

response

The HTTP response message.

Returns: Boolean. true if the context limit is exceeded; otherwise, false.

DetectRateLimitExceeded(response)

Detects if the rate limit has been exceeded in the response.

Parameter
Type
Description

response

The HTTP response message.

Returns: Boolean. true if the rate limit is exceeded; otherwise, false.

GetApiKey()

Gets the API key for the endpoint.

Returns: String. The API key as a string.

GetApiURL()

Gets the API URL for the endpoint.

Returns: String. The API URL as a string.

GetEmbeddingsURL()

Gets the URL for embeddings.

Returns: String. The embeddings URL as a string.

Throws:

PostAsync(url, data)

Asynchronously sends a POST request to the specified URL with the given data.

Parameter
Type
Description

url

The URL to send the request to.

data

The data to be sent in the request body.

Returns: Task<Response>. A task representing the asynchronous operation, with a Response as the result.

This method handles retries and error detection, including token and rate limit exceeded exceptions.Throws:

ReadAssistantMessage(response, message)

Reads the assistant's message from the API response.

Parameter
Type
Description

response

The response received from the API.

message

The message object to populate with the response content.

Throws:

ReadUsage(message, reply)

Reads the usage statistics from the API response.

Parameter
Type
Description

message

The message object to update with usage data.

reply

The dynamic object containing the API response data.

Inherited By

Name
Description

Represents an endpoint for connecting to Amazon Bedrock services.

Represents an endpoint for connecting to Anthropic services.

Represents an endpoint for connecting to Azure AI services, specifically designed to interact with OpenAI models.

Represents a connection to Cerebras endpoints, inheriting from OpenAIEndpoint.

Represents a connection to DeepSeek endpoints, inheriting from OpenAIEndpoint.

Represents a connection to Google AI endpoints for generating content and embeddings.

https://console.groq.com/docs/openai

Represents a connection to GroqCloud speech endpoints for audio transcription.

Represents a connection to HuggingFace serverless endpoints for model inference and embeddings.

Represents a connection to LocalAI endpoints, providing access to various AI models and services.

Represents an endpoint for connecting to LocalAI Image Generation services.

Represents an endpoint for connecting to LocalAI's speech services.

Represents an endpoint for connecting to LocalAI's Whisper model for speech-to-text transcriptions.

Represents a connection to NVIDIA AI endpoints, providing access to various AI models and services.

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

Represents an endpoint for connecting to OpenAI services.

Represents an endpoint for connecting to OpenAI DallE services.

Represents a component that manages communication with OpenAI's real-time API endpoints.

Represents an endpoint for connecting to OpenAI's speech services.

Represents an endpoint for connecting to OpenAI's Whisper model for speech-to-text transcriptions.

Represents a connection to SambaNova endpoints, inheriting from OpenAIEndpoint.

Represents a connection to TogetherAI endpoints, providing access to various AI models and services.

Represents a connection to X.AI endpoints, extending the functionality of OpenAIEndpoint.

Last updated