OpenAIEndpoint
Namespace: Wisej.AI.Endpoints
Assembly: Wisej.AI
Represents an endpoint for connecting to OpenAI services.
- C#
- VB.NET
public class OpenAIEndpoint : SmartHttpEndpoint
Public Class OpenAIEndpoint
Inherits SmartHttpEndpoint
This class is used to interact with OpenAI's API, providing methods to send requests and process responses for both chat completions and embeddings.
Constructors
OpenAIEndpoint()
Initializes a new instance of the OpenAIEndpoint class with default settings.
The default authentication is set to "Bearer".
Properties
EmbeddingModel
String: Gets or sets the model used for embeddings. (Default: "text-embedding-3-small")
Model
String: Gets or sets the model used for chat completions. (Default: "gpt-4o")
URL
String: Gets or sets the base URL for the OpenAI API. (Default: "https://api.openai.com/v1")
UseNativeTools
Boolean: (Default: True)
Methods
AddOptions(message, session)
Adds options to the message for the API request.
| Parameter | Type | Description |
|---|---|---|
| message | Object | The message to be sent to the API. |
| session | SmartSession | The current session context. |
Sets the temperature to 0.0 and max tokens to the value of MaxOutputTokens.
BuildEmbeddingsPayload(inputs)
Builds the payload for an embeddings request.
| Parameter | Type | Description |
|---|---|---|
| inputs | String[] | The input strings to be embedded. |
Returns: Object. The constructed payload for the embeddings request.
Throws:
- ArgumentNullException Thrown when the inputs are null.
BuildMessage(message)
Builds the message payload for the API request.
| Parameter | Type | Description |
|---|---|---|
| message | Message | The message object containing the content to be sent. |
Returns: Object. The constructed message payload.
Throws:
- ArgumentNullException Thrown when the message is null.
GetApiURL()
Constructs the API URL for chat completions.
Returns: String. The full API URL for chat completions.
GetEmbeddingsURL()
Constructs the API URL for embeddings.
Returns: String. The full API URL for embeddings.
ReadEmbeddingsResponse(response)
Reads the embeddings from the API response.
| Parameter | Type | Description |
|---|---|---|
| response | Response | The response received from the API. |
Returns: Single[][]. An array of float arrays representing the embeddings.
Throws:
- ArgumentNullException Thrown when the response is null.
Inherited By
| Name | Description |
|---|---|
| CerebrasEndpoint | Represents a connection to Cerebras endpoints, inheriting from OpenAIEndpoint. |
| DeepSeekEndpoint | Represents a connection to DeepSeek endpoints, inheriting from OpenAIEndpoint. |
| GroqCloudEndpoint | https://console.groq.com/docs/openai |
| HuggingFaceEndpoint | Represents a connection to HuggingFace serverless endpoints for model inference and embeddings. |
| LocalAIEndpoint | Represents a connection to LocalAI endpoints, providing access to various AI models and services. |
| NvidiaAIEndpoint | Represents a connection to NVIDIA AI endpoints, providing access to various AI models and services. |
| SambaNovaEndpoint | Represents a connection to SambaNova endpoints, inheriting from OpenAIEndpoint. |
| TogetherAIEndpoint | Represents a connection to TogetherAI endpoints, providing access to various AI models and services. |
| XAIEndpoint | Represents a connection to X.AI endpoints, extending the functionality of OpenAIEndpoint. |