From 0d705eb11efef23ed9940a797bbd60057bd3365d Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 7 Aug 2023 11:11:57 -0500 Subject: [PATCH] fix(blog): wrap code to fit without horizontal scroll --- .../2023-08-07-hugging-face-supabase.mdx | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/www/_blog/2023-08-07-hugging-face-supabase.mdx b/apps/www/_blog/2023-08-07-hugging-face-supabase.mdx index eb801f55fa1..2365829d325 100644 --- a/apps/www/_blog/2023-08-07-hugging-face-supabase.mdx +++ b/apps/www/_blog/2023-08-07-hugging-face-supabase.mdx @@ -90,6 +90,7 @@ AI/ML is primarily the domain of the Python community, but thanks to some amazin Let’s step through a small demo where we accept some text, convert it into an embedding, and then store it in our Postgres database. You can create a new function with supabase functions new embed and fill it with the following code snippet: +{/* prettier-ignore */} ```ts import { serve } from 'https://deno.land/std@0.168.0/http/server.ts' import { env, pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.5.0' @@ -99,10 +100,16 @@ import { createClient } from 'https://esm.sh/@supabase/supabase-js@2' env.useBrowserCache = false env.allowLocalModels = false -const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key') +const supabase = createClient( + 'https://xyzcompany.supabase.co', + 'public-anon-key', +) // Construct pipeline outside of serve for faster warm starts -const pipe = await pipeline('feature-extraction', 'Supabase/gte-small') +const pipe = await pipeline( + 'feature-extraction', + 'Supabase/gte-small', +) // Deno Handler serve(async (req) => { @@ -118,10 +125,15 @@ serve(async (req) => { const embedding = Array.from(output.data) // Store the embedding - const { data, error } = await supabase.from('collections').insert({ embedding }) + const { data, error } = await supabase + .from('collections') + .insert({ embedding }) // Return the embedding - return new Response({ new_row: data }, { headers: { 'Content-Type': 'application/json' } }) + return new Response( + { new_row: data }, + { headers: { 'Content-Type': 'application/json' } }, + ) }) ```