dify/web/models/debug.ts
lyzno1 5bbf685035
feat: fix i18n missing keys and merge upstream/main (#24615)
Signed-off-by: -LAN- <laipz8200@outlook.com>
Signed-off-by: kenwoodjw <blackxin55+@gmail.com>
Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Signed-off-by: zhanluxianshen <zhanluxianshen@163.com>
Co-authored-by: -LAN- <laipz8200@outlook.com>
Co-authored-by: GuanMu <ballmanjq@gmail.com>
Co-authored-by: Davide Delbianco <davide.delbianco@outlook.com>
Co-authored-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com>
Co-authored-by: kenwoodjw <blackxin55+@gmail.com>
Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
Co-authored-by: Yongtao Huang <99629139+hyongtao-db@users.noreply.github.com>
Co-authored-by: Qiang Lee <18018968632@163.com>
Co-authored-by: 李强04 <liqiang04@gaotu.cn>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
Co-authored-by: Matri Qi <matrixdom@126.com>
Co-authored-by: huayaoyue6 <huayaoyue@163.com>
Co-authored-by: Bowen Liang <liangbowen@gf.com.cn>
Co-authored-by: znn <jubinkumarsoni@gmail.com>
Co-authored-by: crazywoola <427733928@qq.com>
Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: yihong <zouzou0208@gmail.com>
Co-authored-by: Muke Wang <shaodwaaron@gmail.com>
Co-authored-by: wangmuke <wangmuke@kingsware.cn>
Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com>
Co-authored-by: quicksand <quicksandzn@gmail.com>
Co-authored-by: 非法操作 <hjlarry@163.com>
Co-authored-by: zxhlyh <jasonapring2015@outlook.com>
Co-authored-by: Eric Guo <eric.guocz@gmail.com>
Co-authored-by: Zhedong Cen <cenzhedong2@126.com>
Co-authored-by: jiangbo721 <jiangbo721@163.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: hjlarry <25834719+hjlarry@users.noreply.github.com>
Co-authored-by: lxsummer <35754229+lxjustdoit@users.noreply.github.com>
Co-authored-by: 湛露先生 <zhanluxianshen@163.com>
Co-authored-by: Guangdong Liu <liugddx@gmail.com>
Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Yessenia-d <yessenia.contact@gmail.com>
Co-authored-by: huangzhuo1949 <167434202+huangzhuo1949@users.noreply.github.com>
Co-authored-by: huangzhuo <huangzhuo1@xiaomi.com>
Co-authored-by: 17hz <0x149527@gmail.com>
Co-authored-by: Amy <1530140574@qq.com>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: Nite Knite <nkCoding@gmail.com>
Co-authored-by: Yeuoly <45712896+Yeuoly@users.noreply.github.com>
Co-authored-by: Petrus Han <petrus.hanks@gmail.com>
Co-authored-by: iamjoel <2120155+iamjoel@users.noreply.github.com>
Co-authored-by: Kalo Chin <frog.beepers.0n@icloud.com>
Co-authored-by: Ujjwal Maurya <ujjwalsbx@gmail.com>
Co-authored-by: Maries <xh001x@hotmail.com>
2025-08-27 15:07:28 +08:00

259 lines
5.9 KiB
TypeScript

import type { AgentStrategy, ModelModeType, RETRIEVE_TYPE, ToolItem, TtsAutoPlay } from '@/types/app'
import type {
RerankingModeEnum,
WeightedScoreEnum,
} from '@/models/datasets'
import type { FileUpload } from '@/app/components/base/features/types'
import type {
MetadataFilteringConditions,
MetadataFilteringModeEnum,
} from '@/app/components/workflow/nodes/knowledge-retrieval/types'
import type { ModelConfig as NodeModelConfig } from '@/app/components/workflow/types'
export type Inputs = Record<string, string | number | object | boolean>
export enum PromptMode {
simple = 'simple',
advanced = 'advanced',
}
export type PromptItem = {
role?: PromptRole
text: string
}
export type ChatPromptConfig = {
prompt: PromptItem[]
}
export type ConversationHistoriesRole = {
user_prefix: string
assistant_prefix: string
}
export type CompletionPromptConfig = {
prompt: PromptItem
conversation_histories_role: ConversationHistoriesRole
}
export type BlockStatus = {
context: boolean
history: boolean
query: boolean
}
export enum PromptRole {
system = 'system',
user = 'user',
assistant = 'assistant',
}
export type PromptVariable = {
key: string
name: string
type: string // "string" | "number" | "select",
default?: string | number
required?: boolean
options?: string[]
max_length?: number
is_context_var?: boolean
enabled?: boolean
config?: Record<string, any>
icon?: string
icon_background?: string
hide?: boolean // used in frontend to hide variable
json_schema?: string
}
export type CompletionParams = {
max_tokens: number
temperature: number
top_p: number
presence_penalty: number
frequency_penalty: number
stop?: string[]
}
export type ModelId = 'gpt-3.5-turbo' | 'text-davinci-003'
export type PromptConfig = {
prompt_template: string
prompt_variables: PromptVariable[]
}
export type MoreLikeThisConfig = {
enabled: boolean
}
export type SuggestedQuestionsAfterAnswerConfig = MoreLikeThisConfig
export type SpeechToTextConfig = MoreLikeThisConfig
export type TextToSpeechConfig = {
enabled: boolean
voice?: string
language?: string
autoPlay?: TtsAutoPlay
}
export type CitationConfig = MoreLikeThisConfig
export type AnnotationReplyConfig = {
id: string
enabled: boolean
score_threshold: number
embedding_model: {
embedding_provider_name: string
embedding_model_name: string
}
}
export type ModerationContentConfig = {
enabled: boolean
preset_response?: string
}
export type ModerationConfig = MoreLikeThisConfig & {
type?: string
config?: {
keywords?: string
api_based_extension_id?: string
inputs_config?: ModerationContentConfig
outputs_config?: ModerationContentConfig
} & Partial<Record<string, any>>
}
export type RetrieverResourceConfig = MoreLikeThisConfig
export type AgentConfig = {
enabled: boolean
strategy: AgentStrategy
max_iteration: number
tools: ToolItem[]
}
// frontend use. Not the same as backend
export type ModelConfig = {
provider: string // LLM Provider: for example "OPENAI"
model_id: string
mode: ModelModeType
configs: PromptConfig
opening_statement: string | null
more_like_this: MoreLikeThisConfig | null
suggested_questions: string[] | null
suggested_questions_after_answer: SuggestedQuestionsAfterAnswerConfig | null
speech_to_text: SpeechToTextConfig | null
text_to_speech: TextToSpeechConfig | null
file_upload: FileUpload | null
retriever_resource: RetrieverResourceConfig | null
sensitive_word_avoidance: ModerationConfig | null
annotation_reply: AnnotationReplyConfig | null
dataSets: any[]
agentConfig: AgentConfig
}
export type DatasetConfigItem = {
enable: boolean
value: number
}
export type DatasetConfigs = {
retrieval_model: RETRIEVE_TYPE
reranking_model: {
reranking_provider_name: string
reranking_model_name: string
}
top_k: number
score_threshold_enabled: boolean
score_threshold: number | null | undefined
datasets: {
datasets: {
enabled: boolean
id: string
}[]
}
reranking_mode?: RerankingModeEnum
weights?: {
weight_type: WeightedScoreEnum
vector_setting: {
vector_weight: number
embedding_provider_name: string
embedding_model_name: string
}
keyword_setting: {
keyword_weight: number
}
}
reranking_enable?: boolean
metadata_filtering_mode?: MetadataFilteringModeEnum
metadata_filtering_conditions?: MetadataFilteringConditions
metadata_model_config?: NodeModelConfig
}
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 DebugResponseStream = {
id: string
data: string
created_at: string
}
export type FeedBackRequestBody = {
message_id: string
rating: 'like' | 'dislike'
content?: string
from_source: 'api' | 'log'
}
export type FeedBackResponse = {
message_id: string
rating: 'like' | 'dislike'
}
// Log session list
export type LogSessionListQuery = {
keyword?: string
start?: string // format datetime(YYYY-mm-dd HH:ii)
end?: string // format datetime(YYYY-mm-dd HH:ii)
page: number
limit: number // default 20. 1-100
}
export type LogSessionListResponse = {
data: {
id: string
conversation_id: string
query: string // user's query question
message: string // prompt send to LLM
answer: string
created_at: string
}[]
total: number
page: number
}
// log session detail and debug
export type LogSessionDetailResponse = {
id: string
conversation_id: string
model_provider: string
query: string
inputs: Record<string, string | number | object>[]
message: string
message_tokens: number // number of tokens in message
answer: string
answer_tokens: number // number of tokens in answer
provider_response_latency: number // used time in ms
from_source: 'api' | 'log'
}
export type SavedMessage = {
id: string
answer: string
}