Skip to content

Commit f0cc189

Browse files
committed
PromptFineTuning
1 parent b455d54 commit f0cc189

File tree

2 files changed

+46
-36
lines changed

2 files changed

+46
-36
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createOpenAI } from '@ai-sdk/openai';
21
import { codeBlock } from '@blocknote/code-block';
32
import {
43
BlockNoteSchema,
@@ -10,24 +9,20 @@ import * as locales from '@blocknote/core/locales';
109
import { BlockNoteView } from '@blocknote/mantine';
1110
import '@blocknote/mantine/style.css';
1211
import { useCreateBlockNote } from '@blocknote/react';
13-
import {
14-
AIMenuController,
15-
createAIExtension,
16-
createBlockNoteAIClient,
17-
} from '@blocknote/xl-ai';
12+
import { AIMenuController } from '@blocknote/xl-ai';
1813
import { en as aiEn } from '@blocknote/xl-ai/locales';
1914
import '@blocknote/xl-ai/style.css';
2015
import { HocuspocusProvider } from '@hocuspocus/provider';
2116
import { useEffect } from 'react';
2217
import { useTranslation } from 'react-i18next';
2318
import * as Y from 'yjs';
2419

25-
import { fetchAPI } from '@/api';
2620
import { Box, TextErrors } from '@/components';
2721
import { Doc, useIsCollaborativeEditable } from '@/docs/doc-management';
2822
import { useAuth } from '@/features/auth';
2923

3024
import { useHeadings, useUploadFile, useUploadStatus } from '../hook/';
25+
import { useAI } from '../hook/useAI';
3126
import useSaveDoc from '../hook/useSaveDoc';
3227
import { useEditorStore } from '../stores';
3328
import { cssEditor } from '../styles';
@@ -67,31 +62,13 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
6762
const lang = i18n.resolvedLanguage;
6863

6964
const { uploadFile, errorAttachment } = useUploadFile(doc.id);
65+
const aiExtension = useAI(doc.id);
7066

7167
const collabName = readOnly
7268
? 'Reader'
7369
: user?.full_name || user?.email || t('Anonymous');
7470
const showCursorLabels: 'always' | 'activity' | (string & {}) = 'activity';
7571

76-
const client = createBlockNoteAIClient({
77-
baseURL: ``,
78-
apiKey: '',
79-
});
80-
const openai = createOpenAI({
81-
...client.getProviderSettings('openai'),
82-
fetch: (input, init) => {
83-
// Create a new headers object without the Authorization header
84-
const headers = new Headers(init?.headers);
85-
headers.delete('Authorization');
86-
87-
return fetchAPI(`documents/${doc.id}/ai-proxy/`, {
88-
...init,
89-
headers,
90-
});
91-
},
92-
});
93-
const model = openai.chat('neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8');
94-
9572
const editor: DocsBlockNoteEditor = useCreateBlockNote(
9673
{
9774
codeBlock,
@@ -145,16 +122,7 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
145122
showCursorLabels: showCursorLabels as 'always' | 'activity',
146123
},
147124
dictionary: { ...locales[lang as keyof typeof locales], ai: aiEn },
148-
extensions: [
149-
createAIExtension({
150-
stream: false,
151-
model,
152-
agentCursor: {
153-
name: 'Albert',
154-
color: '#8bc6ff',
155-
},
156-
}),
157-
],
125+
extensions: [aiExtension],
158126
tables: {
159127
splitCells: true,
160128
cellBackgroundColor: true,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { createOpenAI } from '@ai-sdk/openai';
2+
import { createAIExtension, createBlockNoteAIClient } from '@blocknote/xl-ai';
3+
import { useMemo } from 'react';
4+
5+
import { fetchAPI } from '@/api';
6+
7+
import { Doc } from '../../doc-management';
8+
9+
const client = createBlockNoteAIClient({
10+
baseURL: ``,
11+
apiKey: '',
12+
});
13+
14+
export const useAI = (docId: Doc['id']) => {
15+
return useMemo(() => {
16+
const openai = createOpenAI({
17+
...client.getProviderSettings('openai'),
18+
fetch: (input, init) => {
19+
// Create a new headers object without the Authorization header
20+
const headers = new Headers(init?.headers);
21+
headers.delete('Authorization');
22+
23+
return fetchAPI(`documents/${docId}/ai-proxy/`, {
24+
...init,
25+
headers,
26+
});
27+
},
28+
});
29+
const model = openai.chat('neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8');
30+
31+
const extension = createAIExtension({
32+
stream: false,
33+
model,
34+
agentCursor: {
35+
name: 'Albert',
36+
color: '#8bc6ff',
37+
},
38+
});
39+
40+
return extension;
41+
}, [docId]);
42+
};

0 commit comments

Comments
 (0)