__base.model_provider.ModelProvider
基本クラスを継承し、以下のインターフェースを実装する必要があります:
credentials
(object) 資格情報
資格情報のパラメータは、サプライヤーのYAML構成ファイルの provider_credential_schema
で定義され、api_key
などが渡されます。
errors.validate.CredentialsValidateFailedError
エラーをスローします。
注:事前定義されたモデルはこのインターフェースを完全に実装する必要がありますが、カスタムモデルサプライヤーは以下の簡単な実装のみが必要です
model
(string) モデル名
credentials
(object) 資格情報
資格情報のパラメータは、供給業者の YAML 構成ファイルの provider_credential_schema または model_credential_schema で定義されており、api_key などの詳細が含まれます。
errors.validate.CredentialsValidateFailedError
エラーをスローします。
InvokeError
タイプにマッピングする必要があり、異なるエラーに対して異なる後続処理を行うためのDifyにとって便利です。
Runtime Errors:
InvokeConnectionError
コール接続エラーInvokeServerUnavailableError
コールサービスが利用できないInvokeRateLimitError
コールが制限に達したInvokeAuthorizationError
コール認証エラーInvokeBadRequestError
コールパラメータが誤っていますInvokeConnectionError
などの例外を直接スローできます。
_invoke_error_mapping
をご参照ください。
__base.large_language_model.LargeLanguageModel
基本クラスを継承し、以下のインターフェースを実装します:
model
(string) モデル名
credentials
(object) 資格情報
資格情報のパラメータは、供給業者の YAML 構成ファイルの provider_credential_schema または model_credential_schema で定義されており、api_key などの詳細が含まれます。
prompt_messages
(array[PromptMessage]) Prompt リスト
モデルのタイプが Completion
の場合、リストには1つのUserPromptMessage 要素のみを渡す必要があります;
モデルのタイプが Chat
の場合、SystemPromptMessage, UserPromptMessage, AssistantPromptMessage, ToolPromptMessage 要素のリストをメッセージに応じて渡す必要があります。
model_parameters
(object) モデルのパラメータ
モデルのパラメータは、モデルのYAML設定におけるparameter_rules
で定義されています。
tools
(array[PromptMessageTool]) [optional] ツールのリスト,function calling
内の function
に相当します。
つまり、tool calling のためのツールリストを指定します。
stop
(array[string]) [optional] ストップシーケンス
モデルが出力を返す際に、定義された文字列の前で出力を停止します。
stream
(bool) ストリーム出力の有無、デフォルトはTrue
ストリーム出力の場合は Generator[LLMResultChunk],出力ではないの場合は LLMResult。
user
(string) [optional] ユーザーの一意の識別子
供給業者が不正行為を監視および検出するのに役立ちます。
LLMの呼び出し
を参照してください。
このインターフェースは、対応するmodel
に基づいて適切なtokenizer
を選択して計算する必要があります。対応するモデルがtokenizer
を提供していない場合は、AIModel
ベースクラスの_get_num_tokens_by_gpt2(text: str)
メソッドを使用して計算できます。
OpenAI
供給業者の下で、微調整モデル名を使用してベースモデルを取得できます。例えば、gpt-3.5-turbo-1106
のような微調整モデル名を使用して、基本モデルの事前定義されたパラメータルールを取得できます。具体的な実装については、openaiを参照してください。
__base.text_embedding_model.TextEmbeddingModel
ベースクラスを継承し、次のインターフェースを実装します:
model
(string) モデル名
credentials
(object) 資格情報
資格情報のパラメータは、供給業者の YAML 構成ファイルの provider_credential_schema または model_credential_schema で定義されており、api_key などの詳細が含まれます。
texts
(array[string]) テキストリスト,バッチで処理できる
user
(string) [optional] ユーザーの一意の識別子
供給業者が不正行為を監視および検出するのに役立ちます。
Embeddingの呼び出し
を参照してください。
上記のLargeLanguageModel
と同様に、このインターフェースは、対応するmodel
に基づいて適切なtokenizer
を選択して計算する必要があります。対応するモデルがtokenizer
を提供していない場合は、AIModel
ベースクラスの_get_num_tokens_by_gpt2(text: str)
メソッドを使用して計算できます。
model
(string) モデル名
credentials
(object) 資格情報
資格情報のパラメータは、供給業者の YAML 構成ファイルの provider_credential_schema または model_credential_schema で定義されており、api_key などの詳細が含まれます。
query
(string) リクエスト内容をチェックする
docs
(array[string]) 並べ替えが必要なセクションリスト
score_threshold
(float) [optional] Scoreの閾値
top_n
(int) [optional] トップのnセクションを取得します
user
(string) [optional] ユーザーの一意の識別子
供給業者が不正行為を監視および検出するのに役立ちます。
__base.speech2text_model.Speech2TextModel
基底クラスを継承し、以下のインターフェースを実装します:
model
(string) モデル名
credentials
(object) 資格情報
資格情報のパラメータは、供給業者の YAML 構成ファイルの provider_credential_schema または model_credential_schema で定義されており、api_key などの詳細が含まれます。
file
(File) ファイルストリーム
user
(string) [optional] ユーザーの一意の識別子
供給業者が不正行為を監視および検出するのに役立ちます。
__base.text2speech_model.Text2SpeechModel
基底クラスを継承し、以下のインターフェースを実装します:
model
(string) モデル名
credentials
(object) 資格情報
資格情報のパラメータは、供給業者の YAML 構成ファイルの provider_credential_schema または model_credential_schema で定義されており、api_key などの詳細が含まれます。
content_text
(string) 変換すべきテキストコンテンツ
streaming
(bool) ストリーミング出力かどうか
user
(string) [optional] ユーザーの一意の識別子
供給業者が不正行為を監視および検出するのに役立ちます。
__base.moderation_model.ModerationModel
基底クラスを継承し、以下のインターフェースを実装します:
model
(string) モデル名
credentials
(object) 資格情報
資格情報のパラメータは、供給業者の YAML 構成ファイルの provider_credential_schema または model_credential_schema で定義されており、api_key などの詳細が含まれます。
text
(string) テキスト内容
user
(string) [optional] ユーザーの一意の識別子
供給業者が不正行為を監視および検出するのに役立ちます。
TextPromptMessageContent
と ImagePromptMessageContent
をそれぞれ初期化する必要がある。
content
リストの一部としてこのエンティティを構築する必要がある。
content
リストの一部としてこのエンティティを構築する必要がある。
data
には url
または画像の base64
でエンコードされた文字列を指定することができる。
few-shots
やチャット履歴が入力として使用されます。
tool_calls
は、モデルに tools
を渡した後、モデルが返す tool call
のリストです。
content
传入工具执行结果。
delta
エンティティ。
credentials
(object) Credential information
The parameters of credential information are defined by the provider_credential_schema
in the provider’s YAML configuration file. Inputs such as api_key
are included.
errors.validate.CredentialsValidateFailedError
error.
model
(string) Model name
credentials
(object) Credential information
The parameters of credential information are defined by either the provider_credential_schema
or model_credential_schema
in the provider’s YAML configuration file. Inputs such as api_key
are included.
errors.validate.CredentialsValidateFailedError
error.
InvokeError
type specified by Runtime. This facilitates Dify’s ability to handle different errors with appropriate follow-up actions.
Runtime Errors:
InvokeConnectionError
Invocation connection errorInvokeServerUnavailableError
Invocation service provider unavailableInvokeRateLimitError
Invocation reached rate limitInvokeAuthorizationError
Invocation authorization failureInvokeBadRequestError
Invocation parameter error_invoke_error_mapping
for an example.
__base.large_language_model.LargeLanguageModel
base class and implement the following interfaces:
model
(string) Model name
credentials
(object) Credential information
The parameters of credential information are defined by either the provider_credential_schema
or model_credential_schema
in the provider’s YAML configuration file. Inputs such as api_key
are included.
prompt_messages
(array[PromptMessage]) List of prompts
If the model is of the Completion
type, the list only needs to include one UserPromptMessage element;
If the model is of the Chat
type, it requires a list of elements such as SystemPromptMessage, UserPromptMessage, AssistantPromptMessage, ToolPromptMessage depending on the message.
model_parameters
(object) Model parameters
The model parameters are defined by the parameter_rules
in the model’s YAML configuration.
tools
(array[PromptMessageTool]) [optional] List of tools, equivalent to the function
in function calling
.
That is, the tool list for tool calling.
stop
(array[string]) [optional] Stop sequences
The model output will stop before the string defined by the stop sequence.
stream
(bool) Whether to output in a streaming manner, default is True
Streaming output returns Generator[LLMResultChunk], non-streaming output returns LLMResult.
user
(string) [optional] Unique identifier of the user
This can help the provider monitor and detect abusive behavior.
LLM Invocation
.
__base.text_embedding_model.TextEmbeddingModel
base class and implement the following interfaces:
model
(string) Model name
credentials
(object) Credential information
The parameters of credential information are defined by either the provider_credential_schema
or model_credential_schema
in the provider’s YAML configuration file. Inputs such as api_key
are included.
texts
(array[string]) List of texts, capable of batch processing
user
(string) [optional] Unique identifier of the user
This can help the provider monitor and detect abusive behavior.
Embedding Invocation
.
__base.rerank_model.RerankModel
base class and implement the following interfaces:
model
(string) Model name
credentials
(object) Credential information
The parameters of credential information are defined by either the provider_credential_schema
or model_credential_schema
in the provider’s YAML configuration file. Inputs such as api_key
are included.
query
(string) Query request content
docs
(array[string]) List of segments to be reranked
score_threshold
(float) [optional] Score threshold
top_n
(int) [optional] Select the top n segments
user
(string) [optional] Unique identifier of the user
This can help the provider monitor and detect abusive behavior.
__base.speech2text_model.Speech2TextModel
base class and implement the following interfaces:
model
(string) Model name
credentials
(object) Credential information
The parameters of credential information are defined by either the provider_credential_schema
or model_credential_schema
in the provider’s YAML configuration file. Inputs such as api_key
are included.
file
(File) File stream
user
(string) [optional] Unique identifier of the user
This can help the provider monitor and detect abusive behavior.
__base.text2speech_model.Text2SpeechModel
base class and implement the following interfaces:
model
(string) Model name
credentials
(object) Credential information
The parameters of credential information are defined by either the provider_credential_schema
or model_credential_schema
in the provider’s YAML configuration file. Inputs such as api_key
are included.
content_text
(string) The text content that needs to be converted
streaming
(bool) Whether to stream output
user
(string) [optional] Unique identifier of the user
This can help the provider monitor and detect abusive behavior.
__base.moderation_model.ModerationModel
base class and implement the following interfaces:
model
(string) Model name
credentials
(object) Credential information
The parameters of credential information are defined by either the provider_credential_schema
or model_credential_schema
in the provider’s YAML configuration file. Inputs such as api_key
are included.
text
(string) Text content
user
(string) [optional] Unique identifier of the user
This can help the provider monitor and detect abusive behavior.
TextPromptMessageContent
and ImagePromptMessageContent
separately for input.
content
list.
content
list.
data
can be either a url
or a base64
encoded string of the image.
few-shots
or inputting chat history.
tool_calls
are the list of tool calls
returned by the model after invoking the model with the tools
input.
content
takes in the results of tool execution.
delta
entity.