Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Supabase Edge Functions で最近追加された AI 機能を使ってみた
Search
4geru
May 14, 2024
Technology
670
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Supabase Edge Functions で最近追加された AI 機能を使ってみた
toranoana.deno #16 での登壇資料です。
https://yumenosora.connpass.com/event/316556/
4geru
May 14, 2024
More Decks by 4geru
See All by 4geru
挑戦。 at YOUはどうしてBridgeへ?
4geru
0
10
Rails で Remote MCP サーバーを作った話
4geru
0
610
Rails で Remote MCP サーバーを作った話
4geru
0
18
1ヶ月Vizを眺めた話
4geru
0
33
年齢で見るチームの特徴
4geru
0
35
Boom!ヒーロー!! - ポーズを決めろ!その瞬間、キミは主役のヒーローだ -
4geru
0
74
AIと考える MCP tools の実装
4geru
0
41
AI様、あとは"よしなに"やっといて! 〜MCPサーバ開発「裏」入門〜
4geru
0
75
その物件でホントにいいの君?_第3回_Dify_Studio_ハッカソン
4geru
0
79
Other Decks in Technology
See All in Technology
AIエージェント時代のPlatform as a Product —— テックリードがPdMとして回す発見・導入・計測 / Platform as a Product in the AI Agent Era
toshi0607
1
530
Harness Engineering on Rails
joelq
0
760
GitHub Agentic Workflows を触ってみる
htkym
2
880
Account Factory for Terraformによる 標準化されたアカウント発行の自動化
pensuke628
0
120
Terraformを用いたJamf Pro構成のIaC, GitOps化への挑戦
yukun
0
110
地方移住と都心キャリアの両立は「金・時間・人」のリソースをフル活用すれば実現できる!〜Snowflake女子会 vol.8
snowwmn0824
0
130
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
3
21k
顧客の成果創出とプロダクトの成長を 両立するためのFDE
sansantech
PRO
0
500
あなたの知らないAmazon VPC Route Server/Amazon VPC Route Server you don't know about
masakiokuda
0
160
Coil3を内部実装から読み解く~キャッシュ戦略とAVIF画像の描画〜/nikkei-tech-talk50
nikkei_engineer_recruiting
0
170
AI臭い文章とは何なのか
nasuvitz
36
75k
Claude Designがめちゃくちゃ便利なので使ってほしい
diggymo
0
150
Featured
See All Featured
Designing Experiences People Love
moore
143
24k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
430
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
290
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
A better future with KSS
kneath
240
18k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
960
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Transcript
4VQBCBTF &EHF'VODUJPOTY"* UPSBOPBOBEFOP!HFSV
͛͠Δ!HFSV 9 چ5XJUUFS ɿ!@HFSV ॴଐɿϚωʔϑΥϫʔυ झຯɿ📷🎱🐟🤿✈ ՝֎׆ಈɿ-*/&"1*&YQFSU ࣗݾհ
4VQBCBTFY-*/&#PUͷ૬ੑͷྑ͞ w 4VQBCBTF&EHF'VODUJPOTͷσϓϩΠ͕؆୯ʂ w $-*ૢ࡞ͰσϓϩΠՄೳ w ଞͷαʔόʔϨεϑϨʔϜϫʔΫͱൺͯ6*͕γϯϓϧ w σʔλϕʔεϩάͷத͕ϒϥβ͔Β֬ೝͰ͖Δ w
DPOTPMFMPHͰϩάग़ྗՄೳʢ+40/Ͱ֬ೝՄೳʣ w -*/&#PUͷ6*͔Βͷจࣈྻը૾Ի(14͕ѻ͑Δ w ༷ʑͳใΛೖྗͰ͖Δ
-*/&#PUҎ֎ /FYU 7VF 'MVUUFSFUD αϯϓϧίʔυ͕ͨ͘͞Μ
4VQBCBTF-PWF🩷
Ұ൪͍͍ͱ͜Ζɺ ʂγϯϓϧʂ
ࠓճͷΰʔϧɿ 4VQBCBTF&EHF'VODUJPOT Λ͍ͨ͘ͳΔʂ
4VQBCBTFͷ (" ਖ਼ࣜ൛ϦϦʔε
ੈք֤Ͱ ϛʔτΞοϓ ͕։࠵ʂʂ
4VQBCBTF("8FFL d w 4VQBCBTF͕(" (FOFSBM"WBJMBCJMJUZਖ਼ࣜ ϦϦʔε w "VUIʹಗ໊ϩάΠϯػೳՃ w 4UPSBHF͕4ϓϩτίϧରԠ
w &EHF'VODUJPOT͕"*ωΠςΟϒରԠ w ΠϯσοΫεΞυόΠβʔػೳՃ
4VQBCBTFY"* ͷ
4VQBCBTF("8FFL d w 4VQBCBTF͕(" (FOFSBM"WBJMBCJMJUZਖ਼ࣜ ϦϦʔε w "VUIʹಗ໊ϩάΠϯػೳՃ w 4UPSBHF͕4ϓϩτίϧରԠ
w &EHF'VODUJPOT͕"*ωΠςΟϒରԠ w ΠϯσοΫεΞυόΠβʔػೳՃ
4VQBCBTF"*ػೳͷϦϦʔε #MPH"**OGFSFODFOPXBWBJMBCMFJO4VQBCBTF&EHF'VODUJPOT 8IZZPVTIPVMEVTF&EHF'VODUJPOTGPS"* -MBNBXJUI7FSDFM"*
4VQBCBTF"*ػೳͷϦϦʔε #MPH"**OGFSFODFOPXBWBJMBCMFJO4VQBCBTF&EHF'VODUJPOT &NCFEEJOH"1*Λఏڙ ྨࣅݕࡧ͕͍͢͠Έ --. -MBNB.JTUSBM Λఏڙ $IBU(15ͷΑ͏ͳνϟοτػೳ
4VQBCBTF"*ػೳͷϦϦʔε #MPH"**OGFSFODFOPXBWBJMBCMFJO4VQBCBTF&EHF'VODUJPOT ཁ͕·ͱΊΒΕͨ ͷಈը ϋϯζΦϯελΠϧͷ ͷಈը
"*ؔ࿈ίʔυ ߦͷΈ
--. -MBNB.JTUSBM Λఏڙ $IBU(15ͷΑ͏ͳνϟοτػೳ -MBNBXJUI7FSDFM"*
-MBNBXJUI7FSDFM"* w ·ͩɺϩʔΧϧͷΈରԠ w MMBNB NJTUSBMNPEFMͷΈରԠ w ଞͷNPEFMͰ͖ΔΑ͏ʹܭըத w PMMBNBΛϩʔΧϧͰڥߏங͢Δඞཁ͋Γ
w কདྷతʹ4VQBCBTFͷதʹΈࠐ·ΕΔ༧ఆ
σϞ
1 // / <reference types="https://esm.sh/@supabase/functions-js/src/edge- runtime.d.ts" /> 2 // const
session = new Supabase.ai.Session('mistral') 3 const session = new Supabase.ai.Session('llama2') 4 import { notifyMessage } from './messages.ts' 5 6 Deno.serve(async (req: Request) => { 7 const params = new URL(req.url).searchParams 8 const prompt = params.get('prompt') ?? '' 9 notifyMessage(`user prompt: ${prompt}`) 10 11 // Get the output as a stream 12 const output = await session.run(prompt, { stream: true }) NPEFMͷઃఆ͕؆୯
1 // / <reference types="https://esm.sh/@supabase/functions-js/src/edge- runtime.d.ts" /> 2 // const
session = new Supabase.ai.Session('mistral') 3 const session = new Supabase.ai.Session('llama2') 4 import { notifyMessage } from './messages.ts' 5 6 Deno.serve(async (req: Request) => { 7 const params = new URL(req.url).searchParams 8 const prompt = params.get('prompt') ?? '' 9 notifyMessage(`user prompt: ${prompt}`) 10 11 // Get the output as a stream 12 const output = await session.run(prompt, { stream: true }) NPEFMͷݺͼग़͕͠؆୯
18 // Create a stream 19 const stream = new
ReadableStream({ 20 async start(controller) { 21 const encoder = new TextEncoder() 22 23 try { 24 let message = '' 25 for await (const chunk of output) { 26 controller.enqueue(encoder.encode(chunk.response ?? '')) 27 message = [...message, chunk.response].join('') 28 } 29 notifyMessage(message) 30 } catch (err) { 31 console.error('Stream error:', err) 32 } finally { 33 controller.close() 34 } 35 }, 36 }) 37 DIVOL͝ͱʹׂͯ͠ड͚औΔ
18 // Create a stream 19 const stream = new
ReadableStream({ 20 async start(controller) { 21 const encoder = new TextEncoder() 22 23 try { 24 let message = '' 25 for await (const chunk of output) { 26 controller.enqueue(encoder.encode(chunk.response ?? '')) 27 message = [...message, chunk.response].join('') 28 } 29 notifyMessage(message) 30 } catch (err) { 31 console.error('Stream error:', err) 32 } finally { 33 controller.close() 34 } 35 }, 36 }) 37 DPOUSPMMFSͰॲཧΛ͢Δ
&NCFEEJOH"1*Λఏڙ ྨࣅݕࡧ͕͍͢͠Έ 8IZZPVTIPVMEVTF&EHF'VODUJPOTGPS"*
8IZZPVTIPVMEVTF&EHF'VODUJPOTGPS"* w 4VQBCBTF&EHF'VODUJPOTͷΈͰɺ݁ɻ w 4VQBCBTFͰใΛอଘͰ͖Δɻγϯϓϧʂʂ w ྨࣅݕࡧ͕ؔͱ࣮ͯ͠ࡁΈ w ςΩετ͚ͩͰͳ͘ɺը૾ͳͲՄೳ
σϞ
10 const session = new Supabase.ai.Session('gte-small'); 11 12 serve(async (req)
=> { 13 const { events } = await req.json() 14 console.log(events) 15 if (events && events[0]?.type === "message") { 16 const input = events[0].message.text 17 // Generate the embedding from the user input 18 const embedding = await session.run(input, { 19 mean_pool: true, 20 normalize: true, 21 }); 22 23 // จࣈྻԽͨ͠ϝοηʔδσʔλ 24 let messages:any = [ 25 { 26 "type": "text", 27 "text": events[0].message.text 28 }, 29 ] NPEFMͷݺͼग़͕͠؆୯ ϕΫτϧใ͕SFUVSO͞ΕΔ
31 // Store the vector in Postgres 32 const supabase
= supabaseClient() 33 const { data: documents } = await supabase.rpc('match_documents', { 34 query_embedding: embedding, // Pass the embedding you want to compare 35 match_threshold: 0.78, // Choose an appropriate threshold for your data 36 match_count: 3, // Choose the number of matches 37 }) 38 console.log({documents}) 39 documents.map((doc) => { 40 messages.push({ 41 "type": "text", 42 "text": `Matched: ${doc.body}` 43 }) 44 }) 45 const { data, error } = await supabase.from('documents').insert({ 46 body: events[0].message.text, 47 embedding, 48 }) 49 replyMessage(events, messages) 50 } Ұக͢ΔυΩϡϝϯτΛݕࡧ
31 // Store the vector in Postgres 32 const supabase
= supabaseClient() 33 const { data: documents } = await supabase.rpc('match_documents', { 34 query_embedding: embedding, // Pass the embedding you want to compare 35 match_threshold: 0.78, // Choose an appropriate threshold for your data 36 match_count: 3, // Choose the number of matches 37 }) 38 console.log({documents}) 39 documents.map((doc) => { 40 messages.push({ 41 "type": "text", 42 "text": `Matched: ${doc.body}` 43 }) 44 }) 45 const { data, error } = await supabase.from('documents').insert({ 46 body: events[0].message.text, 47 embedding, 48 }) 49 replyMessage(events, messages) 50 } ೖྗͨ͠ϕΫτϧͷใΛอଘ
31 // Store the vector in Postgres 32 const supabase
= supabaseClient() 33 const { data: documents } = await supabase.rpc('match_documents', { 34 query_embedding: embedding, // Pass the embedding you want to compare 35 match_threshold: 0.78, // Choose an appropriate threshold for your dat 36 match_count: 3, // Choose the number of matches 37 }) 38 console.log({documents}) 39 documents.map((doc) => { 40 messages.push({ 41 "type": "text", 42 "text": `Matched: ${doc.body}` 43 }) 44 }) 45 const { data, error } = await supabase.from('documents').insert({ 46 body: events[0].message.text, 47 embedding, 48 }) 49 replyMessage(events, messages) 50 } ϩάͷ֬ೝ͕؆୯ʂ
ϩάͷ֬ೝ͕؆୯ʂ
4VQBCBTF͚ͩͰ "*ͷ1P$͕Ͱ͖Δʂ
4VQBCBTFY-*/&#PU ૬ੑ࠷ߴʂ
-*/&#PUҎ֎ /FYU 7VF 'MVUUFSFUD αϯϓϧίʔυ͕ͨ͘͞Μ
ࠓճͷΰʔϧɿ 4VQBCBTF&EHF'VODUJPOT Λ͍ͨ͘ͳΔʂ