Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/ai/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function createSystemPrompt(
currentCellId?: string,
filepaths?: string[],
vectorStoreEnabled: boolean = false,
userSystemPrompt: string = "",
): string {
let prompt = `You are an AI assistant in a collaborative notebook environment.

Expand All @@ -150,6 +151,10 @@ After executing code cells you should review the code and make changes to improv

`;

if (userSystemPrompt) {
prompt += `\n\n${userSystemPrompt}\n`;
}

const vectorStoreExtras =
`IMPORTANT: If you have access to vector store tools (query_documents, find_mounted_file,
list_indexed_files),
Expand Down Expand Up @@ -529,6 +534,7 @@ export async function executeAI(
sessionId: string,
notebookTools: NotebookTool[] = [],
maxIterations: number = 10,
userSystemPrompt: string = "",
): Promise<{ success: boolean; error?: string }> {
const {
cell,
Expand Down Expand Up @@ -587,6 +593,7 @@ export async function executeAI(
cell.id,
extractedFilePaths,
isVectorStoreIndexingEnabled(),
userSystemPrompt,
),
prompt,
);
Expand Down
14 changes: 14 additions & 0 deletions packages/pyodide-runtime-agent/src/pyodide-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
isTextBasedMimeType,
KNOWN_MIME_TYPES,
type KnownMimeType,
tables,
} from "@runt/schema";
import {
getBootstrapPackages as _getBootstrapPackages,
Expand Down Expand Up @@ -551,13 +552,26 @@ export class PyodideRuntimeAgent extends RuntimeAgent {

try {
const maxIterations = this.config.aiMaxIterations;

let userSystemPrompt = this.store.query(
tables.notebookMetadata
.select()
.where({ key: "user_system_prompt" })
.first({ fallback: () => "" }),
);

if (typeof userSystemPrompt !== "string") {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this check feels weird but the datatype means it can be a string

userSystemPrompt = userSystemPrompt.value;
}

return await executeAI(
aiContext,
notebookContext,
this.store,
this.config.sessionId,
notebookTools,
maxIterations,
userSystemPrompt,
);
} finally {
this.currentAIExecution = null;
Expand Down