Skip to content
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

Use AI-Mask within Worker #19

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

pacoccino
Copy link

@pacoccino pacoccino commented Mar 22, 2024

Replacing previous PR #16

Simple modificiation to support AI-Mask extension as a model provider

I have somehow managed to communicate with the extension from within the web worker, so the computation is not blocking anymore.

Deployed here: https://fully-local-pdf-chatbot-topaz.vercel.app/

TODO:

  • Make it work
  •  keep computation in the worker
  • Support embeddings calculations in AI-Mask

Copy link

vercel bot commented Mar 22, 2024

Someone is attempting to deploy a commit to a Personal Account owned by @jacoblee93 on Vercel.

@jacoblee93 first needs to authorize it.

This was referenced Mar 22, 2024
@jacoblee93
Copy link
Owner

Hey really sorry, I got very busy this weekend. I will look as soon as I am able!

app/worker.ts Outdated
@@ -262,3 +307,7 @@ self.addEventListener("message", async (event: { data: any }) => {
data: "OK",
});
});

(async () => {
aiMaskClient = await AIMaskClient.getWorkerClient()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just await above as well as needed? It doesn't seem like it should be a long running operation?

This seems like it'll cause a race condition?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is supposed to be executed be executed at startup. I added an await on the main thread to verify this is done before doing anything else.

Agree that events in the worker are not safe guarded, could be better implemented but I think it's enough for here.

@jacoblee93
Copy link
Owner

Thank you so much for this!

I downloaded and installed the extension but seem to be getting this:

Screenshot 2024-03-31 at 11 31 12 AM

Am I missing some setup step?

</label>
<div className="my-4 ml-auto mr-auto">
<label htmlFor="modelSelector" className='mr-2'>Model provider</label>
<select id="modelSelector" value={modelProvider} onChange={e => setModelProvider(e.target.value as ModelProvider)} className="p-2 bg-white text-black rounded border">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually love to keep Ollama the default here since it's a lot more effective with the 7B parameter models

And would like to keep it as a toggle too - am thinking toggle + select once Browser Only is selected. But I can make that change later!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set ollama as default but kept select for simplicity

@@ -262,3 +307,7 @@ self.addEventListener("message", async (event: { data: any }) => {
data: "OK",
});
});

(async () => {
aiMaskClient = await AIMaskClient.getWorkerClient();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below, could this just trigger on some initialization event, then send a initializationComplete once this await returns or it times out?

@jacoblee93
Copy link
Owner

Overall this looks fantastic!!!

I can make all the changes I've brought up - the bigger problem is that I just can't seem to run the extension 😅

Am I missing a step?

@pacoccino
Copy link
Author

Hey also sorry for the delay, just got back on this. I went through your comments and fixed most of it. My code was mostly a first throw for a working demo with workers.
About the error you got running the extension, it’s because of some workarounds with WebGPU I use, if you open the extension first and reload the web page it should work. This will get better with Chrome release 124.

I’m actually wondering if there’s really something about this extension, compared to ollama, and if it’s worth continuing efforts. I’d love to hear your take on what such an extension could have that something like ollama won’t.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants