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

flutterエンジニアの為のざっくりAI

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

 flutterエンジニアの為のざっくりAI

【背景】
Flutterエンジニアコミュニティ内で行った勉強会の共有資料です

【内容】
2023年4月19日までのAI関連情報およびAI技術について広く浅く共有

Avatar for heyhey1028

heyhey1028

April 20, 2023
Tweet

More Decks by heyhey1028

Other Decks in Technology

Transcript

  1. 主な学習方法
 教師あり学習 → 正解による学習
 - 入力に対して正解を教える学習方法
 教師なし学習 → パターン分析による学習
 -

    データからパターンを自動的に読み取る
 強化学習 → 報酬による学習
 - 開発者が報酬を設計し、報酬が最大化するようにタスクを実行する学習方 法

  2. 使われるアルゴリズム
 • 線形回帰
 • ロジスティック回帰
 • サポートベクターマシン
 • 決定木
 •

    ランダムフォレスト
 
 • ニューラルネットワーク
 • k近傍法
 • 主成分分析
 • K-平均法
 • 隠れマルコフモデル
 などなど...

  3. 使われるアルゴリズム
 • 線形回帰
 • ロジスティック回帰
 • サポートベクターマシン
 • 決定木
 •

    ランダムフォレスト
 
 • ニューラルネットワーク
 • k近傍法
 • 主成分分析
 • K-平均法
 • 隠れマルコフモデル
 などなど...

  4. Chat APIの概要
 使用可能モデル:
 • gpt-3.5-turboまで使用可能
 • gpt-4の使用はwaiting list
 
 入出力文字数の上限:


    • 1度に入出力可能なトークン数は4096トークン
 
 価格:
 • gpt-3.5-turboは $0.002 (¥0.27) / 1,000 tokens

  5. エンドポイント
 • https://api.openai.com/v1/chat/completions
 ヘッダー
 • Autorization: APIトークン
 • Content-Type: json


    リクエストパラメーター
 • model: 使用するモデルの名前
 • messages: 
 ◦ role: system, user, assistant
 ◦ content: プロンプト内容
 http.post( Uri.parse(endpoint), headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer $apiKey', }, body: jsonEncode( { "model": "gpt-3.5-turbo", "messages": [ { "role": "user", "content": prompt, } ], }, ), );
  6. レスポンス
 • choices: 
 ◦ message: 返信内容
 ◦ finish_reason: 終了した理由


    ▪ stop: 正常終了
 ▪ length: トークン上限に達した為 
 ▪ content_filter: 不適切な内容の為
 ▪ null: 処理中 or なんらかの不具合
 • usage:
 ◦ prompt_tokens: 入力completion_tokens: 出 力
 ◦ total_tokens: 合計
 { "id": "chatcmpl-123", "object": "chat.completion", "created": 1677652288, "choices": [ { "index": 0, "message": { "role": "assistant", "content": "\n\nHello there!" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 9, "completion_tokens": 12, "total_tokens": 21 } }
  7. { "model": "gpt-3.5-turbo", "messages": [ {"role": "system", "content": "You are

    a helpful assistant."}, {"role": "user", "content": "Who won the world series in 2020?"}, {"role": "assistant", "content": "Dodgers won in 2020."}, {"role": "user", "content": "Where was it played?"} ], }, Chat APIの挙動
 • 会話履歴を全て投げているだけ
 • 過去のチャット内容を保存しているわけではない

  8. { "model": "gpt-3.5-turbo", "messages": [ {"role": "system", "content": "You are

    a helpful assistant."}, {"role": "user", "content": "Who won the world series in 2020?"}, {"role": "assistant", "content": "Dodgers won in 2020."}, {"role": "user", "content": "Where was it played?"} ], }, role: system
 • 最初に記述
 • 挙動を制御する

  9. { "model": "gpt-3.5-turbo", "messages": [ {"role": "system", "content": "You are

    a helpful assistant."}, {"role": "user", "content": "Who won the world series in 2020?"}, {"role": "assistant", "content": "Dodgers won in 2020."}, {"role": "user", "content": "Where was it played?"} ], }, role: user
 • ユーザーの質問

  10. { "model": "gpt-3.5-turbo", "messages": [ {"role": "system", "content": "You are

    a helpful assistant."}, {"role": "user", "content": "Who won the world series in 2020?"}, {"role": "assistant", "content": "Dodgers won in 2020."}, {"role": "user", "content": "Where was it played?"} ], }, role: assistant
 • GPTからの返答

  11. Models
 • 様々なLLMを呼び出すインターフェース群
 • OpenAIのAPIを含む様々なLLMのAPIを呼び出すラッパーメソッド
 
 • LLMs
 ◦ Text

    Completion APIなど単発のやり取りをするAPI用のインターフェース
 • Chat Models
 ◦ Chat APIなどチャット形式のやり取りをするAPI用のインターフェース
 • Text Embeddings Models
 ◦ Embeddings APIなどEmbedding(埋め込み)を行うAPI用のインターフェース

  12. Prompts
 • プロンプト設定を行う為のインターフェース群
 
 • Prompt Templates 
 ◦ 単発プロンプトの事前プロンプトを定義するクラス


    • Chat Prompt Templates 
 ◦ 対話の事前プロンプトを定義するクラス
 • Example Selectors
 ◦ Few-shotプロンプトを定義するクラス
 • Output Parsers
 ◦ 出力結果を変換するクラス

  13. Indexes
 • ベクトルストア(ベクトル化したデータ用のDB)と連携する為のインターフェース群
 
 • Document Loaders
 ◦ 様々な形式の媒体(PDF、webサイト、Git Repository)からテキストデータを抽出するクラス


    • Text Splitters
 ◦ 抽出されたテキストデータをトークンサイズに分割するクラス
 • Vectorstores
 ◦ ChromaやPineconeなどのベクトルストアにデータを保存する為のクラス
 • Retrivers
 ◦ ベクトルストアからデータを取得する為のクラス

  14. Agents
 • LangChainの最も強力な機能の1つ
 • 自動的にタスクの判断と実行をするAgentを定義するインターフェース
 • Agent自体がLLMを使って、どんなタスクをどの順番で行うかを定義
 
 • Tools


    ◦ Agentが外部サービス(API)を実行する為のインターフェース 
 • Agents
 ◦ タスク実行とprompt実行を行うAIエージェントを定義する為のインターフェース 
 • Toolkits
 ◦ 特定のタスクに特化したAIエージェント