mirror of
https://github.com/langgenius/dify.git
synced 2026-04-26 18:27:15 +08:00
Merge branch 'main' into feat/queue-based-graph-engine
This commit is contained in:
commit
976b3b5e83
87
AGENTS.md
Normal file
87
AGENTS.md
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
# AGENTS.md
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
|
||||||
|
Dify is an open-source platform for developing LLM applications with an intuitive interface combining agentic AI workflows, RAG pipelines, agent capabilities, and model management.
|
||||||
|
|
||||||
|
The codebase consists of:
|
||||||
|
|
||||||
|
- **Backend API** (`/api`): Python Flask application with Domain-Driven Design architecture
|
||||||
|
- **Frontend Web** (`/web`): Next.js 15 application with TypeScript and React 19
|
||||||
|
- **Docker deployment** (`/docker`): Containerized deployment configurations
|
||||||
|
|
||||||
|
## Development Commands
|
||||||
|
|
||||||
|
### Backend (API)
|
||||||
|
|
||||||
|
All Python commands must be prefixed with `uv run --project api`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Start development servers
|
||||||
|
./dev/start-api # Start API server
|
||||||
|
./dev/start-worker # Start Celery worker
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
uv run --project api pytest # Run all tests
|
||||||
|
uv run --project api pytest tests/unit_tests/ # Unit tests only
|
||||||
|
uv run --project api pytest tests/integration_tests/ # Integration tests
|
||||||
|
|
||||||
|
# Code quality
|
||||||
|
./dev/reformat # Run all formatters and linters
|
||||||
|
uv run --project api ruff check --fix ./ # Fix linting issues
|
||||||
|
uv run --project api ruff format ./ # Format code
|
||||||
|
uv run --directory api basedpyright # Type checking
|
||||||
|
```
|
||||||
|
|
||||||
|
### Frontend (Web)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd web
|
||||||
|
pnpm lint # Run ESLint
|
||||||
|
pnpm eslint-fix # Fix ESLint issues
|
||||||
|
pnpm test # Run Jest tests
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing Guidelines
|
||||||
|
|
||||||
|
### Backend Testing
|
||||||
|
|
||||||
|
- Use `pytest` for all backend tests
|
||||||
|
- Write tests first (TDD approach)
|
||||||
|
- Test structure: Arrange-Act-Assert
|
||||||
|
|
||||||
|
## Code Style Requirements
|
||||||
|
|
||||||
|
### Python
|
||||||
|
|
||||||
|
- Use type hints for all functions and class attributes
|
||||||
|
- No `Any` types unless absolutely necessary
|
||||||
|
- Implement special methods (`__repr__`, `__str__`) appropriately
|
||||||
|
|
||||||
|
### TypeScript/JavaScript
|
||||||
|
|
||||||
|
- Strict TypeScript configuration
|
||||||
|
- ESLint with Prettier integration
|
||||||
|
- Avoid `any` type
|
||||||
|
|
||||||
|
## Important Notes
|
||||||
|
|
||||||
|
- **Environment Variables**: Always use UV for Python commands: `uv run --project api <command>`
|
||||||
|
- **Comments**: Only write meaningful comments that explain "why", not "what"
|
||||||
|
- **File Creation**: Always prefer editing existing files over creating new ones
|
||||||
|
- **Documentation**: Don't create documentation files unless explicitly requested
|
||||||
|
- **Code Quality**: Always run `./dev/reformat` before committing backend changes
|
||||||
|
|
||||||
|
## Common Development Tasks
|
||||||
|
|
||||||
|
### Adding a New API Endpoint
|
||||||
|
|
||||||
|
1. Create controller in `/api/controllers/`
|
||||||
|
1. Add service logic in `/api/services/`
|
||||||
|
1. Update routes in controller's `__init__.py`
|
||||||
|
1. Write tests in `/api/tests/`
|
||||||
|
|
||||||
|
## Project-Specific Conventions
|
||||||
|
|
||||||
|
- All async tasks use Celery with Redis as broker
|
||||||
|
- **Internationalization**: Frontend supports multiple languages with English (`web/i18n/en-US/`) as the source. All user-facing text must use i18n keys, no hardcoded strings. Edit corresponding module files in `en-US/` directory for translations.
|
||||||
89
CLAUDE.md
89
CLAUDE.md
@ -1,89 +0,0 @@
|
|||||||
# CLAUDE.md
|
|
||||||
|
|
||||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
||||||
|
|
||||||
## Project Overview
|
|
||||||
|
|
||||||
Dify is an open-source platform for developing LLM applications with an intuitive interface combining agentic AI workflows, RAG pipelines, agent capabilities, and model management.
|
|
||||||
|
|
||||||
The codebase consists of:
|
|
||||||
|
|
||||||
- **Backend API** (`/api`): Python Flask application with Domain-Driven Design architecture
|
|
||||||
- **Frontend Web** (`/web`): Next.js 15 application with TypeScript and React 19
|
|
||||||
- **Docker deployment** (`/docker`): Containerized deployment configurations
|
|
||||||
|
|
||||||
## Development Commands
|
|
||||||
|
|
||||||
### Backend (API)
|
|
||||||
|
|
||||||
All Python commands must be prefixed with `uv run --project api`:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Start development servers
|
|
||||||
./dev/start-api # Start API server
|
|
||||||
./dev/start-worker # Start Celery worker
|
|
||||||
|
|
||||||
# Run tests
|
|
||||||
uv run --project api pytest # Run all tests
|
|
||||||
uv run --project api pytest tests/unit_tests/ # Unit tests only
|
|
||||||
uv run --project api pytest tests/integration_tests/ # Integration tests
|
|
||||||
|
|
||||||
# Code quality
|
|
||||||
./dev/reformat # Run all formatters and linters
|
|
||||||
uv run --project api ruff check --fix ./ # Fix linting issues
|
|
||||||
uv run --project api ruff format ./ # Format code
|
|
||||||
uv run --directory api basedpyright # Type checking
|
|
||||||
```
|
|
||||||
|
|
||||||
### Frontend (Web)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd web
|
|
||||||
pnpm lint # Run ESLint
|
|
||||||
pnpm eslint-fix # Fix ESLint issues
|
|
||||||
pnpm test # Run Jest tests
|
|
||||||
```
|
|
||||||
|
|
||||||
## Testing Guidelines
|
|
||||||
|
|
||||||
### Backend Testing
|
|
||||||
|
|
||||||
- Use `pytest` for all backend tests
|
|
||||||
- Write tests first (TDD approach)
|
|
||||||
- Test structure: Arrange-Act-Assert
|
|
||||||
|
|
||||||
## Code Style Requirements
|
|
||||||
|
|
||||||
### Python
|
|
||||||
|
|
||||||
- Use type hints for all functions and class attributes
|
|
||||||
- No `Any` types unless absolutely necessary
|
|
||||||
- Implement special methods (`__repr__`, `__str__`) appropriately
|
|
||||||
|
|
||||||
### TypeScript/JavaScript
|
|
||||||
|
|
||||||
- Strict TypeScript configuration
|
|
||||||
- ESLint with Prettier integration
|
|
||||||
- Avoid `any` type
|
|
||||||
|
|
||||||
## Important Notes
|
|
||||||
|
|
||||||
- **Environment Variables**: Always use UV for Python commands: `uv run --project api <command>`
|
|
||||||
- **Comments**: Only write meaningful comments that explain "why", not "what"
|
|
||||||
- **File Creation**: Always prefer editing existing files over creating new ones
|
|
||||||
- **Documentation**: Don't create documentation files unless explicitly requested
|
|
||||||
- **Code Quality**: Always run `./dev/reformat` before committing backend changes
|
|
||||||
|
|
||||||
## Common Development Tasks
|
|
||||||
|
|
||||||
### Adding a New API Endpoint
|
|
||||||
|
|
||||||
1. Create controller in `/api/controllers/`
|
|
||||||
1. Add service logic in `/api/services/`
|
|
||||||
1. Update routes in controller's `__init__.py`
|
|
||||||
1. Write tests in `/api/tests/`
|
|
||||||
|
|
||||||
## Project-Specific Conventions
|
|
||||||
|
|
||||||
- All async tasks use Celery with Redis as broker
|
|
||||||
- **Internationalization**: Frontend supports multiple languages with English (`web/i18n/en-US/`) as the source. All user-facing text must use i18n keys, no hardcoded strings. Edit corresponding module files in `en-US/` directory for translations.
|
|
||||||
@ -371,13 +371,14 @@ class WorkflowService:
|
|||||||
|
|
||||||
def _validate_llm_model_config(self, tenant_id: str, provider: str, model_name: str) -> None:
|
def _validate_llm_model_config(self, tenant_id: str, provider: str, model_name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Validate that an LLM model configuration can fetch valid credentials.
|
Validate that an LLM model configuration can fetch valid credentials and has active status.
|
||||||
|
|
||||||
This method attempts to get the model instance and validates that:
|
This method attempts to get the model instance and validates that:
|
||||||
1. The provider exists and is configured
|
1. The provider exists and is configured
|
||||||
2. The model exists in the provider
|
2. The model exists in the provider
|
||||||
3. Credentials can be fetched for the model
|
3. Credentials can be fetched for the model
|
||||||
4. The credentials pass policy compliance checks
|
4. The credentials pass policy compliance checks
|
||||||
|
5. The model status is ACTIVE (not NO_CONFIGURE, DISABLED, etc.)
|
||||||
|
|
||||||
:param tenant_id: The tenant ID
|
:param tenant_id: The tenant ID
|
||||||
:param provider: The provider name
|
:param provider: The provider name
|
||||||
@ -387,6 +388,7 @@ class WorkflowService:
|
|||||||
try:
|
try:
|
||||||
from core.model_manager import ModelManager
|
from core.model_manager import ModelManager
|
||||||
from core.model_runtime.entities.model_entities import ModelType
|
from core.model_runtime.entities.model_entities import ModelType
|
||||||
|
from core.provider_manager import ProviderManager
|
||||||
|
|
||||||
# Get model instance to validate provider+model combination
|
# Get model instance to validate provider+model combination
|
||||||
model_manager = ModelManager()
|
model_manager = ModelManager()
|
||||||
@ -398,6 +400,22 @@ class WorkflowService:
|
|||||||
# via ProviderConfiguration.get_current_credentials() -> _check_credential_policy_compliance()
|
# via ProviderConfiguration.get_current_credentials() -> _check_credential_policy_compliance()
|
||||||
# If it fails, an exception will be raised
|
# If it fails, an exception will be raised
|
||||||
|
|
||||||
|
# Additionally, check the model status to ensure it's ACTIVE
|
||||||
|
provider_manager = ProviderManager()
|
||||||
|
provider_configurations = provider_manager.get_configurations(tenant_id)
|
||||||
|
models = provider_configurations.get_models(provider=provider, model_type=ModelType.LLM)
|
||||||
|
|
||||||
|
target_model = None
|
||||||
|
for model in models:
|
||||||
|
if model.model == model_name and model.provider.provider == provider:
|
||||||
|
target_model = model
|
||||||
|
break
|
||||||
|
|
||||||
|
if target_model:
|
||||||
|
target_model.raise_for_status()
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Model {model_name} not found for provider {provider}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Failed to validate LLM model configuration (provider: {provider}, model: {model_name}): {str(e)}"
|
f"Failed to validate LLM model configuration (provider: {provider}, model: {model_name}): {str(e)}"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user