Skip to content

[Prototype] Self-hosted CodeLlama LLM for code autocompletion #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add a Sidebar setting to turn on/off Codepod copilot
  • Loading branch information
Sen Wang authored and Sen Wang committed Nov 4, 2023
commit 5e9276c0dcd350655cce6da381ac5e9d500c0f90
28 changes: 19 additions & 9 deletions ui/src/components/MyMonaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ export const MyMonaco = memo<MyMonacoProps>(function MyMonaco({
(state) => state.parseResult[id]?.annotations
);
const showAnnotations = useStore(store, (state) => state.showAnnotations);
const copilotEnabled = useStore(store, (state) => state.copilotEnabled);

const scopedVars = useStore(store, (state) => state.scopedVars);
const updateView = useStore(store, (state) => state.updateView);

Expand All @@ -427,7 +429,23 @@ export const MyMonaco = memo<MyMonacoProps>(function MyMonaco({
} else {
highlightAnnotations(editor, []);
}
}, [annotations, editor, showAnnotations, scopedVars]);

let llamaCompletionProvider; // Define the provider reference
let decompose;
if (copilotEnabled) {
llamaCompletionProvider = new llamaInlineCompletionProvider(id, editor);
decompose = monaco.languages.registerInlineCompletionsProvider(
"python",
llamaCompletionProvider
);
}
return () => {
if (llamaCompletionProvider && !copilotEnabled) {
// Unregister the provider if it exists
decompose();
}
};
}, [annotations, editor, showAnnotations, scopedVars, copilotEnabled]);

if (lang === "racket") {
lang = "scheme";
Expand Down Expand Up @@ -494,14 +512,6 @@ export const MyMonaco = memo<MyMonacoProps>(function MyMonaco({
// // content is value?
// updateGitGutter(editor);
// });
const llamaCompletionProvider = new llamaInlineCompletionProvider(
id,
editor
);
monaco.languages.registerInlineCompletionsProvider(
"python",
llamaCompletionProvider
);
// bind it to the ytext with pod id
if (!codeMap.has(id)) {
throw new Error("codeMap doesn't have pod " + id);
Expand Down
20 changes: 20 additions & 0 deletions ui/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ function SidebarSettings() {
);
const devMode = useStore(store, (state) => state.devMode);
const setDevMode = useStore(store, (state) => state.setDevMode);
const copilotEnabled = useStore(store, (state) => state.copilotEnabled);
const setCopilotEnabled = useStore(store, (state) => state.setCopilotEnabled);

const showLineNumbers = useStore(store, (state) => state.showLineNumbers);
const setShowLineNumbers = useStore(
store,
Expand Down Expand Up @@ -488,6 +491,23 @@ function SidebarSettings() {
/>
</FormGroup>
</Tooltip>
<Tooltip title={"Enable Codepod Copilot"} disableInteractive>
<FormGroup>
<FormControlLabel
control={
<Switch
checked={copilotEnabled}
size="small"
color="warning"
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
setCopilotEnabled(event.target.checked);
}}
/>
}
label="Enable Codepod Copilot"
/>
</FormGroup>
</Tooltip>
{showAnnotations && (
<Stack spacing={0.5}>
<Box className="myDecoration-function">Function Definition</Box>
Expand Down
13 changes: 13 additions & 0 deletions ui/src/lib/store/settingSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface SettingSlice {
setShowAnnotations: (b: boolean) => void;
devMode?: boolean;
setDevMode: (b: boolean) => void;
copilotEnabled?: boolean;
setCopilotEnabled: (b: boolean) => void;
autoRunLayout?: boolean;
setAutoRunLayout: (b: boolean) => void;
contextualZoomParams: Record<any, number>;
Expand Down Expand Up @@ -56,6 +58,17 @@ export const createSettingSlice: StateCreator<MyState, [], [], SettingSlice> = (
// also write to local storage
localStorage.setItem("devMode", JSON.stringify(b));
},

copilotEnabled: localStorage.getItem("copilotEnabled")
? JSON.parse(localStorage.getItem("copilotEnabled")!)
: false,
setCopilotEnabled: (b: boolean) => {
// set it
set({ copilotEnabled: b });
// also write to local storage
localStorage.setItem("copilotEnabled", JSON.stringify(b));
},

autoRunLayout: localStorage.getItem("autoRunLayout")
? JSON.parse(localStorage.getItem("autoRunLayout")!)
: true,
Expand Down