@datagrok/grokky 1.0.4
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/.eslintignore +2 -0
- package/.eslintrc.json +48 -0
- package/CHANGELOG.md +26 -0
- package/README.md +3 -0
- package/css/ai.css +200 -0
- package/detectors.js +9 -0
- package/dist/package-test.js +1738 -0
- package/dist/package-test.js.map +1 -0
- package/dist/package.js +92488 -0
- package/dist/package.js.map +1 -0
- package/dockerfiles/claude-runtime/.dockerignore +4 -0
- package/dockerfiles/claude-runtime/Dockerfile +27 -0
- package/dockerfiles/claude-runtime/container.json +5 -0
- package/dockerfiles/claude-runtime/package-lock.json +448 -0
- package/dockerfiles/claude-runtime/package.json +20 -0
- package/dockerfiles/claude-runtime/src/server.ts +273 -0
- package/dockerfiles/claude-runtime/src/types.ts +37 -0
- package/dockerfiles/claude-runtime/tsconfig.json +15 -0
- package/dockerfiles/mcp-server/Dockerfile +12 -0
- package/dockerfiles/mcp-server/container.json +1 -0
- package/dockerfiles/mcp-server/package-lock.json +1178 -0
- package/dockerfiles/mcp-server/package.json +15 -0
- package/dockerfiles/mcp-server/src/api-client.ts +100 -0
- package/dockerfiles/mcp-server/src/index.ts +155 -0
- package/dockerfiles/mcp-server/tsconfig.json +13 -0
- package/package.json +126 -0
- package/package.png +0 -0
- package/src/ai-panel.ts +174 -0
- package/src/claude-code/claude-panel.ts +34 -0
- package/src/claude-code/claude-runtime-client.ts +148 -0
- package/src/llm-utils/LLM-client.ts +251 -0
- package/src/llm-utils/combined-search.ts +162 -0
- package/src/llm-utils/creds.ts +30 -0
- package/src/llm-utils/db-index-tools.ts +642 -0
- package/src/llm-utils/deepwikiclient.ts +118 -0
- package/src/llm-utils/depr/AI-API-providers/openai-chat-completions-provider.ts +115 -0
- package/src/llm-utils/depr/AI-API-providers/openai-responses-provider.ts +108 -0
- package/src/llm-utils/depr/AI-API-providers/types.ts +106 -0
- package/src/llm-utils/depr/depr.ts +235 -0
- package/src/llm-utils/depr/embeddings.ts +58 -0
- package/src/llm-utils/depr/sql-utils.ts +377 -0
- package/src/llm-utils/indexes/biologics-index.ts +1098 -0
- package/src/llm-utils/indexes/chembl-index.ts +10074 -0
- package/src/llm-utils/indexes/dg-repository-index.ts +266 -0
- package/src/llm-utils/panel.ts +866 -0
- package/src/llm-utils/query-matching.ts +370 -0
- package/src/llm-utils/query-meta-utils.ts +106 -0
- package/src/llm-utils/script-tools.ts +784 -0
- package/src/llm-utils/sql-tools.ts +840 -0
- package/src/llm-utils/storage.ts +201 -0
- package/src/llm-utils/tableview-tools.ts +704 -0
- package/src/llm-utils/ui.ts +315 -0
- package/src/package-api.ts +83 -0
- package/src/package-test.ts +16 -0
- package/src/package.g.ts +122 -0
- package/src/package.ts +275 -0
- package/src/prompt-engine/chatgpt-assistant.ts +257 -0
- package/src/prompt-engine/interfaces.ts +170 -0
- package/src/prompt-engine/prompt-engine.ts +52 -0
- package/src/prompt-engine/rendering-tools.ts +103 -0
- package/src/prompts/is-help-request.ts +26 -0
- package/src/utils.ts +174 -0
- package/src/viewers-ai.ts +67 -0
- package/tsconfig.json +72 -0
- package/webpack.config.js +49 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
|
|
3
|
+
import * as grok from 'datagrok-api/grok';
|
|
4
|
+
import * as ui from 'datagrok-api/ui';
|
|
5
|
+
import * as DG from 'datagrok-api/dg';
|
|
6
|
+
import {askDeepWiki} from './deepwikiclient';
|
|
7
|
+
import {askOpenAIHelp, ModelType} from './LLM-client';
|
|
8
|
+
import {CombinedAISearchAssistant} from './combined-search';
|
|
9
|
+
import {ChatGPTPromptEngine} from '../prompt-engine/prompt-engine';
|
|
10
|
+
import {ChatGptAssistant} from '../prompt-engine/chatgpt-assistant';
|
|
11
|
+
import * as api from '../package-api';
|
|
12
|
+
import {Plan} from '../prompt-engine/interfaces';
|
|
13
|
+
import {AssistantRenderer} from '../prompt-engine/rendering-tools';
|
|
14
|
+
import {fireAIAbortEvent, fireAIPanelToggleEvent} from '../utils';
|
|
15
|
+
import {generateAISqlQueryWithTools} from './sql-tools';
|
|
16
|
+
import {BuiltinDBInfoMeta} from './query-meta-utils';
|
|
17
|
+
import {processTableViewAIRequest} from './tableview-tools';
|
|
18
|
+
import {DBAIPanel, ScriptingAIPanel, TVAIPanel} from './panel';
|
|
19
|
+
import {ClaudeRuntimeClient} from '../claude-code/claude-runtime-client';
|
|
20
|
+
import {generateDatagrokScript} from './script-tools';
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export async function askWiki(question: string, useOpenAI: boolean = true) {
|
|
24
|
+
try {
|
|
25
|
+
const res = !useOpenAI ? (await askDeepWiki(question)) : (await askOpenAIHelp(question));
|
|
26
|
+
const markdown = ui.markdown(res);
|
|
27
|
+
markdown.style.userSelect = 'text';
|
|
28
|
+
return DG.Widget.fromRoot(markdown);
|
|
29
|
+
} catch (error: any) {
|
|
30
|
+
console.error('Error during DeepGROK ask:', error);
|
|
31
|
+
return DG.Widget.fromRoot(ui.divText(`Error during DeepGROK ask: ${error.message}`));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function smartExecution(prompt: string, modelName: string) {
|
|
36
|
+
const gptEngine = ChatGPTPromptEngine.getInstance(modelName);
|
|
37
|
+
const gptAssistant = new ChatGptAssistant(gptEngine);
|
|
38
|
+
|
|
39
|
+
const mainWaitDiv = ui.wait(async () => {
|
|
40
|
+
const resDiv = ui.divV([], 'chatgpt-ask-ai-result');
|
|
41
|
+
const plan = JSON.parse(await api.funcs.getExecutionPlan(prompt)) as Plan;
|
|
42
|
+
const planDiv = AssistantRenderer.renderPlan(plan);
|
|
43
|
+
resDiv.appendChild(planDiv);
|
|
44
|
+
resDiv.appendChild(ui.wait(async () => {
|
|
45
|
+
const result = await gptAssistant.execute(plan);
|
|
46
|
+
const resRen = AssistantRenderer.renderResult(result);
|
|
47
|
+
return resRen;
|
|
48
|
+
}));
|
|
49
|
+
return resDiv;
|
|
50
|
+
});
|
|
51
|
+
return DG.Widget.fromRoot(mainWaitDiv);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// sets up the ui button for the input
|
|
55
|
+
export function setupSearchUI() {
|
|
56
|
+
if (!grok.ai.config.configured) {
|
|
57
|
+
console.warn('LLM API key is not set up. Search UI will not have AI assistance.');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const maxRetries = 10;
|
|
62
|
+
function searchForSearchBox() {
|
|
63
|
+
const searchBoxContainer = document.getElementsByClassName('power-pack-welcome-view')[0];
|
|
64
|
+
if (!searchBoxContainer)
|
|
65
|
+
return null;
|
|
66
|
+
const searchInput = Array.from(searchBoxContainer.getElementsByClassName('power-search-search-everywhere-input'))[0] as HTMLInputElement;
|
|
67
|
+
return searchInput;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function initInput(searchInput: HTMLInputElement) {
|
|
71
|
+
const parent: HTMLElement = searchInput.parentElement!;
|
|
72
|
+
const aiIcon = ui.iconFA('magic', () => { aiCombinedSearch(searchInput.value); }, 'Ask AI');
|
|
73
|
+
aiIcon.style.cursor = 'pointer';
|
|
74
|
+
aiIcon.style.color = 'var(--blue-1)';
|
|
75
|
+
aiIcon.style.marginLeft = '4px';
|
|
76
|
+
aiIcon.style.marginRight = '4px';
|
|
77
|
+
parent.appendChild(aiIcon);
|
|
78
|
+
|
|
79
|
+
const onSearchChanged = () => {
|
|
80
|
+
if (!searchInput.value?.trim())
|
|
81
|
+
aiIcon.style.display = 'none';
|
|
82
|
+
else
|
|
83
|
+
aiIcon.style.display = 'flex';
|
|
84
|
+
};
|
|
85
|
+
searchInput.addEventListener('input', onSearchChanged);
|
|
86
|
+
// set up the enter key listener and modify suggestion
|
|
87
|
+
const searchHelpDiv = document.getElementsByClassName('power-search-help-text-container')[0] as HTMLDivElement;
|
|
88
|
+
if (searchHelpDiv)
|
|
89
|
+
searchHelpDiv.innerText = `Press Enter to grok. ${searchHelpDiv.innerText}`;
|
|
90
|
+
|
|
91
|
+
searchInput.addEventListener('keyup', (event: KeyboardEvent) => {
|
|
92
|
+
if (event.key === 'Enter' && searchInput.value?.trim()) {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
setTimeout(() => aiCombinedSearch(searchInput.value), 400); // timeout needed to allow other enter handlers to run first
|
|
95
|
+
}
|
|
96
|
+
if (searchHelpDiv)
|
|
97
|
+
searchHelpDiv.style.visibility = searchInput.value?.trim().split(' ').length > 1 ? 'visible' : 'hidden';
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
onSearchChanged();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const retries = 0;
|
|
104
|
+
const intervalId = setInterval(() => {
|
|
105
|
+
const searchInput = searchForSearchBox();
|
|
106
|
+
if (searchInput) {
|
|
107
|
+
clearInterval(intervalId);
|
|
108
|
+
initInput(searchInput);
|
|
109
|
+
} else if (retries >= maxRetries) {
|
|
110
|
+
clearInterval(intervalId);
|
|
111
|
+
console.warn('Search input box not found after maximum retries.');
|
|
112
|
+
}
|
|
113
|
+
}, 1000);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function aiCombinedSearch(prompt: string) {
|
|
117
|
+
// hide the menu
|
|
118
|
+
document.querySelector('.d4-menu-popup')?.remove();
|
|
119
|
+
await CombinedAISearchAssistant.instance.searchUI(prompt);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export async function setupAIQueryEditorUI(v: DG.ViewBase, connectionID: string, queryEditorRoot: HTMLElement, setAndRunFunc: (query: string) => void): Promise<boolean> {
|
|
123
|
+
if (!grok.ai.config.configured)
|
|
124
|
+
return false;
|
|
125
|
+
const connection = await grok.dapi.connections.find(connectionID);
|
|
126
|
+
if (!connection) { // should not happen but just in case
|
|
127
|
+
grok.shell.error(`Connection with ID ${connectionID} not found.`);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const allDbInfos = await BuiltinDBInfoMeta.allFromConnection(connection);
|
|
132
|
+
const catalogs = allDbInfos.map((d) => d.name);
|
|
133
|
+
const defaultCatalog = connection.parameters?.['catalog'] ?? connection.parameters?.['db'] ?? catalogs[0] ?? '';
|
|
134
|
+
|
|
135
|
+
const panel = new DBAIPanel(catalogs, defaultCatalog, connectionID, v);
|
|
136
|
+
panel.show();
|
|
137
|
+
|
|
138
|
+
panel.onRunRequest.subscribe(async (args) => {
|
|
139
|
+
ui.setUpdateIndicator(queryEditorRoot, true, 'Grokking Query...', () => { fireAIAbortEvent(); });
|
|
140
|
+
const session = panel.startChatSession();
|
|
141
|
+
try {
|
|
142
|
+
const sqlQuery = await generateAISqlQueryWithTools(args.currentPrompt.prompt, connectionID, {
|
|
143
|
+
catalogName: args.currentPrompt.catalogName,
|
|
144
|
+
oldMessages: args.prevMessages,
|
|
145
|
+
aiPanel: session.session, modelType: panel.getCurrentInputs().model,
|
|
146
|
+
});
|
|
147
|
+
if (sqlQuery && typeof sqlQuery === 'string' && sqlQuery.trim().length > 0)
|
|
148
|
+
setAndRunFunc(sqlQuery);
|
|
149
|
+
} catch (error: any) {
|
|
150
|
+
ui.setUpdateIndicator(queryEditorRoot, false);
|
|
151
|
+
grok.shell.error(`Error during AI query generation`);
|
|
152
|
+
console.error('Error during AI query generation:', error);
|
|
153
|
+
}
|
|
154
|
+
ui.setUpdateIndicator(queryEditorRoot, false);
|
|
155
|
+
session.endSession();
|
|
156
|
+
});
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function runClaudeStreaming(panel: TVAIPanel, userPrompt: string, tableView: DG.TableView) {
|
|
161
|
+
const chatSession = panel.startChatSession();
|
|
162
|
+
const sessionId = panel.sessionId;
|
|
163
|
+
let accumulated = '';
|
|
164
|
+
let toolStatus = '';
|
|
165
|
+
const subs: {unsubscribe: () => void}[] = [];
|
|
166
|
+
const cleanup = () => subs.forEach((s) => s.unsubscribe());
|
|
167
|
+
|
|
168
|
+
const forSession = <T extends {sessionId: string}>(
|
|
169
|
+
source: {subscribe: (cb: (evt: T) => void) => {unsubscribe: () => void}},
|
|
170
|
+
handler: (evt: T) => void,
|
|
171
|
+
) => subs.push(source.subscribe((evt) => {
|
|
172
|
+
if (evt.sessionId === sessionId)
|
|
173
|
+
handler(evt);
|
|
174
|
+
}));
|
|
175
|
+
|
|
176
|
+
const endWithError = (msg: string) => {
|
|
177
|
+
panel.clearStreaming();
|
|
178
|
+
grok.shell.error(msg);
|
|
179
|
+
chatSession.endSession();
|
|
180
|
+
cleanup();
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
const client = ClaudeRuntimeClient.getInstance();
|
|
185
|
+
await client.ensureConnected();
|
|
186
|
+
|
|
187
|
+
chatSession.session.addUiMessage(userPrompt, true);
|
|
188
|
+
|
|
189
|
+
forSession(client.onChunk, (evt) => {
|
|
190
|
+
accumulated += evt.content;
|
|
191
|
+
toolStatus = '';
|
|
192
|
+
panel.updateStreaming(accumulated, chatSession.loader);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
forSession(client.onToolActivity, (evt) => {
|
|
196
|
+
toolStatus = `\n\n---\n**${evt.summary}**`;
|
|
197
|
+
panel.updateStreaming(accumulated + toolStatus, chatSession.loader);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
forSession(client.onToolResult, (evt) => {
|
|
201
|
+
toolStatus = `\n\n---\n\`\`\`\n${evt.content}\n\`\`\``;
|
|
202
|
+
panel.updateStreaming(accumulated + toolStatus, chatSession.loader);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
forSession(client.onFinal, (evt) => {
|
|
206
|
+
panel.finalizeStreaming(evt.content, tableView);
|
|
207
|
+
chatSession.endSession();
|
|
208
|
+
cleanup();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
forSession(client.onError, (evt) => endWithError(`Claude: ${evt.message}`));
|
|
212
|
+
|
|
213
|
+
subs.push(client.onClose.subscribe(() => endWithError('Claude: connection lost')));
|
|
214
|
+
|
|
215
|
+
const prompt = panel.prependViewContext(userPrompt, tableView);
|
|
216
|
+
client.send(sessionId, prompt);
|
|
217
|
+
}
|
|
218
|
+
catch (e: any) {
|
|
219
|
+
panel.clearStreaming();
|
|
220
|
+
grok.shell.error(`Claude runtime: ${e.message}`);
|
|
221
|
+
console.error('Claude runtime error:', e);
|
|
222
|
+
chatSession.endSession();
|
|
223
|
+
cleanup();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export async function setupTableViewAIPanelUI() {
|
|
228
|
+
if (!grok.ai.config.configured)
|
|
229
|
+
return;
|
|
230
|
+
const handleView = (tableView: DG.TableView) => {
|
|
231
|
+
// setup ribbon panel icon
|
|
232
|
+
const iconFse = ui.iconSvg('ai.svg', () => fireAIPanelToggleEvent(tableView), 'Ask AI \n Ctrl+I');
|
|
233
|
+
iconFse.style.width = iconFse.style.height = '18px';
|
|
234
|
+
tableView.setRibbonPanels([...tableView.getRibbonPanels(), [iconFse]]);
|
|
235
|
+
// setup the panel itself
|
|
236
|
+
const panel = new TVAIPanel(tableView);
|
|
237
|
+
panel.hide();
|
|
238
|
+
|
|
239
|
+
// Setup request handler
|
|
240
|
+
panel.onRunRequest.subscribe(async (args) => {
|
|
241
|
+
if (panel.currentEngine === 'Claude') {
|
|
242
|
+
await runClaudeStreaming(panel, args.currentPrompt.prompt, tableView);
|
|
243
|
+
} else {
|
|
244
|
+
const chatSession = panel.startChatSession();
|
|
245
|
+
try {
|
|
246
|
+
await processTableViewAIRequest(
|
|
247
|
+
args.currentPrompt.prompt,
|
|
248
|
+
tableView,
|
|
249
|
+
{
|
|
250
|
+
oldMessages: args.prevMessages,
|
|
251
|
+
aiPanel: chatSession.session,
|
|
252
|
+
modelType: panel.getCurrentInputs().model,
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
} catch (error: any) {
|
|
256
|
+
grok.shell.error('Error during AI table view processing');
|
|
257
|
+
console.error('Error during AI table view processing:', error);
|
|
258
|
+
}
|
|
259
|
+
chatSession.endSession();
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
// also handle already opened views
|
|
264
|
+
Array.from(grok.shell.tableViews).filter((v) => v.dataFrame != null).forEach((view) => {
|
|
265
|
+
handleView(view as DG.TableView);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
grok.events.onViewAdded.subscribe((view) => {
|
|
269
|
+
if (view.type === DG.VIEW_TYPE.TABLE_VIEW)
|
|
270
|
+
handleView(view as DG.TableView);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export async function setupScriptsAIPanelUI() {
|
|
275
|
+
const handleView = (scriptView: DG.ScriptView) => {
|
|
276
|
+
// setup ribbon panel icon
|
|
277
|
+
const iconFse = ui.iconSvg('ai.svg', () => fireAIPanelToggleEvent(scriptView), 'Ask AI \n Ctrl+I');
|
|
278
|
+
iconFse.style.width = iconFse.style.height = '18px';
|
|
279
|
+
scriptView.setRibbonPanels([...scriptView.getRibbonPanels(), [iconFse]]);
|
|
280
|
+
// Setup request handler
|
|
281
|
+
// setup the panel itself
|
|
282
|
+
const panel = new ScriptingAIPanel(scriptView);
|
|
283
|
+
panel.hide();
|
|
284
|
+
panel.onRunRequest.subscribe(async (args) => {
|
|
285
|
+
ui.setUpdateIndicator(scriptView.root, true, 'Vibe-Grokking Script...', () => { fireAIAbortEvent(); });
|
|
286
|
+
const indicator = scriptView.root.querySelector('.d4-update-shadow') as HTMLElement;
|
|
287
|
+
if (indicator)
|
|
288
|
+
indicator.style.zIndex = '1000';
|
|
289
|
+
const session = panel.startChatSession();
|
|
290
|
+
try {
|
|
291
|
+
const res = await generateDatagrokScript(
|
|
292
|
+
args.currentPrompt.prompt,
|
|
293
|
+
panel.getCurrentInputs().language,
|
|
294
|
+
{
|
|
295
|
+
oldMessages: args.prevMessages,
|
|
296
|
+
aiPanel: session.session
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
if (res && res.trim().length > 0)
|
|
300
|
+
scriptView.code = res;
|
|
301
|
+
console.log('Generated script:', res);
|
|
302
|
+
} catch (error: any) {
|
|
303
|
+
grok.shell.error('Error during AI table view processing');
|
|
304
|
+
console.error('Error during AI table view processing:', error);
|
|
305
|
+
}
|
|
306
|
+
ui.setUpdateIndicator(scriptView.root, false);
|
|
307
|
+
session.endSession();
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
grok.events.onViewAdded.subscribe((view) => {
|
|
312
|
+
if (view.type === 'ScriptView')
|
|
313
|
+
setTimeout(() => handleView(view as DG.ScriptView), 500);
|
|
314
|
+
});
|
|
315
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
This file is auto-generated by the grok api command.
|
|
3
|
+
If you notice any changes, please push them to the repository.
|
|
4
|
+
Do not edit this file manually.
|
|
5
|
+
*/
|
|
6
|
+
import * as grok from 'datagrok-api/grok';
|
|
7
|
+
import * as DG from 'datagrok-api/dg';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export namespace funcs {
|
|
11
|
+
export async function init(): Promise<void> {
|
|
12
|
+
return await grok.functions.call('Grokky:Init', {});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function autostart(): Promise<void> {
|
|
16
|
+
return await grok.functions.call('Grokky:Autostart', {});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function combinedLLMSearchProvider(): Promise<any> {
|
|
20
|
+
return await grok.functions.call('Grokky:CombinedLLMSearchProvider', {});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
Get answers from DeepGROK AI assistant based on Datagrok documentation and public code.
|
|
25
|
+
*/
|
|
26
|
+
export async function askHelpLLMProvider(prompt: string ): Promise<any> {
|
|
27
|
+
return await grok.functions.call('Grokky:AskHelpLLMProvider', { prompt });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
Plans and executes function steps to achieve needed results
|
|
32
|
+
*/
|
|
33
|
+
export async function smartChainExecutionProvider(prompt: string ): Promise<any> {
|
|
34
|
+
return await grok.functions.call('Grokky:SmartChainExecutionProvider', { prompt });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
Tries to find a query which has the similar pattern as the prompt user entered and executes it
|
|
39
|
+
*/
|
|
40
|
+
export async function llmSearchQueryProvider(prompt: string ): Promise<any> {
|
|
41
|
+
return await grok.functions.call('Grokky:LlmSearchQueryProvider', { prompt });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function askAIGeneralCached(model: string , systemPrompt: string , prompt: string , schema: any ): Promise<string> {
|
|
45
|
+
return await grok.functions.call('Grokky:AskAIGeneralCached', { model, systemPrompt, prompt, schema });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function ask(question: string ): Promise<string> {
|
|
49
|
+
return await grok.functions.call('Grokky:Ask', { question });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function getExecutionPlan(userGoal: string ): Promise<string> {
|
|
53
|
+
return await grok.functions.call('Grokky:GetExecutionPlan', { userGoal });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function findMatchingPatternQuery(prompt: string ): Promise<string> {
|
|
57
|
+
return await grok.functions.call('Grokky:FindMatchingPatternQuery', { prompt });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function askDocumentationCached(prompt: string ): Promise<string> {
|
|
61
|
+
return await grok.functions.call('Grokky:AskDocumentationCached', { prompt });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function setupAIQueryEditor(view: DG.View , connectionID: string , queryEditorRoot: any , setAndRunFunc: any ): Promise<boolean> {
|
|
65
|
+
return await grok.functions.call('Grokky:SetupAIQueryEditor', { view, connectionID, queryEditorRoot, setAndRunFunc });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function moveMetaToDB(dbName: string ): Promise<void> {
|
|
69
|
+
return await grok.functions.call('Grokky:MoveMetaToDB', { dbName });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function setupVectorStore(): Promise<void> {
|
|
73
|
+
return await grok.functions.call('Grokky:SetupVectorStore', {});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function searchForSomething(): Promise<void> {
|
|
77
|
+
return await grok.functions.call('Grokky:SearchForSomething', {});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function indexDatabaseSchema(): Promise<void> {
|
|
81
|
+
return await grok.functions.call('Grokky:IndexDatabaseSchema', {});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as DG from "datagrok-api/dg";
|
|
2
|
+
import * as grok from 'datagrok-api/grok';
|
|
3
|
+
import { runTests, tests, TestContext } from '@datagrok-libraries/test/src/test';
|
|
4
|
+
|
|
5
|
+
export let _package = new DG.Package();
|
|
6
|
+
export { tests };
|
|
7
|
+
|
|
8
|
+
//name: test
|
|
9
|
+
//input: string category {optional: true}
|
|
10
|
+
//input: string test {optional: true}
|
|
11
|
+
//input: object testContext {optional: true}
|
|
12
|
+
//output: dataframe result
|
|
13
|
+
export async function test(category: string, test: string, testContext: TestContext): Promise<DG.DataFrame> {
|
|
14
|
+
const data = await runTests({ category, test, testContext });
|
|
15
|
+
return DG.DataFrame.fromObjects(data)!;
|
|
16
|
+
}
|
package/src/package.g.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {PackageFunctions} from './package';
|
|
2
|
+
import * as DG from 'datagrok-api/dg';
|
|
3
|
+
|
|
4
|
+
//tags: init
|
|
5
|
+
//meta.role: init
|
|
6
|
+
export async function init() : Promise<void> {
|
|
7
|
+
await PackageFunctions.init();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//tags: autostart
|
|
11
|
+
//meta.role: autostart
|
|
12
|
+
export function autostart() : void {
|
|
13
|
+
PackageFunctions.autostart();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//output: dynamic result
|
|
17
|
+
//meta.role: searchProvider
|
|
18
|
+
export function combinedLLMSearchProvider() : any {
|
|
19
|
+
return PackageFunctions.combinedLLMSearchProvider();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//name: Help
|
|
23
|
+
//description: Get answers from DeepGROK AI assistant based on Datagrok documentation and public code.
|
|
24
|
+
//input: string prompt
|
|
25
|
+
//output: widget result
|
|
26
|
+
//meta.role: aiSearchProvider
|
|
27
|
+
//meta.useWhen: If the user is asking questions about how to do something, how to write the code on platform, how to execute tasks, or any other questions related to Datagrok platform functionalities and capabilities. The tone of the prompt should generally sound like "how do I do this" / "what is this". for example, "what sequence notations are supported?
|
|
28
|
+
export async function askHelpLLMProvider(prompt: string) : Promise<any> {
|
|
29
|
+
return await PackageFunctions.askHelpLLMProvider(prompt);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//name: Execute
|
|
33
|
+
//description: Plans and executes function steps to achieve needed results
|
|
34
|
+
//input: string prompt
|
|
35
|
+
//output: widget result
|
|
36
|
+
//meta.role: aiSearchProvider
|
|
37
|
+
//meta.useWhen: If the prompt looks like a user has a goal to achieve something with concrete input(s), and wants the system to plan and execute a series of steps/functions to achieve that goal. This relates to functions that analyse or mutate data, not get it. for example, adme properties of CHEMBL1234, enumerate some peptide, etc... Also, if the tone of the prompt sounds like "Do something to something", use this function
|
|
38
|
+
export async function smartChainExecutionProvider(prompt: string) : Promise<any> {
|
|
39
|
+
return await PackageFunctions.smartChainExecutionProvider(prompt);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//name: Query
|
|
43
|
+
//description: Tries to find a query which has the similar pattern as the prompt user entered and executes it
|
|
44
|
+
//input: string prompt
|
|
45
|
+
//output: widget result
|
|
46
|
+
//meta.role: aiSearchProvider
|
|
47
|
+
//meta.useWhen: if the prompt suggest that the user is looking for a data table result and the prompt resembles a query pattern. for example, "bioactivity data for shigella" or "compounds similar to aspirin" or first 100 chembl compounds. there should be some parts of user prompt that could match parameters in some query, like shigella, aspirin, first 100 etc. Always use this function when user wants to get the data without any further processing or calculating
|
|
48
|
+
export async function llmSearchQueryProvider(prompt: string) : Promise<any> {
|
|
49
|
+
return await PackageFunctions.llmSearchQueryProvider(prompt);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//input: string model
|
|
53
|
+
//input: string systemPrompt
|
|
54
|
+
//input: string prompt
|
|
55
|
+
//input: dynamic schema
|
|
56
|
+
//output: string result
|
|
57
|
+
//meta.cache: all
|
|
58
|
+
//meta.cache.invalidateOn: 0 0 1 * *
|
|
59
|
+
export async function askAIGeneralCached(model: string, systemPrompt: string, prompt: string, schema?: any) : Promise<string> {
|
|
60
|
+
return await PackageFunctions.askAIGeneralCached(model, systemPrompt, prompt, schema);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//input: string question
|
|
64
|
+
//output: string result
|
|
65
|
+
//meta.cache: all
|
|
66
|
+
//meta.cache.invalidateOn: 0 0 1 * *
|
|
67
|
+
export async function ask(question: string) : Promise<string> {
|
|
68
|
+
return await PackageFunctions.ask(question);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//input: string userGoal
|
|
72
|
+
//output: string result
|
|
73
|
+
//meta.cache: all
|
|
74
|
+
//meta.cache.invalidateOn: 0 0 1 * *
|
|
75
|
+
export async function getExecutionPlan(userGoal: string) : Promise<string> {
|
|
76
|
+
return await PackageFunctions.getExecutionPlan(userGoal);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//input: string prompt
|
|
80
|
+
//output: string result
|
|
81
|
+
//meta.cache: all
|
|
82
|
+
//meta.cache.invalidateOn: 0 0 1 * *
|
|
83
|
+
export async function findMatchingPatternQuery(prompt: string) : Promise<string> {
|
|
84
|
+
return await PackageFunctions.findMatchingPatternQuery(prompt);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//input: string prompt
|
|
88
|
+
//output: string result
|
|
89
|
+
//meta.cache: all
|
|
90
|
+
//meta.cache.invalidateOn: 0 0 1 * *
|
|
91
|
+
export async function askDocumentationCached(prompt: string) : Promise<string> {
|
|
92
|
+
return await PackageFunctions.askDocumentationCached(prompt);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//input: view view
|
|
96
|
+
//input: string connectionID
|
|
97
|
+
//input: dynamic queryEditorRoot
|
|
98
|
+
//input: dynamic setAndRunFunc
|
|
99
|
+
//output: bool result
|
|
100
|
+
export async function setupAIQueryEditor(view: DG.ViewBase, connectionID: string, queryEditorRoot: any, setAndRunFunc: any) : Promise<boolean> {
|
|
101
|
+
return await PackageFunctions.setupAIQueryEditor(view, connectionID, queryEditorRoot, setAndRunFunc);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//input: string dbName { choices: ["biologics","chembl"] }
|
|
105
|
+
export async function moveMetaToDB(dbName: string) : Promise<void> {
|
|
106
|
+
await PackageFunctions.moveMetaToDB(dbName);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//name: setupVectorStore
|
|
110
|
+
export async function setupVectorStore() : Promise<void> {
|
|
111
|
+
await PackageFunctions.setupVectorStore();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//name: searchForSomething
|
|
115
|
+
export async function searchForSomething() : Promise<void> {
|
|
116
|
+
await PackageFunctions.searchForSomething();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//name: indexDatabaseSchema
|
|
120
|
+
export async function indexDatabaseSchema() : Promise<void> {
|
|
121
|
+
await PackageFunctions.indexDatabaseSchema();
|
|
122
|
+
}
|