You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -643,7 +598,7 @@ export function AIGenerateCodeCell({
643
598
if(!e.shiftKey)return;
644
599
e.preventDefault();// prevent the default action
645
600
e.stopPropagation();// stop event propagation
646
-
doQuery(prevCodeContents);
601
+
doQuery(contextContent);
647
602
}}
648
603
autoSize={{minRows: 2,maxRows: 6}}
649
604
/>
@@ -657,7 +612,7 @@ export function AIGenerateCodeCell({
657
612
<LLMQueryDropdownButton
658
613
disabled={!prompt.trim()}
659
614
loading={querying}
660
-
onClick={()=>doQuery(prevCodeContents)}
615
+
onClick={()=>doQuery(contextContent)}
661
616
llmTools={llmTools}
662
617
task="Generate using"
663
618
/>
@@ -724,9 +679,10 @@ interface GetInputProps {
724
679
model: LanguageModel;
725
680
position: Position;
726
681
prompt: string;
727
-
prevCodeContents: string;
682
+
contextContent: CellContextContent;
728
683
lang: string;
729
684
kernel_name: string;
685
+
contextRange: [number,number];
730
686
}
731
687
732
688
functiongetInputPrompt(prompt: string): string{
@@ -736,9 +692,10 @@ function getInputPrompt(prompt: string): string {
736
692
functiongetInput({
737
693
frameActions,
738
694
prompt,
739
-
prevCodeContents,
695
+
contextContent,
740
696
lang,
741
697
kernel_name,
698
+
contextRange,
742
699
}: GetInputProps): {
743
700
input: string;
744
701
system: string;
@@ -753,9 +710,30 @@ function getInput({
753
710
);
754
711
return{input: "",system: "",history: []};
755
712
}
756
-
constprevCode=prevCodeContents
757
-
? `The context after which to insert the cells is:\n\n<context>\n${prevCodeContents}\n\</context>\n\n`
758
-
: "";
713
+
714
+
constprevCount=-contextRange[0];// cells before insertion point
715
+
constafterCount=contextRange[1];// cells after insertion point
716
+
717
+
letcontextInfo="";
718
+
719
+
if(contextContent.before||contextContent.after){
720
+
constbeforeCells=
721
+
prevCount>0 ? `${prevCount} cells before` : "no cells before";
722
+
constafterCells=
723
+
afterCount>0 ? `${afterCount} cells after` : "no cells after";
724
+
contextInfo=`Context: The new cell will be inserted with ${beforeCells} and ${afterCells} the insertion point.\n\n`;
725
+
726
+
if(contextContent.before){
727
+
contextInfo+=`Cells BEFORE insertion point:\n<before>\n${contextContent.before}\n</before>\n\n`;
728
+
}
729
+
730
+
if(contextContent.after){
731
+
contextInfo+=`Cells AFTER insertion point:\n<after>\n${contextContent.after}\n</after>\n\n`;
732
+
}
733
+
}else{
734
+
contextInfo=
735
+
"Context: The new cell will be inserted at the beginning or end of the notebook.\n\n";
736
+
}
759
737
760
738
consthistory: Message[]=[
761
739
{role: "user",content: getInputPrompt("Show the value of foo.")},
@@ -766,8 +744,8 @@ function getInput({
766
744
];
767
745
768
746
return{
769
-
input: `${prevCode}${getInputPrompt(prompt)}`,
747
+
input: `${contextInfo}${getInputPrompt(prompt)}`,
770
748
history,
771
-
system: `Create one or more code cells in a Jupyter Notebook.\n\nKernel: "${kernel_name}".\n\nProgramming language: "${lang}".\n\nEach code cell must be wrapped in triple backticks. Do not say what the output will be. Be brief.`,
749
+
system: `Create one or more code cells in a Jupyter Notebook.\n\nKernel: "${kernel_name}".\n\nProgramming language: "${lang}".\n\nThe new cell(s) will be inserted at a specific position in the notebook. Pay attention to the context provided - cells marked as BEFORE come before the insertion point, cells marked as AFTER come after the insertion point.\n\nEach code cell must be wrapped in triple backticks. Do not say what the output will be. Be brief.`,
0 commit comments