Skip to content

Commit

Permalink
Merge pull request #1450 from mito-ds/q-and-a-mode-2
Browse files Browse the repository at this point in the history
mito-ai: add back q&a chat
  • Loading branch information
ngafar authored Dec 30, 2024
2 parents 6a4d9b2 + 4c892b1 commit c277316
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import OpenAI from "openai";
import { IVariableManager } from "../VariableManager/VariableManagerPlugin";
import { INotebookTracker } from '@jupyterlab/notebook';
import { getActiveCellCode, getActiveCellID, getCellCodeByID } from "../../utils/notebook";
import { createBasicPrompt } from "../../prompts/BasicPrompt";
import { createChatPrompt } from "../../prompts/ChatPrompt";
import { createErrorPrompt, removeInnerThoughtsFromMessage } from "../../prompts/SmartDebugPrompt";
import { createExplainCodePrompt } from "../../prompts/ExplainCodePrompt";

Expand Down Expand Up @@ -92,7 +92,7 @@ export class ChatHistoryManager {

const aiOptimizedMessage: OpenAI.Chat.ChatCompletionMessageParam = {
role: 'user',
content: createBasicPrompt(variables, activeCellCode || '', input)
content: createChatPrompt(variables, activeCellCode || '', input)
};

this.history.displayOptimizedChatHistory.push(
Expand All @@ -117,7 +117,7 @@ export class ChatHistoryManager {

const aiOptimizedMessage: OpenAI.Chat.ChatCompletionMessageParam = {
role: 'user',
content: createBasicPrompt(this.variableManager.variables, activeCellCode || '', newContent)
content: createChatPrompt(this.variableManager.variables, activeCellCode || '', newContent)
};

// Update the message at the specified index
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Variable } from "../Extensions/VariableManager/VariableInspector";

export function createBasicPrompt(
export function createChatPrompt(
variables: Variable[],
activeCellCode: string,
input: string
): string {
const prompt = `You are an expert python programmer writing a script in a Jupyter notebook. You are given a set of variables, existing code, and a task.
Respond with the updated active code cell and a short explanation of the changes you made.
There are two possible types of responses you might give:
1. Code Update: If the task requires modifying or extending the existing code, respond with the updated active code cell and a short explanation of the changes made.
2. Explanation/Information: If the task does not require a code update, provide an explanation, additional information about a package, method, or general programming question, without writing any code. Keep your response concise and to the point.
When responding:
- Do not use the word "I"
Expand Down Expand Up @@ -36,7 +38,6 @@ sales_df = pd.read_csv('./sales.csv')
Your task: convert the transaction_date column to datetime and then multiply the total_price column by the sales_multiplier.
Output:
\`\`\`python
import pandas as pd
sales_df = pd.read_csv('./sales.csv')
Expand All @@ -49,10 +50,9 @@ Converted the \`transaction_date\` column to datetime using the built-in pd.to_d
</Example>
Defined Variables:
${variables?.map(variable => `${JSON.stringify(variable, null, 2)}\n`).join('')}
Code in the active code cell:
Code in the active code cell:
\`\`\`python
${activeCellCode}
\`\`\`
Expand Down

0 comments on commit c277316

Please sign in to comment.