diff options
| author | Dhravya <[email protected]> | 2024-04-13 01:45:17 -0700 |
|---|---|---|
| committer | Dhravya <[email protected]> | 2024-04-13 01:45:17 -0700 |
| commit | ad422c6b6636d32c56e210705a89c9dc2cc5de8d (patch) | |
| tree | 9d3d89f66f3c7e70336e1302c7f95a2cce17c2e2 /apps | |
| parent | comment extension dialog for now (diff) | |
| download | supermemory-ad422c6b6636d32c56e210705a89c9dc2cc5de8d.tar.xz supermemory-ad422c6b6636d32c56e210705a89c9dc2cc5de8d.zip | |
switch to cloudfalre
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/cf-ai-backend/src/routes/chat.ts | 55 | ||||
| -rw-r--r-- | apps/extension/manifest.json | 2 | ||||
| -rw-r--r-- | apps/extension/src/components/FilterCombobox.tsx | 4 |
3 files changed, 37 insertions, 24 deletions
diff --git a/apps/cf-ai-backend/src/routes/chat.ts b/apps/cf-ai-backend/src/routes/chat.ts index 7603667f..75c7b426 100644 --- a/apps/cf-ai-backend/src/routes/chat.ts +++ b/apps/cf-ai-backend/src/routes/chat.ts @@ -2,6 +2,8 @@ import { Content, GenerativeModel } from '@google/generative-ai'; import { OpenAIEmbeddings } from '../OpenAIEmbedder'; import { CloudflareVectorizeStore } from '@langchain/cloudflare'; import { Request } from '@cloudflare/workers-types'; +import { AiTextGenerationOutput } from '@cloudflare/ai/dist/ai/tasks/text-generation'; +import { Ai } from '@cloudflare/ai'; export async function POST(request: Request, _: CloudflareVectorizeStore, embeddings: OpenAIEmbeddings, model: GenerativeModel, env?: Env) { const queryparams = new URL(request.url).searchParams; @@ -112,28 +114,39 @@ export async function POST(request: Request, _: CloudflareVectorizeStore, embedd }, ] as Content[]; - const chat = model.startChat({ - history: [...defaultHistory, ...(body.chatHistory ?? [])], - }); + // const chat = model.startChat({ + // history: [...defaultHistory, ...(body.chatHistory ?? [])], + // }); const prompt = `Context:\n${preparedContext ?? ''}\n\nQuestion: ${query}\nAnswer:`; - const output = await chat.sendMessageStream(prompt); - - const response = new Response( - new ReadableStream({ - async start(controller) { - const converter = new TextEncoder(); - for await (const chunk of output.stream) { - const chunkText = await chunk.text(); - const encodedChunk = converter.encode('data: ' + JSON.stringify({ response: chunkText }) + '\n\n'); - controller.enqueue(encodedChunk); - } - const doneChunk = converter.encode('data: [DONE]'); - controller.enqueue(doneChunk); - controller.close(); - }, - }), - ); - return response; + // const output = await chat.sendMessageStream(prompt); + + // const response = new Response( + // new ReadableStream({ + // async start(controller) { + // const converter = new TextEncoder(); + // for await (const chunk of output.stream) { + // const chunkText = await chunk.text(); + // const encodedChunk = converter.encode('data: ' + JSON.stringify({ response: chunkText }) + '\n\n'); + // controller.enqueue(encodedChunk); + // } + // const doneChunk = converter.encode('data: [DONE]'); + // controller.enqueue(doneChunk); + // controller.close(); + // }, + // }), + // ); + // return response; + const ai = new Ai(env?.AI); + const output: AiTextGenerationOutput = (await ai.run('@hf/thebloke/mistral-7b-instruct-v0.1-awq', { + prompt, + stream: true, + })) as ReadableStream; + + return new Response(output, { + headers: { + 'content-type': 'text/event-stream', + }, + }); } diff --git a/apps/extension/manifest.json b/apps/extension/manifest.json index 561ca8fe..5cf05298 100644 --- a/apps/extension/manifest.json +++ b/apps/extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "SuperMemory", - "version": "1.0.0", + "version": "2.0.0", "action": { "default_popup": "index.html" }, diff --git a/apps/extension/src/components/FilterCombobox.tsx b/apps/extension/src/components/FilterCombobox.tsx index f6215c03..5467655b 100644 --- a/apps/extension/src/components/FilterCombobox.tsx +++ b/apps/extension/src/components/FilterCombobox.tsx @@ -62,7 +62,7 @@ export function FilterSpaces({ <div className="anycontext-flex anycontext-flex-wrap anycontext-gap-1 anycontext-text-sm anycontext-"> {selectedSpaces.map((spaceid) => { const space = spaces.find((s) => s.id === spaceid)!; - return <SpaceItem {...space} key={spaceid} onRemove={() => {}} />; + return <SpaceItem {...space} key={spaceid} />; })} </div> ); @@ -143,7 +143,7 @@ export function FilterSpaces({ ); } -function SpaceItem({ name, onRemove }: { onRemove: () => void } & Space) { +function SpaceItem({ name }: Space) { return ( <div className="anycontext-flex anycontext-justify-center anycontext-items-center anycontext-gap-2 anycontext-p-1 anycontext-pl-2 anycontext-pr-3 anycontext-rounded-full anycontext-bg-black/5 dark:anycontext-bg-white/5 anycontext-border-white/20 dark:anycontext-border-black/20 border"> <button className="anycontext-flex hover:anycontext-bg-transparent anycontext-justify-center anycontext-scale-110 anycontext-items-center focus-visible:anycontext-outline-none anycontext-rounded-full anycontext-w-3 anycontext-bg-black/5 dark:anycontext-bg-white/5 anycontext-h-3 anycontext-text-transparent hover:anycontext-text-black dark:hover:anycontext-text-white"> |