diff --git a/src/components/Settings/Sections/ChatSettings.tsx b/src/components/Settings/Sections/ChatSettings.tsx index 302b4e1e..e43d9878 100644 --- a/src/components/Settings/Sections/ChatSettings.tsx +++ b/src/components/Settings/Sections/ChatSettings.tsx @@ -24,19 +24,22 @@ const ChatSettings = () => { ) => { event.preventDefault() const target = event.target as HTMLFormElement - + const apiKeyValue = target.openAiApiKey.value const baseurlValue = target.openAiBaseUrl.value if (OpenAiApiKeyInputRef.current) { - const isOpenAiKeyValid: boolean = await validateApiKey(apiKeyValue, baseurlValue) + const isOpenAiKeyValid: boolean = await validateApiKey( + apiKeyValue, + baseurlValue, + ) if (isOpenAiKeyValid) { setSettings({ ...settings, chat: { ...chatSettings, openAIKey: apiKeyValue, - openAiBaseUrl: baseurlValue , + openAiBaseUrl: baseurlValue, }, }) } @@ -83,11 +86,11 @@ const ChatSettings = () => { type={showPassword ? 'text' : 'password'} className="input" /> - diff --git a/src/components/Sidebar/auth/index.tsx b/src/components/Sidebar/auth/index.tsx index 63398ab0..f474ff88 100644 --- a/src/components/Sidebar/auth/index.tsx +++ b/src/components/Sidebar/auth/index.tsx @@ -18,9 +18,11 @@ const Auth = () => { e.preventDefault() const data = new FormData(e.currentTarget) const key = data.get('openAiKey') as string | null - const openAiBaseUrl = data.get('openAiBaseUrl') as string | "https://api.openai.com/v1" + const openAiBaseUrl = data.get('openAiBaseUrl') as + | string + | 'https://api.openai.com/v1' - if (key && (await validateApiKey(key,openAiBaseUrl))) { + if (key && (await validateApiKey(key, openAiBaseUrl))) { setSettings((prev) => ({ ...prev, chat: { @@ -62,9 +64,9 @@ const Auth = () => { data-error={error ? 'true' : undefined} className="cdx-mt-4 cdx-text-center cdx-p-2 cdx-w-full cdx-rounded-md cdx-border dark:cdx-border-neutral-600 cdx-border-neutral-200 dark:cdx-bg-neutral-800/90 cdx-bg-neutral-200/90 focus:cdx-outline-none focus:cdx-ring-2 focus:cdx-ring-blue-900 focus:cdx-ring-opacity-50 data-[error]:cdx-text-red-500" /> - diff --git a/src/components/Sidebar/chat/ChatList.tsx b/src/components/Sidebar/chat/ChatList.tsx index 7175727b..155a4f13 100644 --- a/src/components/Sidebar/chat/ChatList.tsx +++ b/src/components/Sidebar/chat/ChatList.tsx @@ -109,4 +109,3 @@ const ChatList = ({ } export default ChatList - diff --git a/src/components/Sidebar/chat/index.tsx b/src/components/Sidebar/chat/index.tsx index ded39cc1..079c387a 100644 --- a/src/components/Sidebar/chat/index.tsx +++ b/src/components/Sidebar/chat/index.tsx @@ -23,7 +23,7 @@ const Chat = ({ settings }: ChatProps) => { apiKey: settings.chat.openAIKey!, mode: settings.chat.mode, systemPrompt: SYSTEM_PROMPT, - baseURL: settings.chat.openAiBaseUrl || "", + baseURL: settings.chat.openAiBaseUrl || '', }) useEffect(() => { diff --git a/src/hooks/useChatCompletion.ts b/src/hooks/useChatCompletion.ts index ca017db3..f717e973 100644 --- a/src/hooks/useChatCompletion.ts +++ b/src/hooks/useChatCompletion.ts @@ -37,7 +37,7 @@ export const useChatCompletion = ({ apiKey, mode, systemPrompt, - baseURL + baseURL, }: UseChatCompletionProps) => { const { messages, @@ -58,7 +58,7 @@ export const useChatCompletion = ({ openAIApiKey: apiKey, modelName: model, configuration: { - baseURL: baseURL, + baseURL: baseURL, }, temperature: Number(mode), maxTokens: 4_096, @@ -97,7 +97,12 @@ export const useChatCompletion = ({ */ let matchedContext: string | undefined if (context) { - matchedContext = await getMatchedContent(message.text, context, apiKey, baseURL) + matchedContext = await getMatchedContent( + message.text, + context, + apiKey, + baseURL, + ) } const expandedQuery = matchedContext diff --git a/src/lib/getMatchedContent.ts b/src/lib/getMatchedContent.ts index 0bab0b6a..10f37804 100644 --- a/src/lib/getMatchedContent.ts +++ b/src/lib/getMatchedContent.ts @@ -11,9 +11,9 @@ export const getMatchedContent = async ( query: string, context: string, apiKey: string, - baseURL: string + baseURL: string, ) => { - const vectorStore = await getContextVectorStore(context, apiKey,baseURL) + const vectorStore = await getContextVectorStore(context, apiKey, baseURL) const retriever = vectorStore.asRetriever() const relevantDocs = await retriever.getRelevantDocuments(query) return relevantDocs.map((doc) => doc.pageContent).join('\n') @@ -24,15 +24,17 @@ export const getMatchedContent = async ( * from the context. It caches the vector store in the local storage * for faster retrieval */ -const getContextVectorStore = async (context: string, apiKey: string, baseURL: string) => { - const embeddings = new OpenAIEmbeddings( - { - openAIApiKey: apiKey , - configuration: { - baseURL: baseURL, - }, - } - ) +const getContextVectorStore = async ( + context: string, + apiKey: string, + baseURL: string, +) => { + const embeddings = new OpenAIEmbeddings({ + openAIApiKey: apiKey, + configuration: { + baseURL: baseURL, + }, + }) const hashKey = `SYNCIA_STORE_EMBEDDINGS_${await createSHA256Hash(context)}` const memoryVectors: [] | null = JSON.parse( localStorage.getItem(hashKey) || 'null', diff --git a/src/lib/getScreenshotImage.ts b/src/lib/getScreenshotImage.ts index 32b80a4c..c76b36d5 100644 --- a/src/lib/getScreenshotImage.ts +++ b/src/lib/getScreenshotImage.ts @@ -108,15 +108,15 @@ export const getScreenshotImage = async (): Promise => { }) // Crop the screenshot to the user's selection - let finalStartX = startX < endX ? startX : endX - let finalStaryY = startY < endY ? startY : endY + const finalStartX = startX < endX ? startX : endX + const finalStaryY = startY < endY ? startY : endY ctx.drawImage( image, finalStartX * window.devicePixelRatio, finalStaryY * window.devicePixelRatio, - (canvas.width) * window.devicePixelRatio, - (canvas.height) * window.devicePixelRatio, + canvas.width * window.devicePixelRatio, + canvas.height * window.devicePixelRatio, 0, 0, canvas.width, diff --git a/src/lib/validApiKey.ts b/src/lib/validApiKey.ts index 15d61e38..7269b533 100644 --- a/src/lib/validApiKey.ts +++ b/src/lib/validApiKey.ts @@ -3,11 +3,14 @@ import { ChatOpenAI } from '@langchain/openai' export const validateApiKey = async ( openAIApiKey: string, - baseURL: string + baseURL: string, ): Promise => { - const model = new ChatOpenAI({ openAIApiKey:openAIApiKey,configuration: { - baseURL: baseURL || "https://api.openai.com/v1", - },}) + const model = new ChatOpenAI({ + openAIApiKey: openAIApiKey, + configuration: { + baseURL: baseURL || 'https://api.openai.com/v1', + }, + }) try { await model.invoke([new HumanMessage('Say Ok')]) return true