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

llm.pdf

Avatar for nikawa2161 nikawa2161
June 05, 2025
3

 llm.pdf

Avatar for nikawa2161

nikawa2161

June 05, 2025
Tweet

Transcript

  1. 用意するもの E フロント(React' E ストリーミングで表& E バックエンド(Hono' E AI SDKでモデル選択

    ライブラリ E ai-sdk/openaS E ai-sdk/reac` E aS E zor E aiの依存関係として必要
  2. モデルの選択 1 2 3 4 5 6 7 8 9

    import from const { createOpenAI } ; model ({ baseURL ,   apiKey process.env. , }). ( ); "@ai-sdk/openai" "https://models.github.ai/inference" "openai/gpt-4o-mini" = : : createOpenAI chat OPENAI_API_KEY
  3. リクエスト 1 2 3 4 5 6 7 8 9

    10 11 12 13 14 15 16 17 18 19 import from import from const async const await const return { createOpenAI } ; { streamText } ; model ({ baseURL ,   apiKey process.env. , }). ( ); app. ( , (c) { { messages } c.req. (); result ({ model, system , messages, }); result. (); }); "@ai-sdk/openai" "ai" "https://models.github.ai/inference" "openai/gpt-4o-mini" "/api/chat" "You are a helpful assistant." = : : => = = : createOpenAI chat post json streamText toDataStream OPENAI_API_KEY
  4. リクエスト(Hono) 1 2 3 4 5 6 7 8 9

    10 11 12 13 14 15 16 17 18 19 20 import from import from import from const async const await const return { createOpenAI } ; { stream } ; { streamText } ; model ({ baseURL ,   apiKey process.env. , }). ( ); app. ( , (c) { { messages } c.req. (); result ({ model, system , messages, }); c. ( , ); (c, (stream) stream. (result. ())); }); "@ai-sdk/openai" "hono/streaming" "ai" "https://models.github.ai/inference" "openai/gpt-4o-mini" "/api/chat" "You are a helpful assistant." "Content-Encoding" "Identity" = : : => = = : => createOpenAI chat post json streamText header stream pipe toDataStream OPENAI_API_KEY
  5. 表示側 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" "http://localhost:5173/api/chat" "user" "User: " "AI: " Chat useChat map = : => === ? :
  6. モデル選択(OpenAi) 1 2 3 4 5 6 7 8 9

    10 11 12 13 14 15 16 17 18 19 20 import from import from import from const async const await const return { createOpenAI } ; { stream } ; { streamText } ; model ({ baseURL ,   apiKey process.env. , }). ( ); app. ( , (c) { { messages } c.req. (); result ({ model, system , messages, }); c. ( , ); (c, (stream) stream. (result. ())); }); "@ai-sdk/openai" "hono/streaming" "ai" "https://models.github.ai/inference" "openai/gpt-4o-mini" "/api/chat" "You are a helpful assistant." "Content-Encoding" "Identity" = : : => = = : => createOpenAI chat post json streamText header stream pipe toDataStream OPENAI_API_KEY
  7. モデル選択(ollama) 1 2 3 4 5 6 7 8 9

    10 11 12 13 14 15 16 17 18 19 20 // import { createOpenAI } from "@ai-sdk/openai"; import from import from import from const async const await const return { createOllama } ; { stream } ; { streamText } ; model ({ baseURL , }). ( ); app. ( , (c) { { messages } c.req. (); result ({ model, system , messages, }); c. ( , ); (c, (stream) stream. (result. ())); }); "ollama-ai-provider" "hono/streaming" "ai" "http://localhost:11434/api" "phi3" "/api/chat" "You are a helpful assistant." "Content-Encoding" "Identity" = : => = = : => createOllama chat post json streamText header stream pipe toDataStream