Class: SmartChatModelApiAdapter

SmartChatModelApiAdapter()

Base class for API adapters to handle various chat model platforms.

Constructor

new SmartChatModelApiAdapter()

Source:

Extends

  • SmartChatModelAdapter

Classes

SmartChatModelApiAdapter

Members

api_key

Get the API key.

Source:

choices

Get the number of choices.

Source:

default_model_config

Get the default model configuration.

Source:

endpoint

Get the endpoint URL.

Source:

endpoint_streaming

Get the streaming endpoint URL.

Source:

max_output_tokens

Get the maximum output tokens.

Source:

model_config

Get the model configuration.

Source:

model_key

Get the model key.

Source:

models

Get the models.

Source:

platform

Get the platform object.

Source:

platform_settings

Get the platform settings.

Source:

req_adapter

Get the request adapter class.

Source:

res_adapter

Get the response adapter class.

Source:

temperature

Get the temperature.

Source:

Methods

(async) complete(req) → {Promise.<Object>}

Completes a chat request.

Parameters:
Name Type Description
req Object

The request object.

Source:
Returns:

The completed chat response in OpenAI format.

Type
Promise.<Object>

(async) count_tokens(req)

Count the number of tokens in a given request.

Parameters:
Name Type Description
req Object

The request object.

Source:
Throws:

Throws an error if not implemented in the subclass.

Type
Error

(async) get_models(refreshopt) → {Promise.<Array.<Object>>}

Get the available models from the platform.

Parameters:
Name Type Attributes Default Description
refresh boolean <optional>
false

Whether to refresh the cached models.

Source:
Returns:

An array of model objects.

Type
Promise.<Array.<Object>>

get_text_chunk_from_stream(event) → {string}

Get the text chunk from the stream event.

Parameters:
Name Type Description
event Event

The stream event.

Source:
Returns:

The text chunk.

Type
string

is_end_of_stream(event) → {boolean}

Check if the event indicates the end of the stream.

Parameters:
Name Type Description
event Event

The event object.

Source:
Returns:

True if the event indicates the end of the stream, false otherwise.

Type
boolean

parse_model_data(model_data) → {Array.<Object>}

Parses the raw model data from OpenAI API and transforms it into a more usable format.

Parameters:
Name Type Description
model_data Object

The raw model data received from OpenAI API.

Properties:
Name Type Attributes Description
model_name string

The name/ID of the model as returned by the API.

key string

The key used to identify the model (usually same as model_name).

multimodal boolean

Indicates if the model supports multimodal inputs.

max_input_tokens number <optional>

The maximum number of input tokens the model can process.

description string <optional>

A description of the model's context and output capabilities.

Source:
Returns:

An array of parsed model objects with the following properties:

Type
Array.<Object>

stop_stream()

Stop the active stream.

Source: