Upgrade to Pro — share decks privately, control downloads, hide ads and more …

LLMを拡張機能に

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for nikawa2161 nikawa2161
June 17, 2025
12

 LLMを拡張機能に

Avatar for nikawa2161

nikawa2161

June 17, 2025
Tweet

More Decks by nikawa2161

Transcript

  1. Chrome 拡張機s H Manifes` H 定義や宣言を行4 H Service workerG H

    ブラウザのイベントを処理できT H Content scriptG H DOM を利用で、変更を加えたりできT H Toolbar actio@ H 拡張機能ツールバーのアイコンをクリックした時に、処理を 実行できる
  2. manifest.json 1 2 3 4 5 6 7 8 9

    10 11 12 13 { , , , [ , ], { }, { , } } "manifest_version" "name" "version" "permissions" "background" "service_worker" "side_panel" "default_path" : : : : : : : : 3 "LLM Assistant" "1.0" "sidePanel" "scripting" "background.js" "index.html"
  3. background.js 1 2 3 4 5 6 7 8 9

    10 11 12 13 14 15 16 17 18 19 20 21 const const async const await const return if model ({ baseURL , apiKey , }). ( ); (request Request) { { messages } request. (); result ({ model, system   , messages, }); result. (); }; self. ( , (event ) { (event.request.url. ( )) { event. ( (event.request)); } }); = : : = : => = = : : any => createOpenAI chat handleChat json streamText toDataStreamResponse addEventListener endsWith respondWith handleChat 'https://models.github.ai/inference' 'api-key' 'openai/gpt-4.1' 'AIアシスタント' 'fetch' '/api/chat' // リクエストを横取り
  4. index.html(react) 1 2 3 4 5 6 7 8 9

    10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import from export default function const return div div div form input button button form div { useChat } ; () { { messages, input, handleInputChange, handleSubmit } ({ api , }); ( < > {messages. ((message) ( < key={message.id}> {message.role } {message.content} </ > ))} < onSubmit={handleSubmit}> < name="prompt" placeholder="質問を入力してください" value={input} onChange={handleInputChange} /> < type="submit">送信</ > </ > </ > ); } "@ai-sdk/react" "/api/chat" "user" "User: " "AI: " Chat useChat map = : => === ? :