### Install Python Dependencies (Bash) Source: https://github.com/fasuizu-br/dify-brainiall-plugin/blob/main/GUIDE.md This command installs all Python dependencies listed in the `requirements.txt` file. Ensure you have Python 3.11+ installed. ```bash pip install -r requirements.txt ``` -------------------------------- ### Initialize and Run Dify Plugin Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt This Python script demonstrates the entry point for the Dify Brainiall plugin. It initializes the Plugin class with custom request timeout settings and then runs the plugin. This is essential for starting the plugin's operations within the Dify environment. ```python # Plugin entry point (main.py) from dify_plugin import Plugin, DifyPluginEnv plugin = Plugin(DifyPluginEnv(MAX_REQUEST_TIMEOUT=120)) if __name__ == "__main__": plugin.run() ``` -------------------------------- ### Credential Validation and Usage Example for Brainiall Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt This Python code snippet shows how to validate credentials for a specific model using the Brainiall provider. It includes a usage example demonstrating the expected structure for the credentials dictionary, which requires a 'brainiall_api_key' and 'mode'. ```python # Validate credentials for a specific model def validate_credentials(self, model: str, credentials: dict) -> None: self._add_custom_parameters(credentials) super().validate_credentials(model, credentials) # Usage example - credentials structure credentials = { "brainiall_api_key": "your-api-key-here", "mode": "chat", } ``` -------------------------------- ### Interact with Brainiall API using cURL Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt This example shows how to make a direct API call to the Brainiall service using cURL. It demonstrates sending a chat completion request with specific model parameters, messages, and authentication details. The `stream: true` option indicates that the response should be streamed. ```bash # Direct API call using curl curl -X POST "https://apim-ai-apis.azure-api.net/v1/chat/completions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_BRAINIALL_API_KEY" \ -d '{ "model": "claude-sonnet-4-6", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello, how are you?"} ], "temperature": 0.7, "max_tokens": 4096, "stream": true }' ``` -------------------------------- ### Dify Plugin Manifest Structure (YAML) Source: https://github.com/fasuizu-br/dify-brainiall-plugin/blob/main/GUIDE.md The `manifest.yaml` file describes a Dify plugin's metadata, type, author, resources, and extensions. It's crucial for defining the plugin's capabilities and how it integrates with Dify. ```yaml version: "1.0.0" type: "plugin" author: "Your Organization" label: en: "My Awesome Plugin" zh: "我的超棒插件" created_at: "2023-10-27T10:00:00Z" icon: "icon.png" resource: memory: 512 permission: tool: enabled: true model: enabled: true llm: true text_embedding: true rerank: true tts: true speech2text: true moderation: true node: enabled: true endpoint: enabled: true app: enabled: true storage: enabled: true size: 1073741824 plugins: tools: [] models: [] endpoints: [] meta: version: "0.0.1" arch: ["amd64", "arm64"] runner: language: "python" version: "3.12" entrypoint: "main" ``` -------------------------------- ### Configure DeepSeek R1 Model (YAML) Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt Specifies the configuration for the DeepSeek R1 model, detailing its identifier, display label, model type, supported features, operational mode, context size, parameter rules, and pricing details. This setup is for reasoning and general tasks. ```yaml # DeepSeek R1 configuration (models/llm/deepseek-r1.yaml) model: deepseek-r1 label: en_US: DeepSeek R1 model_type: llm features: - agent-thought model_properties: mode: chat context_size: 128000 parameter_rules: - name: temperature use_template: temperature - name: top_p use_template: top_p - name: max_tokens use_template: max_tokens default: 4096 min: 1 max: 64000 pricing: input: "1.35" output: "5.40" unit: "0.000001" currency: USD ``` -------------------------------- ### Plugin Entry Point Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt Initialize and run the Dify plugin with custom timeout settings. ```APIDOC ## Plugin Entry Point ### Description Initialize and run the Dify plugin with custom timeout settings. ### Method N/A (Script Execution) ### Endpoint N/A (Script Execution) ### Code Example ```python # Plugin entry point (main.py) from dify_plugin import Plugin, DifyPluginEnv plugin = Plugin(DifyPluginEnv(MAX_REQUEST_TIMEOUT=120)) if __name__ == "__main__": plugin.run() ``` ``` -------------------------------- ### Available Models Reference Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt Reference table for available models, including their context size and pricing information. ```APIDOC ## Available Models Reference ### Description Reference table for available models, including their context size and pricing information. ### Models | Model | Context Size | Input/Output Pricing ($/MTok) | |-------|-------------|-------------------------------| | claude-opus-4-6 | 200K | $5 / $25 | | claude-sonnet-4-6 | 200K | $3 / $15 | | claude-haiku-4-5 | 200K | $1 / $5 | | claude-opus-4-5 | 200K | $15 / $75 | | deepseek-r1 | 128K | $1.35 / $5.40 | | deepseek-v3 | 128K | $0.27 / $1.10 | | llama-3.3-70b | 128K | $0.72 / $0.72 | | llama-4-scout-17b | 512K | $0.17 / $0.17 | | qwen-3-235b | 128K | $0.80 / $2.40 | | mistral-large-3 | 128K | $2 / $6 | | nova-pro | 300K | $0.80 / $3.20 | | nova-micro | 128K | $0.035 / $0.14 | ``` -------------------------------- ### Define Provider Schema (YAML) Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt This YAML configuration outlines the structure for defining a provider within the system. It includes specifications for credential forms and references to the models that the provider supports, enabling the system to manage and utilize various AI services. ```yaml # Provider YAML Configuration # Define the provider schema with credential forms and model references. ``` -------------------------------- ### Generate Customizable LLM Model Schema (Python) Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt Defines a Python function to dynamically create an AIModelEntity for customizable LLM models. It configures features like tool calling based on credentials and sets parameters such as context size, mode, temperature, max tokens, and top_p. This function is essential for integrating flexible LLM models into the system. ```python from dify_plugin.entities.model import ( AIModelEntity, FetchFrom, I18nObject, ModelFeature, ModelPropertyKey, ModelType, ParameterRule, ParameterType, ) from dify_plugin.entities.model.llm import LLMMode def get_customizable_model_schema( self, model: str, credentials: dict ) -> Optional[AIModelEntity]: return AIModelEntity( model=model, label=I18nObject(en_US=model, zh_Hans=model), model_type=ModelType.LLM, features=( [ ModelFeature.TOOL_CALL, ModelFeature.MULTI_TOOL_CALL, ModelFeature.STREAM_TOOL_CALL, ] if credentials.get("function_calling_type") == "tool_call" else [] ), fetch_from=FetchFrom.CUSTOMIZABLE_MODEL, model_properties={ ModelPropertyKey.CONTEXT_SIZE: int(credentials.get("context_size", 8000)), ModelPropertyKey.MODE: LLMMode.CHAT.value, }, parameter_rules=[ ParameterRule( name="temperature", use_template="temperature", label=I18nObject(en_US="Temperature", zh_Hans="温度"), type=ParameterType.FLOAT, ), ParameterRule( name="max_tokens", use_template="max_tokens", default=4096, min=1, max=int(credentials.get("max_tokens", 16384)), label=I18nObject(en_US="Max Tokens", zh_Hans="最大标记"), type=ParameterType.INT, ), ParameterRule( name="top_p", use_template="top_p", label=I18nObject(en_US="Top P", zh_Hans="Top P"), type=ParameterType.FLOAT, ), ], ) ``` -------------------------------- ### Provider Configuration Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt Configuration details for the Brainiall provider, including supported model types, configuration methods, and schema for model and provider credentials. ```APIDOC ## Provider Configuration (provider/brainiall.yaml) ### Provider Details - **Provider**: `brainiall` - **Label**: `Brainiall` (en_US) - **Supported Model Types**: `llm` - **Configuration Methods**: `predefined-model`, `customizable-model` ### Model Credential Schema - **Model Name**: - Label: `Model Name` (en_US) - Placeholder: `Enter your model name` (en_US) - **Credential Form Schemas**: - **`brainiall_api_key`**: - Label: `API Key` (en_US) - Type: `secret-input` - Required: `true` - **`context_size`**: - Label: `Model context size` (en_US) - Default: `4096` - Required: `true` - Type: `text-input` - **`max_tokens`**: - Label: `Upper bound for max tokens` (en_US) - Default: `4096` - Type: `text-input` - **`function_calling_type`**: - Label: `Function calling` (en_US) - Default: `no_call` - Type: `select` - Options: - Label: `Not Support` (en_US), Value: `no_call` - Label: `Support` (en_US), Value: `tool_call` ### Provider Credential Schema - **Credential Form Schemas**: - **`brainiall_api_key`**: - Label: `API Key` (en_US) - Type: `secret-input` - Required: `true` ``` -------------------------------- ### OpenAI-Compatible API Usage Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt Access models through the standard OpenAI API format using cURL for direct API calls. ```APIDOC ## OpenAI-Compatible API Usage ### Description Access models through the standard OpenAI API format. ### Method `POST` ### Endpoint `https://apim-ai-apis.azure-api.net/v1/chat/completions` ### Parameters #### Headers - **Content-Type** (`string`): `application/json` - **Authorization** (`string`): `Bearer YOUR_BRAINIALL_API_KEY` #### Request Body - **model** (`string`): The name of the model to use (e.g., `claude-sonnet-4-6`). - **messages** (`array`): An array of message objects representing the conversation history. - **role** (`string`): The role of the message sender (`system`, `user`, `assistant`). - **content** (`string`): The content of the message. - **temperature** (`number`, optional): Controls randomness. Lower values make output more focused and deterministic. - **max_tokens** (`integer`, optional): The maximum number of tokens to generate in the completion. - **stream** (`boolean`, optional): Whether to stream back partial message deltas as they are generated. ### Request Example ```bash curl -X POST "https://apim-ai-apis.azure-api.net/v1/chat/completions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_BRAINIALL_API_KEY" \ -d '{ "model": "claude-sonnet-4-6", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello, how are you?"} ], "temperature": 0.7, "max_tokens": 4096, "stream": true }' ``` ### Response #### Success Response (200) - **id** (`string`): Unique identifier for the completion. - **object** (`string`): Type of object returned (e.g., `chat.completion`). - **created** (`integer`): Unix timestamp of creation. - **model** (`string`): The model used for the completion. - **choices** (`array`): A list of completion choices. - **index** (`integer`): Index of the choice. - **message** (`object`): - **role** (`string`): Role of the message sender. - **content** (`string`): The content of the message. - **finish_reason** (`string`): The reason the model stopped generating tokens. - **usage** (`object`): - **prompt_tokens** (`integer`): Number of tokens in the prompt. - **completion_tokens** (`integer`): Number of tokens in the completion. - **total_tokens** (`integer`): Total tokens used. #### Response Example ```json { "id": "chatcmpl-12345", "object": "chat.completion", "created": 1677652288, "model": "claude-sonnet-4-6", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "I am doing well, thank you! How can I help you today?" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30 } } ``` ``` -------------------------------- ### Configure Llama 4 Scout 17B Model with Vision (YAML) Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt This YAML configuration defines the Llama 4 Scout 17B model, highlighting its multimodal vision capabilities. It includes settings for its label, type, features, context size, parameter rules for temperature and max tokens, and associated pricing information. ```yaml # Llama 4 Scout with vision (models/llm/llama-4-scout-17b.yaml) model: llama-4-scout-17b label: en_US: Llama 4 Scout 17B model_type: llm features: - agent-thought - vision model_properties: mode: chat context_size: 512000 parameter_rules: - name: temperature use_template: temperature - name: max_tokens default: 4096 min: 1 max: 8192 pricing: input: "0.17" output: "0.17" unit: "0.000001" currency: USD ``` -------------------------------- ### Configure Brainiall Provider Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt This YAML configuration defines the Brainiall provider for Dify, specifying supported model types, configuration methods, and schemas for both model and provider credentials. It includes fields for API keys, context size, max tokens, and function calling support. ```yaml provider: brainiall label: en_US: Brainiall supported_model_types: - llm configurate_methods: - predefined-model - customizable-model model_credential_schema: model: label: en_US: Model Name placeholder: en_US: Enter your model name credential_form_schemas: - variable: brainiall_api_key label: en_US: API Key type: secret-input required: true - variable: context_size default: "4096" label: en_US: Model context size required: true type: text-input - variable: max_tokens default: "4096" label: en_US: Upper bound for max tokens type: text-input - variable: function_calling_type default: no_call label: en_US: Function calling options: - label: en_US: Not Support value: no_call - label: en_US: Support value: tool_call type: select provider_credential_schema: credential_form_schemas: - variable: brainiall_api_key label: en_US: API Key type: secret-input required: true ``` -------------------------------- ### Validate Brainiall Provider Credentials in Python Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt This Python code snippet demonstrates how to validate Brainiall provider credentials within a Dify plugin. It uses the ModelProvider class and raises a CredentialsValidateFailedError if the API key or other required parameters are missing or invalid. ```python from dify_plugin import ModelProvider from dify_plugin.errors.model import CredentialsValidateFailedError from typing import Mapping class BrainiallModelProvider(ModelProvider): def validate_provider_credentials(self, credentials: Mapping) -> None: """ Validate provider credentials. If validation fails, raise CredentialsValidateFailedError. """ try: model_instance = self.get_model_instance("llm") model_instance.validate_credentials( model="deepseek-v3", credentials={ "brainiall_api_key": credentials["brainiall_api_key"], "mode": "chat", }, ) except CredentialsValidateFailedError as ex: raise ex ``` -------------------------------- ### Configure Claude Sonnet 4.6 Model (YAML) Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt Defines the configuration for the Claude Sonnet 4.6 model, including its label, type, features (vision support), model properties (context size, mode), parameter rules, and pricing. This YAML file enables the integration and specific usage of this model. ```yaml # Example: Claude Sonnet 4.6 with vision support (models/llm/claude-sonnet-4-6.yaml) model: claude-sonnet-4-6 label: en_US: Claude Sonnet 4.6 model_type: llm features: - agent-thought - vision model_properties: mode: chat context_size: 200000 parameter_rules: - name: temperature use_template: temperature - name: top_p use_template: top_p - name: max_tokens use_template: max_tokens default: 4096 min: 1 max: 64000 - name: response_format use_template: response_format pricing: input: "3.0" output: "15.0" unit: "0.000001" currency: USD ``` -------------------------------- ### Invoke LLM Models with Brainiall Gateway in Python Source: https://context7.com/fasuizu-br/dify-brainiall-plugin/llms.txt This Python code defines a BrainiallLargeLanguageModel class that inherits from OAICompatLargeLanguageModel. It customizes the invocation process by adding specific Brainiall parameters like API key, mode, and endpoint URL before calling the parent class's _invoke method, enabling streaming and function calling support. ```python from dify_plugin import OAICompatLargeLanguageModel from dify_plugin.entities.model.llm import LLMResult from dify_plugin.entities.model.message import PromptMessage, PromptMessageTool from typing import Union, Generator, Optional BRAINIALL_ENDPOINT_URL = "https://apim-ai-apis.azure-api.net/v1" class BrainiallLargeLanguageModel(OAICompatLargeLanguageModel): def _invoke( self, model: str, credentials: dict, prompt_messages: list[PromptMessage], model_parameters: dict, tools: Optional[list[PromptMessageTool]] = None, stop: Optional[list[str]] = None, stream: bool = True, user: Optional[str] = None, ) -> Union[LLMResult, Generator]: self._add_custom_parameters(credentials) return super()._invoke( model, credentials, prompt_messages, model_parameters, tools, stop, stream ) @classmethod def _add_custom_parameters(cls, credentials: dict) -> None: credentials["api_key"] = credentials.get( "brainiall_api_key", credentials.get("api_key", "") ) credentials["mode"] = "chat" credentials["endpoint_url"] = BRAINIALL_ENDPOINT_URL ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.