Remix
Learn how to integrate Monacopilot with Remix.
Installation
First, install the required dependencies:
bash
npm install monacopilot @monaco-editor/reactbash
yarn add monacopilot @monaco-editor/reactbash
pnpm add monacopilot @monaco-editor/reactbash
bun add monacopilot @monaco-editor/reactImplementation
API Route
Create a route handler for completions:
tsx
import {json, type ActionFunctionArgs} from '@remix-run/node';
import {CompletionCopilot, type CompletionRequestBody} from 'monacopilot';
const copilot = new CompletionCopilot(process.env.MISTRAL_API_KEY, {
provider: 'mistral',
model: 'codestral',
});
export const action = async ({request}: ActionFunctionArgs) => {
const body: CompletionRequestBody = await request.json();
const completion = await copilot.complete({body});
return json(completion);
};Editor Component
Create a Editor component in:
tsx
import {useEffect, useRef} from 'react';
import MonacoEditor from '@monaco-editor/react';
import {
registerCompletion,
type CompletionRegistration,
type Monaco,
type StandaloneCodeEditor,
} from 'monacopilot';
export default function Editor() {
const completionRef = useRef<CompletionRegistration | null>(null);
const handleMount = (editor: StandaloneCodeEditor, monaco: Monaco) => {
completionRef.current = registerCompletion(monaco, editor, {
endpoint: '/code-completion',
language: 'javascript',
});
};
useEffect(() => {
return () => {
completionRef.current?.deregister();
};
}, []);
return <MonacoEditor language="javascript" onMount={handleMount} />;
}Page Component
Create your page component:
tsx
import Editor from '~/components/Editor';
export default function Index() {
return (
<main className="h-screen w-screen">
<h1>Monacopilot Remix Example</h1>
<Editor />
</main>
);
}Environment Variables
Create a .env file in your project root:
bash
MISTRAL_API_KEY=your_mistral_api_key_hereObtain your Mistral API Key from the Mistral AI Console.
Monacopilot supports multiple AI providers and models. For details on available options and configuration, see the Changing the Provider and Model documentation.
Obtain your Mistral API Key from the Mistral AI Console.
Running the Example
- Install dependencies:
bash
npm installbash
yarnbash
pnpm installbash
bun install- Start the development server:
bash
npm run devbash
yarn devbash
pnpm devbash
bun dev- Open
http://localhost:3000in your browser.
You should now see a Monaco Editor with AI-powered completions working!