Files
dify-docs/plugin-dev-en/0211-getting-started-new-model.mdx
2025-07-16 16:42:34 +08:00

130 lines
9.1 KiB
Plaintext

---
dimensions:
type:
primary: implementation
detail: basic
level: beginner
standard_title: Getting Started New Model
language: en
title: Quick Integration of a New Model
description: This document guides non-professional developers on how to add new models
to Dify, focusing on adding new model versions to existing model providers by modifying
configuration files. Includes the complete process of forking the repository, copying
and modifying model configurations, updating provider version, local testing, and
submitting contributions.
---
Welcome to the world of Dify plugin development! Dify's powerful functionality depends on the collective efforts of community contributors. We believe that even if you're not a professional programmer, as long as you're passionate about AI technology and willing to research information, you can contribute to Dify—for example, by helping Dify support more and newer AI models.
This article will guide you, in the simplest way possible, through completing the most common and straightforward contribution: adding a **new model version** to a model provider that Dify **already supports**. This approach typically **only requires modifying configuration files**, without writing code, making it perfect for your first contribution!
> **Related Concepts**: Before starting, we recommend reading the [Model Plugin](/plugin-dev-en/0411-model-plugin-introduction) documentation to understand the basic concepts and structure of model plugins.
**This quick integration method is suitable for:**
- New models that belong to providers already supported by Dify plugins (such as OpenAI, Google Gemini, Anthropic Claude, etc.).
- New models that use the same API authentication and base calling logic as other models in the same series.
- Models that primarily differ in model ID, context length, maximum token count, pricing, and other configuration parameters.
_(If the model you need to add requires new API logic or supports special functionality, it will involve Python code writing. Please refer to [Creating a New Model Provider](/plugin-dev-en/0222-creating-new-model-provider) for more detailed guidance.)_
**Preparation:**
- Familiarity with basic Git operations (Fork, Clone, Pull Request).
- A GitHub account.
- Installing and configuring the Dify plugin development toolkit (refer to [Initializing Development Tools](/plugin-dev-en/0221-initialize-development-tools)).
**Steps:**
1. **Fork & Clone the Official Plugin Repository:**
- Visit the Dify official plugin repository `https://github.com/langgenius/dify-official-plugins`.
- Click the "Fork" button to fork the repository to your own GitHub account.
- Use Git to clone your forked repository to your local computer.
2. **Find and Copy the Model Configuration File:**
- In your local repository, navigate to the `models/` directory, find the provider folder for the model you want to add, for example `vertex_ai`.
- Enter the corresponding model type subdirectory for that provider, usually `models/llm/` (if it's a text generation model).
- In that directory, find a YAML configuration file for an existing model that is most similar to the new version you want to add (for example, `gemini-1.0-pro-001.yaml`).
- Copy this YAML file and rename it to clearly identify the new version (for example, `gemini-1.5-pro-latest.yaml`).
3. **Modify the Model Configuration (YAML):**
- Open the YAML file you just renamed (e.g., `gemini-1.5-pro-latest.yaml`).
- **Core Step:** Refer to the **model provider's official documentation**, carefully verify and modify the following key information in the file:
- `model`: **Must** be updated to the official API identifier for the new version.
- `label`: **Must** be updated to the model name displayed to users in the Dify interface (recommend providing both `en_US` and `zh_Hans` languages).
- `model_properties`: Update `context_size` (context window size).
- `parameter_rules`: Check and update model parameter limitations, especially the `default`, `min`, and `max` values for `max_tokens` (maximum output token count).
- `pricing`: Update the model's `input` and `output` pricing, as well as the `unit` (typically `0.000001` representing per million tokens) and `currency`.
- _(Reference)_ For detailed specifications of all fields in the model YAML file, please consult [Model Design Rules](/plugin-dev-en/0411-model-designing-rules) and [Model Schema Definition](/plugin-dev-en/0412-model-schema).
**Example (Adding Gemini 1.5 Pro):**
| Parameter | Old Model (Example) | New Gemini 1.5 Pro (Example) | Notes |
| :---------------- | :------------------- | :--------------------------- | :----------------------------------- |
| `model` | `gemini-1.0-pro-001` | `gemini-1.5-pro-latest` | **Must** change to official model ID |
| `label: en_US` | Gemini 1.0 Pro | Gemini 1.5 Pro | **Must** change user-visible label |
| `context_size` | 30720 | 1048576 | **Must** change per official docs |
| `max_tokens` (below) | 2048 | 8192 | **Must** change default/max values |
4. **Update the Provider Manifest Version:**
- Return to the root directory of the model provider (e.g., `models/vertex_ai/`).
- Find and open the `manifest.yaml` file.
- Increment the `version` field by a minor version number (e.g., `version: 0.0.8` -> `version: 0.0.9`). This tells Dify that this is an update.
5. **Package and Local Testing:**
- Open your terminal (command line tool).
- **Make sure your current directory is the root of the `dify-official-plugins` repository** (the directory containing folders like `models`, `tools`, etc.).
- Run the packaging command:
```bash
# Replace <provider_name> with the actual provider directory name, such as cohere or vertex_ai
dify plugin package models/<provider_name>
```
- _After success, you'll see a prompt like `plugin packaged successfully, output path: <provider_name>.difypkg`, and a plugin package file named `<provider_name>.difypkg` will be generated in the current project root directory._
- Log in to your Dify instance (local deployment or cloud version).
- Click the **"Plugins"** menu item on the top right of the Dify navigation bar.
- On the plugins page, click the **"Install Plugin"** button.
- Select the **"Local Plugin"** tab.
- Click the upload area, select or drag and drop the `<provider_name>.difypkg` file you just generated locally.
- Wait for the plugin installation or update to complete.
- After successful installation, you typically need to go to "Settings" -> "Model Providers" to find the corresponding provider and configure your API credentials (if you haven't configured them before).
- Create a new Dify application or edit an existing one, in the "Prompt Orchestration" -> "Model" settings, try selecting your newly added model. Conduct some simple conversations or call tests to ensure it works properly and returns expected results.
6. **Submit Your Contribution:**
- After verifying that local testing is working properly, commit your changes (the new model YAML file and updated `manifest.yaml`) via Git and push them to your forked GitHub repository.
- On GitHub, initiate a Pull Request (PR) to the main `langgenius/dify-official-plugins` repository. In the PR description, briefly mention which model you added and include a link to the model's official documentation to facilitate reviewer verification of parameters.
---
**What's Next?**
Once your PR is reviewed, approved, and merged, your contribution becomes part of the official Dify plugins, and all Dify users can easily use this new model!
This quick integration method is the fastest way to make Dify support new models. Of course, if this model needs to support more complex features in the future (such as image input, function calling, etc.), then experienced developers may need to update the plugin at the code level. But the step you've completed now is already a very valuable contribution!
**Explore More:**
- [Model Schema Definition](/plugin-dev-en/0412-model-schema) (Learn detailed rules for model YAML files)
- [Model Design Rules](/plugin-dev-en/0411-model-designing-rules) (Learn specifications for model parameter design)
- [General Specifications](/plugin-dev-en/0411-general-specifications) (Understand the role of `manifest.yaml`)
- [Creating a New Model Provider](/plugin-dev-en/0222-creating-new-model-provider) (Learn how to add a new model provider)
- [Publish to Dify Marketplace](/plugin-dev-en/0322-release-to-dify-marketplace) (Learn how to publish your plugin)
- [Dify Official Plugin Repository](https://github.com/langgenius/dify-official-plugins) (View examples of other plugins)
{/*
Contributing Section
DO NOT edit this section!
It will be automatically generated by the script.
*/}
---
[Edit this page](https://github.com/langgenius/dify-docs/edit/main/plugin-dev-en/0211-getting-started-new-model.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)