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

fix: refactor Supabase AI API #273

Merged
merged 3 commits into from
Feb 20, 2024
Merged

fix: refactor Supabase AI API #273

merged 3 commits into from
Feb 20, 2024

Conversation

laktek
Copy link
Contributor

@laktek laktek commented Feb 19, 2024

What kind of change does this PR introduce?

Modified to initialize session once and reuse internal session/tokenizer.

esm_entry_point = "ext:sb_ai/ai.js",
esm = ["ai.js",]
);

fn run_gte(state: &mut OpState, prompt: String) -> Result<Vec<f32>, Error> {
fn init_gte(state: &mut OpState) -> Result<(), Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be interesting if we can make this op async and have the whole logic of initialization (if it's heavy) on a different thread. (I'm thinking especially because models can be large)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andreespirela Thanks for the suggestion! Refactored the init to run on a tokio task (ie. green thread)

crates/sb_ai/lib.rs Outdated Show resolved Hide resolved
Deno.serve(async (req: Request) => {
const params = new URL(req.url).searchParams;
const input = params.get('text');
const output = Supabase_UNSTABLE.ai.runModel('gte', input);
const output = model.run(input);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also wonder if the run op should be async...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Copy link
Collaborator

@andreespirela andreespirela left a comment

Choose a reason for hiding this comment

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

Lgtm!

@laktek laktek merged commit f5d2d18 into main Feb 20, 2024
3 checks passed
@laktek laktek deleted the refactor-sb-ai branch February 20, 2024 23:41
Copy link

🎉 This PR is included in version 1.36.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants