graphile-llm 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +193 -0
- package/__tests__/graphile-llm.test.d.ts +1 -0
- package/__tests__/graphile-llm.test.js +721 -0
- package/chat.d.ts +37 -0
- package/chat.js +105 -0
- package/embedder.d.ts +35 -0
- package/embedder.js +79 -0
- package/esm/__tests__/graphile-llm.test.d.ts +1 -0
- package/esm/__tests__/graphile-llm.test.js +683 -0
- package/esm/chat.d.ts +37 -0
- package/esm/chat.js +97 -0
- package/esm/embedder.d.ts +35 -0
- package/esm/embedder.js +71 -0
- package/esm/index.d.ts +39 -0
- package/esm/index.js +42 -0
- package/esm/plugins/llm-module-plugin.d.ts +38 -0
- package/esm/plugins/llm-module-plugin.js +82 -0
- package/esm/plugins/rag-plugin.d.ts +36 -0
- package/esm/plugins/rag-plugin.js +341 -0
- package/esm/plugins/text-mutation-plugin.d.ts +44 -0
- package/esm/plugins/text-mutation-plugin.js +191 -0
- package/esm/plugins/text-search-plugin.d.ts +41 -0
- package/esm/plugins/text-search-plugin.js +163 -0
- package/esm/preset.d.ts +55 -0
- package/esm/preset.js +74 -0
- package/esm/types.d.ts +173 -0
- package/esm/types.js +6 -0
- package/index.d.ts +39 -0
- package/index.js +56 -0
- package/package.json +76 -0
- package/plugins/llm-module-plugin.d.ts +38 -0
- package/plugins/llm-module-plugin.js +85 -0
- package/plugins/rag-plugin.d.ts +36 -0
- package/plugins/rag-plugin.js +344 -0
- package/plugins/text-mutation-plugin.d.ts +44 -0
- package/plugins/text-mutation-plugin.js +194 -0
- package/plugins/text-search-plugin.d.ts +41 -0
- package/plugins/text-search-plugin.js +166 -0
- package/preset.d.ts +55 -0
- package/preset.js +77 -0
- package/types.d.ts +173 -0
- package/types.js +7 -0
package/types.d.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* graphile-llm Types
|
|
3
|
+
*
|
|
4
|
+
* Shared type definitions for the LLM plugin.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A function that converts text into a vector embedding.
|
|
8
|
+
*/
|
|
9
|
+
export type EmbedderFunction = (text: string) => Promise<number[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for an embedding provider.
|
|
12
|
+
*/
|
|
13
|
+
export interface EmbedderConfig {
|
|
14
|
+
/** Provider name: 'ollama', 'openai', or 'custom' */
|
|
15
|
+
provider: string;
|
|
16
|
+
/** Model identifier (e.g. 'nomic-embed-text', 'text-embedding-3-small') */
|
|
17
|
+
model?: string;
|
|
18
|
+
/** Base URL for the provider (e.g. 'http://localhost:11434' for Ollama) */
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
/** API key for providers that require authentication (e.g. OpenAI) */
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A single message in a chat conversation.
|
|
25
|
+
*/
|
|
26
|
+
export interface ChatMessage {
|
|
27
|
+
role: 'system' | 'user' | 'assistant';
|
|
28
|
+
content: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for a chat completion request.
|
|
32
|
+
*/
|
|
33
|
+
export interface ChatOptions {
|
|
34
|
+
/** Maximum tokens to generate */
|
|
35
|
+
maxTokens?: number;
|
|
36
|
+
/** Temperature for sampling (0 = deterministic, 1 = creative) */
|
|
37
|
+
temperature?: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A function that sends messages to a chat completion provider and returns the response.
|
|
41
|
+
*/
|
|
42
|
+
export type ChatFunction = (messages: ChatMessage[], options?: ChatOptions) => Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Configuration for a chat completion provider.
|
|
45
|
+
*/
|
|
46
|
+
export interface ChatConfig {
|
|
47
|
+
/** Provider name: 'ollama', 'openai', or 'custom' */
|
|
48
|
+
provider: string;
|
|
49
|
+
/** Model identifier (e.g. 'llama3', 'gpt-4o') */
|
|
50
|
+
model?: string;
|
|
51
|
+
/** Base URL for the provider */
|
|
52
|
+
baseUrl?: string;
|
|
53
|
+
/** API key for providers that require authentication */
|
|
54
|
+
apiKey?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The shape of the `llm_module` data stored in `services_public.api_modules`.
|
|
58
|
+
*
|
|
59
|
+
* This is the per-database configuration that controls which LLM provider
|
|
60
|
+
* and models are available for that API.
|
|
61
|
+
*/
|
|
62
|
+
export interface LlmModuleData {
|
|
63
|
+
/** Embedding provider: 'ollama', 'openai', or 'custom' */
|
|
64
|
+
embedding_provider: string;
|
|
65
|
+
/** Embedding model identifier */
|
|
66
|
+
embedding_model?: string;
|
|
67
|
+
/** Base URL for the embedding provider */
|
|
68
|
+
embedding_base_url?: string;
|
|
69
|
+
/** Number of dimensions the embedding model produces */
|
|
70
|
+
embedding_dimensions?: number;
|
|
71
|
+
/** Chat/completion provider (for RAG/conversation features) */
|
|
72
|
+
chat_provider?: string;
|
|
73
|
+
/** Chat model identifier */
|
|
74
|
+
chat_model?: string;
|
|
75
|
+
/** Base URL for the chat provider */
|
|
76
|
+
chat_base_url?: string;
|
|
77
|
+
/** API key reference (e.g. 'vault://openai-key' or env var name) */
|
|
78
|
+
api_key_ref?: string;
|
|
79
|
+
/** Rate limit: requests per minute */
|
|
80
|
+
rate_limit_rpm?: number;
|
|
81
|
+
/** Maximum tokens per request */
|
|
82
|
+
max_tokens_per_request?: number;
|
|
83
|
+
/** Default number of context items for RAG queries */
|
|
84
|
+
rag_context_limit?: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Default configuration for RAG (Retrieval-Augmented Generation) queries.
|
|
88
|
+
*/
|
|
89
|
+
export interface RagDefaults {
|
|
90
|
+
/**
|
|
91
|
+
* Default number of context items to feed into the RAG prompt.
|
|
92
|
+
* Per-query `contextLimit` overrides this.
|
|
93
|
+
* @default 5
|
|
94
|
+
*/
|
|
95
|
+
contextLimit?: number;
|
|
96
|
+
/**
|
|
97
|
+
* Default maximum tokens for the chat completion response.
|
|
98
|
+
* @default 4000
|
|
99
|
+
*/
|
|
100
|
+
maxTokens?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Default minimum similarity threshold (0..1).
|
|
103
|
+
* Only chunks with similarity >= this threshold are included.
|
|
104
|
+
* Converted to max distance internally (1 - minSimilarity for cosine).
|
|
105
|
+
* @default 0 (no threshold)
|
|
106
|
+
*/
|
|
107
|
+
minSimilarity?: number;
|
|
108
|
+
/**
|
|
109
|
+
* Default system prompt prepended to RAG context.
|
|
110
|
+
* Can be overridden per-query.
|
|
111
|
+
*/
|
|
112
|
+
systemPrompt?: string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Info about a chunk-aware table discovered during schema build.
|
|
116
|
+
* Parsed from the @hasChunks smart tag on the parent table's codec.
|
|
117
|
+
*/
|
|
118
|
+
export interface ChunkTableInfo {
|
|
119
|
+
/** Parent table codec name */
|
|
120
|
+
parentCodecName: string;
|
|
121
|
+
/** Schema of the chunks table (or null for public/default) */
|
|
122
|
+
chunksSchema: string | null;
|
|
123
|
+
/** Name of the chunks table */
|
|
124
|
+
chunksTableName: string;
|
|
125
|
+
/** FK column on chunks table pointing to parent */
|
|
126
|
+
parentFkField: string;
|
|
127
|
+
/** PK column on parent table */
|
|
128
|
+
parentPkField: string;
|
|
129
|
+
/** Embedding vector column on chunks table */
|
|
130
|
+
embeddingField: string;
|
|
131
|
+
/** Text content column on chunks table (the actual chunk text) */
|
|
132
|
+
contentField: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Options for the GraphileLlmPreset.
|
|
136
|
+
*/
|
|
137
|
+
export interface GraphileLlmOptions {
|
|
138
|
+
/**
|
|
139
|
+
* Default embedding provider when no llm_module is configured.
|
|
140
|
+
* Useful for development/testing without requiring api_modules setup.
|
|
141
|
+
* @default undefined (requires llm_module to be configured)
|
|
142
|
+
*/
|
|
143
|
+
defaultEmbedder?: EmbedderConfig;
|
|
144
|
+
/**
|
|
145
|
+
* Default chat completion provider when no llm_module is configured.
|
|
146
|
+
* Required for RAG queries.
|
|
147
|
+
* @default undefined
|
|
148
|
+
*/
|
|
149
|
+
defaultChatCompleter?: ChatConfig;
|
|
150
|
+
/**
|
|
151
|
+
* Whether to add `text` field to VectorNearbyInput for text-based vector search.
|
|
152
|
+
* @default true
|
|
153
|
+
*/
|
|
154
|
+
enableTextSearch?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Whether to add `*Text` companion fields on mutation inputs for vector columns.
|
|
157
|
+
* @default true
|
|
158
|
+
*/
|
|
159
|
+
enableTextMutations?: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Whether to enable RAG (Retrieval-Augmented Generation) query support.
|
|
162
|
+
* When enabled, detects tables with @hasChunks smart tag and adds:
|
|
163
|
+
* - `ragQuery` root query field for context-aware LLM answers
|
|
164
|
+
* - `embedText` root query field for text-to-vector conversion
|
|
165
|
+
* @default false
|
|
166
|
+
*/
|
|
167
|
+
enableRag?: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Default configuration for RAG queries.
|
|
170
|
+
* Individual queries can override these values.
|
|
171
|
+
*/
|
|
172
|
+
ragDefaults?: RagDefaults;
|
|
173
|
+
}
|