This Documentation is Being Deprecated
This page is being phased out as part of our documentation reorganization.
Click this card to be redirected to the updated version with the most current information.
If you notice any discrepancies or areas needing improvement in the new documentation, please use the “Report an issue” button at the bottom of the page.
Model Providers
Inherit from the__base.model_provider.ModelProvider base class, implement the following endpoint:
Provider Credentials Validation
provider_credential_schema, such as passing in api_key. If validation fails, throw the errors.validate.CredentialsValidateFailedError error.
Note: Predefined models must fully implement this interface, while custom model providers can implement it simply as follows:
Models
Models are divided into 5 different model types, each inheriting from different base classes and requiring implementation of different methods.Common Interfaces
All models must uniformly implement the following 2 methods: Model Credential Validation Similar to provider credential validation, this is specifically for validating individual models.model(string): Model namecredentials(object): Credential information Credential parameters are defined by the provider’s YAML configuration file’sprovider_credential_schemaormodel_credential_schema, such as passing inapi_key. If validation fails, throw theerrors.validate.CredentialsValidateFailedErrorerror.
InvokeConnectionError: Invocation connection errorInvokeServerUnavailableError: Invocation service unavailableInvokeRateLimitError: Invocation rate limit reachedInvokeAuthorizationError: Invocation authentication failedInvokeBadRequestError: Incorrect invocation parameters
InvokeConnectionError and other exceptions.
Large Language Model (LLM)
Inherit from__base.large_language_model.LargeLanguageModel base class, implement the following interfaces:
LLM Invocation
Implement the core method for LLM invocation, supporting both streaming and synchronous returns.model(string): Model namecredentials(object): Credential information Credential parameters are defined by the provider’s YAML configuration file’sprovider_credential_schemaormodel_credential_schema, such as passing inapi_keyprompt_messages(array[PromptMessage]): Prompt list- For Completion-type models, only one UserPromptMessage element needs to be passed
- For Chat-type models, a list of SystemPromptMessage, UserPromptMessage, AssistantPromptMessage, ToolPromptMessage elements needs to be passed according to message type
model_parameters(object): Model parameters defined by the model’s YAML configuration’sparameter_rulestools(array[PromptMessageTool]) [optional]: Tool list, equivalent to function calling functionsstop(array[string]) [optional]: Stop sequences. Model output will stop before the defined stringstream(bool): Whether to stream output, default True. Streaming returns Generator[LLMResultChunk], non-streaming returns LLMResultuser(string) [optional]: Unique user identifier to help providers monitor and detect abuse
- Streaming returns Generator[LLMResultChunk]
- Non-streaming returns LLMResult
Pre-calculate Input Tokens
If the model does not provide a pre-calculate tokens interface, directly return 0.Optional: Get Custom Model Rules
Text Embedding
Inherit from__base.text_embedding_model.TextEmbeddingModel base class, implement the following interfaces:
Embedding Invocation
model(string): Model namecredentials(object): Credential information Credential parameters are defined by the provider’s YAML configuration file’sprovider_credential_schemaormodel_credential_schematexts(array[string]): Text list, can be processed in batchuser(string) [optional]: Unique user identifier to help providers monitor and detect abuse
- TextEmbeddingResult entity
Pre-calculate Tokens
_get_num_tokens_by_gpt2(text: str) method in the AIModel base class.
Rerank
Inherit from__base.rerank_model.RerankModel base class, implement the following interfaces:
Rerank Invocation
model(string): Model namecredentials(object): Credential informationquery(string): Search query contentdocs(array[string]): List of segments to be re-rankedscore_threshold(float) [optional]: Score thresholdtop_n(int) [optional]: Take top n segmentsuser(string) [optional]: Unique user identifier to help providers monitor and detect abuse
- RerankResult entity
Speech2Text
Inherit from__base.speech2text_model.Speech2TextModel base class, implement the following interfaces:
Invoke Invocation
model(string): Model namecredentials(object): Credential informationfile(File): File streamuser(string) [optional]: Unique user identifier to help providers monitor and detect abuse
- Converted text string from speech
Text2Speech
Inherit from__base.text2speech_model.Text2SpeechModel base class, implement the following interfaces:
Invoke Invocation
model(string): Model namecredentials(object): Credential informationcontent_text(string): Text content to be convertedstreaming(bool): Whether to stream outputuser(string) [optional]: Unique user identifier to help providers monitor and detect abuse
- Audio stream converted from text
Moderation
Inherit from__base.moderation_model.ModerationModel base class, implement the following interfaces:
Invoke Invocation
model(string): Model namecredentials(object): Credential informationtext(string): Text contentuser(string) [optional]: Unique user identifier to help providers monitor and detect abuse
- False indicates the input text is safe, True indicates otherwise
Edit this page | Report an issue