-
Notifications
You must be signed in to change notification settings - Fork 16
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
[Prototype] Self-hosted CodeLlama LLM for code autocompletion #576
base: main
Are you sure you want to change the base?
Changes from 3 commits
e1548fe
5e9276c
1974f45
33951f4
6fb6b31
e2f24be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { monaco } from "react-monaco-editor"; | ||
import { trpcProxyClient } from "./trpc"; | ||
|
||
export class llamaInlineCompletionProvider | ||
implements monaco.languages.InlineCompletionsProvider | ||
{ | ||
private readonly podId: string; | ||
private readonly editor: monaco.editor.IStandaloneCodeEditor; | ||
private isFetchingSuggestions: boolean; // Flag to track if a fetch operation is in progress | ||
|
||
constructor(podId: string, editor: monaco.editor.IStandaloneCodeEditor) { | ||
this.podId = podId; | ||
this.editor = editor; | ||
this.isFetchingSuggestions = false; // Initialize the flag | ||
} | ||
|
||
private async provideSuggestions(input: string) { | ||
if (/^\s*$/.test(input || " ")) { | ||
return ""; | ||
} | ||
|
||
const suggestion = await trpcProxyClient.spawner.codeAutoComplete.mutate({ | ||
code: input, | ||
podId: this.podId, | ||
}); | ||
return suggestion; | ||
} | ||
public async provideInlineCompletions( | ||
model: monaco.editor.ITextModel, | ||
position: monaco.IPosition, | ||
context: monaco.languages.InlineCompletionContext, | ||
token: monaco.CancellationToken | ||
): Promise<monaco.languages.InlineCompletions | undefined> { | ||
if (!this.editor.hasTextFocus()) { | ||
return; | ||
} | ||
if (token.isCancellationRequested) { | ||
return; | ||
} | ||
|
||
if (!this.isFetchingSuggestions) { | ||
this.isFetchingSuggestions = true; | ||
try { | ||
const suggestion = await this.provideSuggestions( | ||
model.getValue() || " " | ||
); | ||
|
||
return { | ||
items: [ | ||
{ | ||
insertText: suggestion, | ||
range: new monaco.Range( | ||
position.lineNumber, | ||
position.column, | ||
position.lineNumber, | ||
position.column | ||
), | ||
}, | ||
], | ||
}; | ||
} finally { | ||
this.isFetchingSuggestions = false; | ||
} | ||
} | ||
} | ||
|
||
handleItemDidShow?( | ||
completions: monaco.languages.InlineCompletions<monaco.languages.InlineCompletion>, | ||
item: monaco.languages.InlineCompletion | ||
): void {} | ||
|
||
freeInlineCompletions( | ||
completions: monaco.languages.InlineCompletions<monaco.languages.InlineCompletion> | ||
): void {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
import { createTRPCReact } from "@trpc/react-query"; | ||
import { | ||
createTRPCReact, | ||
createTRPCProxyClient, | ||
httpBatchLink, | ||
} from "@trpc/react-query"; | ||
import type { AppRouter } from "../../../api/src/spawner/trpc"; | ||
export const trpc = createTRPCReact<AppRouter>(); | ||
let remoteUrl; | ||
|
||
if (import.meta.env.DEV) { | ||
remoteUrl = `localhost:4000`; | ||
} else { | ||
remoteUrl = `${window.location.hostname}:${window.location.port}`; | ||
} | ||
export const trpcProxyClient = createTRPCProxyClient<AppRouter>({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have a trpc client in App.tsx. You can access the client in // MyMonaco.tsx
function MyMonaco() {
...
const { client } = trpc.useUtils();
const llamaCompletionProvider = new llamaInlineCompletionProvider(
id,
editor,
client
);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A second thought: since the copilot is already a REST API, and we are not going to further customize it or add authentication to this Desktop app, let's directly call the REST API in the frontend. The trpc is preferred in the cloud app. |
||
links: [ | ||
httpBatchLink({ | ||
url: `http://${remoteUrl}/trpc`, | ||
}), | ||
], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd revert this print information, because people may choose to run CodePod without copilot server, and this info is misleading. Just be silent should be fine.