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
680
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
11
Rails で Remote MCP サーバーを作った話
4geru
0
640
Rails で Remote MCP サーバーを作った話
4geru
0
21
1ヶ月Vizを眺めた話
4geru
0
34
年齢で見るチームの特徴
4geru
0
35
Boom!ヒーロー!! - ポーズを決めろ!その瞬間、キミは主役のヒーローだ -
4geru
0
81
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
Temporal 最高!でも改めて「日付」について調べたら人類の負債すぎる件
riyaamemiya
0
150
分析の民主化を支えるメタデータ整備の実践
kakehashi
PRO
4
1.4k
Browser Spec: Testing Hotwire with Ruby
takahashim
1
120
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
140
1つのリクエストを追って理解する - llm-dのP/D分離
akhino
1
160
Persisting Massive Data with Rails ~Designing for 60 billion rows, and fighting the bottlenecks~ Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
0
730
サブエージェントと Claude Mods で作る独自 Advisor ツールの話
kenichiodo
2
160
WasmをRustにする
sansantech
PRO
0
250
AI導入は済んだ。次は統制を作り替える番だ_AI×開発組織 Summit 2026
techtekt
PRO
0
210
AI時代のPRレビューにどう向き合うか?
kairim0
1
240
Benchmarking Disaggregated Serving on vLLM + Dynamo with a Real Coding-Agent Workload
nttcom
1
190
Claude の新機能を、 出た日に触って社内に届けるまで
rfdnxbro
1
170
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Mobile First: as difficult as doing things right
swwweet
225
10k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
Thoughts on Productivity
jonyablonski
76
5.4k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
400
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Facilitating Awesome Meetings
lara
57
7.2k
Practical Orchestrator
shlominoach
192
12k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
410
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
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 Λ͍ͨ͘ͳΔʂ