chat.ts
Overview
The chat.ts file defines TypeScript interfaces and types that model the core data structures used in a chat or conversational AI system. These interfaces represent configurations, dialog metadata, conversations, messages, references, answers, tokens, and statistics, enabling strong typing and clear contracts for components interacting with chat-related data. The file mainly serves as a type definitions module to standardize data shapes across the application, facilitating maintainability and reducing runtime errors.
The file does not contain executable logic or algorithms but provides critical schema definitions that underpin chat functionality such as message handling, dialog settings, LLM (Large Language Model) configurations, conversation referencing, and token management.
Detailed Interface Descriptions
PromptConfig
Defines the configuration for a prompt used in generating or refining chat responses.
Property | Type | Description |
|---|---|---|
|
| The response to use when no content is generated or found. |
|
| Array of parameters required or optional for prompt generation. |
|
| Introductory text to prepend to generated prompts. |
|
| System-level instructions or context for the prompt. |
|
| Optional flag to enable text-to-speech features. |
|
| Whether quoting is enabled in the prompt. |
|
| Whether keyword extraction or usage is enabled. |
|
| Enables refinement across multiple turns in a conversation. |
|
| Whether to use a knowledge graph in prompt generation. |
|
| Optional flag to enable reasoning capabilities. |
| Optional list of supported cross-languages for multilingual prompts. |
Usage example:
const examplePromptConfig: PromptConfig = {
empty_response: "Sorry, I don't have an answer.",
parameters: [{ key: 'topic', optional: false }],
prologue: "Let's discuss the topic:",
system: "You are an expert assistant.",
quote: true,
keyword: false,
refine_multiturn: true,
use_kg: false,
};
Parameter
Defines an individual prompt parameter specifying its key and whether it is optional.
Property | Type | Description |
|---|---|---|
|
| The name/key of the parameter. |
|
| Whether the parameter is optional. |
LlmSetting
Describes multiple LLM configuration profiles, each represented as a Variable.
Property | Type | Description |
|---|---|---|
|
| Settings for a creative LLM style. |
|
| Custom LLM settings. |
|
| Balanced LLM settings. |
|
| Settings favoring precision. |
Variable
Models the configurable parameters for an LLM instance.
Property | Type | Description |
|---|---|---|
|
| Controls repetition penalty. |
|
| Maximum tokens allowed in a generation. |
|
| Penalty for presence of new tokens. |
|
| Sampling temperature for randomness. |
|
| Top-p nucleus sampling parameter. |
|
| Identifier for the LLM instance. |
IDialog
Represents metadata and configuration of a dialog session or template.
Property | Type | Description |
|---|---|---|
|
| Creation date of the dialog. |
|
| Timestamp of creation. |
|
| Description or summary of the dialog. |
|
| Icon identifier or URL associated with the dialog. |
|
| Unique identifier of the dialog. |
|
| Another dialog ID, possibly for external referencing. |
|
| Knowledge base IDs linked to this dialog. |
|
| Names of linked knowledge bases. |
|
| Language code of the dialog. |
|
| Identifier of the LLM used in the dialog. |
|
| LLM parameters associated with the dialog. |
|
| Type or profile name of the LLM setting (e.g., "Creative"). |
|
| Human-readable name for the dialog. |
|
| Configuration for prompts used in this dialog. |
|
| Type/category of prompt (e.g., "question_answering"). |
|
| Current status of the dialog (e.g., "active"). |
|
| Tenant or customer identifier owning this dialog. |
|
| Last update date. |
|
| Last update timestamp. |
|
| Weighting factor for vector similarity in retrieval. |
|
| Threshold for similarity filtering. |
|
| Number of top results to consider. |
|
| Number of top candidates to retrieve. |
|
| Filter criteria for metadata during retrieval or processing. |
MetaDataFilter
Defines filtering method and manual filters applied to metadata.
Property | Type | Description |
|---|---|---|
|
| Array of manual filter conditions. |
|
| Filtering method used (e.g., "and"). |
Manual
Specifies a single manual filter condition.
Property | Type | Description |
|---|---|---|
|
| Metadata key to filter by. |
|
| Operation to apply (e.g., "="). |
|
| Value to match for the key. |
IConversation
Represents a conversation thread or chat session.
Property | Type | Description |
|---|---|---|
|
| Creation date of the conversation. |
|
| Creation timestamp. |
|
| Associated dialog ID. |
|
| Unique ID for the conversation. |
|
| Avatar image or icon for UI display. |
|
| List of messages in the conversation. |
|
| List of references related to the conversation. |
|
| Name or title of the conversation. |
|
| Last update date. |
|
| Last update timestamp. |
|
| Flag indicating if the conversation is new. |
Message
Represents an individual message within a conversation.
Property | Type | Description |
|---|---|---|
|
| Text content of the message. |
|
| Role of the sender (e.g., user, system). |
|
| Optional list of document IDs referenced. |
|
| Optional prompt text associated. |
|
| Optional unique message identifier. |
|
| Optional audio binary data for TTS. |
|
| Optional additional data payload. |
|
| Optional attached files. |
|
| Optional ID of the chat box UI element. |
IReferenceChunk
Represents a chunk of referenced data from a document.
Property | Type | Description |
|---|---|---|
|
| Unique chunk identifier. |
|
| Content is currently null (placeholder). |
|
| ID of the document this chunk belongs to. |
|
| Name of the document. |
|
| Dataset identifier. |
|
| Associated image identifier. |
|
| Overall similarity score. |
|
| Similarity based on vector embedding. |
|
| Similarity based on term matching. |
|
| Positions or offsets in the document. |
|
| Optional document type (e.g., "pdf"). |
IReference
Represents aggregated referencing information for documents related to a conversation or answer.
Property | Type | Description |
|---|---|---|
|
| Array of referenced chunks. |
|
| Aggregated document metadata. |
|
| Total number of references. |
IReferenceObject
Alternative representation with mapped chunk and document aggregations keyed by IDs.
Property | Type | Description |
|---|---|---|
|
| Map of chunk IDs to chunks. |
|
| Map of document IDs to aggregates. |
IAnswer
Represents an answer generated by the system, potentially with references and audio.
Property | Type | Description |
|---|---|---|
|
| The textual answer content. |
|
| Optional references supporting the answer. |
|
| Optional ID of the conversation. |
|
| Optional prompt used to generate the answer. |
|
| Optional unique answer ID. |
|
| Optional audio data for TTS playback. |
|
| Optional additional data payload. |
|
| Optional UI chat box identifier. |
Docagg
Aggregated metadata for a document referenced in conversations or answers.
Property | Type | Description |
|---|---|---|
|
| Number of references or hits. |
|
| Document ID. |
|
| Document name. |
|
| Optional URL to access the document. |
IToken
Represents an authentication or access token entity.
Property | Type | Description |
|---|---|---|
|
| Token creation date. |
|
| Creation timestamp. |
|
| Tenant or customer owning the token. |
|
| The token string itself. |
|
| Optional last update date. |
|
| Optional last update timestamp. |
|
| Beta feature flag or related info. |
IStats
Holds various usage and performance statistics as arrays of timestamp-value tuples.
Property | Type | Description |
|---|---|---|
|
| Page views over time. |
|
| Unique visitors over time. |
|
| Processing speed metrics. |
|
| Token usage counts. |
|
| Conversation rounds count. |
|
| Positive feedback counts. |
IExternalChatInfo
Metadata for external chat integrations or imports.
Property | Type | Description |
|---|---|---|
|
| Optional avatar image URL or ID. |
|
| Title or name of the external chat. |
|
| Optional introductory text. |
Important Implementation Notes
The file primarily contains interface declarations, no executable code is present.
Interfaces such as
IDialog,IConversation,IAnswer, andMessageare central to representing chat states, history, and responses.The
PromptConfiginterface supports multi-turn conversations with options for keyword extraction, reasoning, and knowledge graph use, indicating flexibility in prompt engineering.Similarity metrics (
vector_similarity,term_similarity) inIReferenceChunkhint at use of embedding-based retrieval and classical term matching for document referencing.The
LlmSettingandVariableinterfaces expose fine-grained control over LLM parameters, supporting multiple generation styles (Creative, Precise, etc.).The
MetaDataFilterandManualinterfaces suggest filtering capabilities on metadata when retrieving documents or chunks.Use of optional properties (marked with
?) allows flexibility in object construction and partial data.
Interaction with Other System Components
This file imports
MessageTypefrom@/constants/chat, indicating dependency on a constants module defining allowed message roles/types.The defined interfaces support data exchange between frontend UI components (chat boxes, dialogs), backend services (LLM inference, document retrieval), and possibly middleware handling chat sessions and token authentication.
The
kb_idsandkb_namesinIDialoglink dialogs to knowledge bases, implying integration with knowledge management systems.The
IReferenceandIReferenceChunkinterfaces indicate interaction with document indexing and retrieval subsystems.ITokensuggests integration with authentication or API key management services.The
IStatsinterface likely connects to analytics and monitoring components tracking usage and performance.
Visual Diagram: Class Diagram of Interfaces in chat.ts
classDiagram
class PromptConfig {
+empty_response: string
+parameters: Parameter[]
+prologue: string
+system: string
+tts?: boolean
+quote: boolean
+keyword: boolean
+refine_multiturn: boolean
+use_kg: boolean
+reasoning?: boolean
+cross_languages?: string[]
}
class Parameter {
+key: string
+optional: boolean
}
class LlmSetting {
+Creative: Variable
+Custom: Variable
+Evenly: Variable
+Precise: Variable
}
class Variable {
+frequency_penalty?: number
+max_tokens?: number
+presence_penalty?: number
+temperature?: number
+top_p?: number
+llm_id?: string
}
class IDialog {
+create_date: string
+create_time: number
+description: string
+icon: string
+id: string
+dialog_id: string
+kb_ids: string[]
+kb_names: string[]
+language: string
+llm_id: string
+llm_setting: Variable
+llm_setting_type: string
+name: string
+prompt_config: PromptConfig
+prompt_type: string
+status: string
+tenant_id: string
+update_date: string
+update_time: number
+vector_similarity_weight: number
+similarity_threshold: number
+top_k: number
+top_n: number
+meta_data_filter: MetaDataFilter
}
class MetaDataFilter {
+manual: Manual[]
+method: string
}
class Manual {
+key: string
+op: string
+value: string
}
class IConversation {
+create_date: string
+create