Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Supabase Edge Functions で最近追加された AI 機能を使ってみた
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
4geru
May 14, 2024
Technology
630
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
1ヶ月Vizを眺めた話
4geru
0
22
年齢で見るチームの特徴
4geru
0
20
Boom!ヒーロー!! - ポーズを決めろ!その瞬間、キミは主役のヒーローだ -
4geru
0
64
AIと考える MCP tools の実装
4geru
0
32
AI様、あとは"よしなに"やっといて! 〜MCPサーバ開発「裏」入門〜
4geru
0
68
その物件でホントにいいの君?_第3回_Dify_Studio_ハッカソン
4geru
0
69
How OpenAPI Is Transforming API Client Development
4geru
0
89
AI時代のハンズオン:未来の“相棒”と出会う実践体験
4geru
0
61
ツンデレさんと考える LINE bot MCP の使い方
4geru
0
1.3k
Other Decks in Technology
See All in Technology
新しいUbuntu/GNOMEが使いたいからXからWaylandへ移行頑張ってるの巻 2026-06-20
nobutomurata
0
160
GitHub Copilot app最速の発信の裏側
tomokusaba
1
240
生成 AI 実践ガイド (概略版) AIガバナンス編
asei
0
180
いまさら聞けない「仕様駆動開発入門」 〜AI活用時代の開発プロセスを考える〜
findy_eventslides
2
180
MUSUBI 田中裕一『AIと共に行う「しごとのリデザイン」- スモールバックオフィス編』AI Ops Lab #4
musubi
0
310
SONiC実機とGNS3 SONiC VSによる事前コンフィグ検証 ― 生成AIエージェントを環境構築・検証支援に使ってみた ―
sonic
0
120
Flow 不死:AI 時代 DevOps 的不變本質
cheng_wei_chen
2
480
AIのReact習熟度を測る
uhyo
2
670
技術・能力を向上する原理原則 #きのこセッションa #きのこ2026
bash0c7
0
110
入門!AWS Blocks
ysuzuki
1
180
アジャイルな経理と Claude Code と経営の未来
kawaguti
PRO
3
190
SteampipeとExcel Power QueryでAWS構成定義書の作成を自動化する
jhashimoto
0
170
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
2.1k
Navigating Weather and Climate Data
rabernat
0
230
Between Models and Reality
mayunak
4
350
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
210
WENDY [Excerpt]
tessaabrams
11
38k
The browser strikes back
jonoalderson
0
1.3k
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
Balancing Empowerment & Direction
lara
6
1.2k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
630
Test your architecture with Archunit
thirion
1
2.3k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
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 Λ͍ͨ͘ͳΔʂ