Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langgenius Dify Debug Models

From Leeroopedia


Knowledge Sources
Domains Frontend, Type Definitions, LLM Configuration, Debugging
Last Updated 2026-02-08 00:00 GMT

Overview

Defines TypeScript types and enums for LLM model configuration, prompt management, completion parameters, dataset retrieval settings, debug requests/responses, and feedback handling in the Dify frontend.

Description

web/models/debug.ts is a central type definition module for the Dify application configuration and debugging system. It provides the type infrastructure for the "Debug and Preview" feature of the application builder, covering the full spectrum of LLM configuration options.

Key type groups include:

  • Prompt system: PromptMode enum (simple/advanced), PromptRole enum (system/user/assistant), PromptItem, PromptVariable, ChatPromptConfig, CompletionPromptConfig
  • Model configuration: ModelConfig (comprehensive frontend model configuration), CompletionParams, ModelId
  • Feature configurations: MoreLikeThisConfig, SuggestedQuestionsAfterAnswerConfig, SpeechToTextConfig, TextToSpeechConfig, CitationConfig, ModerationConfig, AnnotationReplyConfig, RetrieverResourceConfig, AgentConfig
  • Dataset configurations: DatasetConfigs with retrieval model, reranking settings, score thresholds, metadata filtering
  • Debug/log types: DebugRequestBody, DebugResponse, DebugResponseStream, FeedBackRequestBody, FeedBackResponse
  • Session types: LogSessionListQuery, LogSessionListResponse, LogSessionDetailResponse

Usage

Import types from this module when building configuration UIs, debug panels, or handling model-related API responses:

import type { ModelConfig, PromptVariable, CompletionParams } from '@/models/debug'
import { PromptMode, PromptRole } from '@/models/debug'

Code Reference

Source Location

Signature

export type Inputs = Record<string, string | number | object | boolean>

export enum PromptMode { simple = 'simple', advanced = 'advanced' }
export enum PromptRole { system = 'system', user = 'user', assistant = 'assistant' }

export type PromptVariable = {
  key: string; name: string; type: string;
  default?: string | number; required?: boolean;
  options?: string[]; max_length?: number;
}

export type CompletionParams = {
  max_tokens: number; temperature: number; top_p: number;
  presence_penalty: number; frequency_penalty: number; stop?: string[];
}

export type ModelConfig = {
  provider: string; model_id: string; mode: ModelModeType;
  configs: PromptConfig; opening_statement: string | null;
  more_like_this: MoreLikeThisConfig | null;
  dataSets: any[]; agentConfig: AgentConfig;
  // ... many more optional feature configs
}

export type DatasetConfigs = {
  retrieval_model: RETRIEVE_TYPE;
  reranking_model: { reranking_provider_name: string; reranking_model_name: string };
  top_k: number; score_threshold: number | null | undefined;
  datasets: { datasets: { enabled: boolean; id: string }[] };
}

export type DebugRequestBody = { inputs: Inputs; query: string; completion_params: CompletionParams; model_config: ModelConfig }
export type DebugResponse = { id: string; answer: string; created_at: string }

export type ModerationConfig = { enabled: boolean; type?: string; config?: { keywords?: string; ... } }

Import

import type { ModelConfig, PromptVariable, DatasetConfigs, ModerationConfig } from '@/models/debug'
import { PromptMode, PromptRole } from '@/models/debug'

I/O Contract

Inputs

Name Type Required Description
(none) - - This module only exports type definitions and enums; it has no runtime inputs

Outputs

Name Type Description
PromptMode enum Enum with values simple and advanced for prompt editing modes
PromptRole enum Enum with values system, user, assistant for chat prompt roles
ModelConfig type Comprehensive frontend model configuration including provider, prompt, features, and dataset settings
CompletionParams type LLM generation parameters: temperature, top_p, max_tokens, stop sequences, penalties
DatasetConfigs type RAG retrieval configuration with reranking, scoring, and metadata filtering options
DebugRequestBody type Request body for debug/preview API calls
ModerationConfig type Content moderation configuration with keyword and API-based options
PromptVariable type Variable definition for prompt templates with key, type, options, and validation

Usage Examples

import type { ModelConfig, CompletionParams, PromptVariable } from '@/models/debug'
import { PromptRole, PromptMode } from '@/models/debug'

// Build a model configuration for the debug panel
const modelConfig: ModelConfig = {
  provider: 'openai',
  model_id: 'gpt-3.5-turbo',
  mode: 'chat',
  prompt_type: PromptMode.advanced,
  configs: {
    prompt_template: 'You are a helpful assistant.',
    prompt_variables: [],
  },
  chat_prompt_config: {
    prompt: [{ role: PromptRole.system, text: 'You are a helpful assistant.' }],
  },
  opening_statement: 'Hello! How can I help you today?',
  more_like_this: null,
  // ... other required fields
}

// Define prompt variables
const variables: PromptVariable[] = [
  { key: 'name', name: 'User Name', type: 'string', required: true },
  { key: 'language', name: 'Language', type: 'select', options: ['English', 'Chinese'] },
]

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment