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

Seamless inventory management with AI

Seamless inventory management with AI

関数呼び出しやチャット補完など、LLM AIの機能を応用し、音声やテキストによる会話を通じて店舗の在庫を管理できるAIチャットボットの作成方法を示します。

More Decks by LINEヤフーTech (LY Corporation Tech)

Other Decks in Technology

Transcript

  1. • 6TF"*UPDPOWFSUTQFFDIUPUFYU • 6TF"*UPUIJOLXIBUUPDBMM XIJDI"1*UPVTF • 6TF"*UPFYUSBDUEBUBGSPN+40/ • *OUFHSBUFXJUI-*/&.FTTBHJOH"1*BOE-*/&4IPQQJOH"1* •

    -*/&4IPQQJOHMFUT5IBJMBOETFMMFSTDSFBUFBTIPQPO-*/& 0GGJDJBM"DDPVOU • 8FDSFBUFB3JDI XPSLGMPXVTJOH"* *OUIFEFNP TVNNBSZ
  2. • 0QFO"*"1* • 4QFFDIUPUFYU"1* • $IBUDPNQMFUJPO"1* • 'VODUJPODBMMJOH • 4USVDUVSFEEBUBFYUSBDUJPO

    • -*/&"1* • -*/&.FTTBHJOH"1*GPSSFDFJWJOHXFCIPPLBOETFOEB SFQMZNFTTBHF • -*/&4)011*/("1*GPS HFUQSPEVDUMJTUJOHBOE VQEBUFJOWFOUPSZ )PX
  3. "SDIJUFDUVSF LINE Webhook server OpenAI API 1. Webhook LINE Shopping

    API 2. Get Content 3. Audio 4. Speech to text 7. Get function call User 8. Call API 9. Send Reply Message 5. text 6. Chat completion
  4. "SDIJUFDUVSF LINE Webhook server OpenAI API 1. Webhook LINE Shopping

    API 2. Get Content 3. Audio 4. Speech to text 7. Get function call User 8. Call API 9. Send Reply Message 5. text 6. Chat completion
  5. { "destination": "xxxxxxxxxx", "events": [ { "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", "type": "message",

    "mode": "active", "timestamp": 1462629479859, "source": { "type": "user", "userId": "U4af4980629..." }, "webhookEventId": "01FZ74A0TDDPYRVKNK77XKC3ZR", "deliveryContext": { "isRedelivery": false }, "message": { "id": "325708", "type": "audio", "duration": 60000, "contentProvider": { "type": "line" } } } ] }
  6. "SDIJUFDUVSF LINE Webhook server OpenAI API 1. Webhook LINE Shopping

    API 2. Get Content 3. Audio 4. Speech to text 7. Get function call User 8. Call API 9. Send Reply Message 5. text 6. Chat completion
  7. "SDIJUFDUVSF LINE Webhook server OpenAI API 1. Webhook LINE Shopping

    API 2. Get Content 3. Audio 4. Speech to text 7. Get function call User 8. Call API 9. Send Reply Message 5. text 6. Chat completion
  8. LINE Get Content API to Get Message Content by Message

    ID curl --request POST ¥ --url https://api.openai.com/v1/audio/transcriptions ¥ --header "Authorization: Bearer $OPENAI_API_KEY" ¥ --header 'Content-Type: multipart/form-data' ¥ --form file=@/path/to/file/speech.mp3 ¥ --form model=whisper-1 ¥ --form response_format=text response text = `Can I get a product list` And we use OpenAI speech to text API
  9. "SDIJUFDUVSF LINE Webhook server OpenAI API 1. Webhook LINE Shopping

    API 2. Get Content 3. Audio 4. Speech to text 7. Get function call User 8. Call API 9. Send Reply Message 5. text 6. Chat completion
  10. Use OpenAI function calling chat completion API curl https://api.openai.com/v1/chat/completions ¥

    --header "Authorization: Bearer $OPENAI_API_KEY" ¥ --header 'Content-Type: application/json‘ ¥ -d '{ "model": "gpt-4o", "messages": [ { "role": "user", "content": "Can I get product list" } ], "tools": [ { "type": "function", "function": { "name": "get_products", "description": "Get products in MyShop", "parameters": { "type": "object", "properties": { "ids": { "type": "string", "description": “id of products" } }, "required": [] } } } ], "tool_choice": "auto" }'
  11. Tools Definition "tools": [ { "type": "function", "function": { "name":

    "get_products", "description": "Get products in MyShop", "parameters": { "type": "object", "properties": { "ids": { "type": "string", "description": “id of products" } }, "required": [] } } } ], "tool_choice": "auto" }'
  12. OpenAI function calling chat completion API Response { "id": "chatcmpl-abc123",

    "object": "chat.completion", "created": 1699896916, "model": "gpt-4o-mini", "choices": [ { "index": 0, "message": { "role": "assistant", "content": null, "tool_calls": [ { "id": "call_abc123", "type": "function", "function": { "name": “get_products", "arguments": "{¥n¥"ids¥": ¥"¥"¥n}" } } ] }, "logprobs": null, "finish_reason": "tool_calls" } ], "usage": { "prompt_tokens": 82, "completion_tokens": 17, "total_tokens": 99, "completion_tokens_details": { "reasoning_tokens": 0 } } }
  13. Choices Response "choices": [ { "index": 0, "message": { "role":

    "assistant", "content": null, "tool_calls": [ { "id": "call_abc123", "type": "function", "function": { "name": "get_products", "arguments": "{¥n¥"ids¥": ¥"¥"¥n}" } } ] }, "logprobs": null, "finish_reason": "tool_calls" } ],
  14. "SDIJUFDUVSF LINE Webhook server OpenAI API 1. Webhook LINE Shopping

    API 2. Get Content 3. Audio 4. Speech to text 7. Get function call User 8. Call API 9. Send Reply Message 5. text 6. Chat completion
  15. Now we know we have to get products from LINE

    Shopping API curl https://developers-oaplus.line.biz/myshop/v1/products ¥ --header “X-API-KEY: Bearer $LINE_SHOPPING_API_KEY” ¥ --header ‘Content-Type: application/json‘ We then use normal LINE Messaging Reply API to reply to user 🤓 🥳
  16. "SDIJUFDUVSF LINE Webhook server OpenAI API 1. Webhook LINE Shopping

    API 2. Get Content 3. Audio 4. Speech to text 7. Get function call User 8. Call API 9. Send Reply Message 5. text 6. Chat completion
  17. Update product’s inventory is the same: LINE Get Content API

    to Get Message Content by Message ID to get audio Use OpenAI Speech to text to convert audio to text We get “Update inventory of LINE dev t-shirt to 20” 🤓 🥳
  18. Now is function calling’s job curl https://api.openai.com/v1/chat/completions ¥ --header "Authorization:

    Bearer $OPENAI_API_KEY" ¥ --header 'Content-Type: application/json‘ ¥ -d '{ "model": "gpt-4o", "messages": [ { "role": "user", "content": "Update inventory of LINE dev t-shirt to 25" } ], "tools": [ { "type": "function", "function": { "name": "update_inventory_by_name", "description": "Update product inventory in MyShop by product name", "parameters": { "type": "object", "properties": { "name": { "type": "string", "description": “name of product" }, "amount": { "type": "integer", "description": “quantity of product" } }, "required": [] } } } ], "tool_choice": "auto" }' 🤓 🥳
  19. But LINE Shopping API doesn’t have update inventory by product

    name How do we solve this? LINE Shopping API provides only update by `inventory id` 🤓 🥳
  20. curl https://api.openai.com/v1/chat/completions ¥ --header "Authorization: Bearer $OPENAI_API_KEY" ¥ --header 'Content-Type:

    application/json‘ ¥ -d '{ "model": "gpt-4o", "messages": [ { "role": "system", "content": "You are an expert at structured data extraction. You will be given json response api and should parse inventory id" }, { "role": "system", "content": "extract inventory id for $productName with following: $json" } ], "tools": [ { "type": "function", "function": { "name": "update_inventory_by_name", "description": "Update product inventory in MyShop by product name", "parameters": { "type": "object", "properties": { "name": { "type": "string", "description": “name of product" }, "amount": { "type": "integer", "description": “quantity of product" } }, "required": [] } } } ], "tool_choice": "auto" }' 🤓 🥳
  21. "messages": [ { "role": "system", "content": "You are an expert

    at structured data extraction. You will be given json response from api and should parse inventory id" }, { "role": "system", "content": "extract inventory id for เสื$อไลน์เดฟ with following: { … // JSON … }” } ], 🤓 🥳
  22. "SDIJUFDUVSF LINE Webhook server OpenAI API 1. Webhook LINE Shopping

    API 2. Get Content 3. Audio 4. Speech to text 7. Get function call User 8. Call API 9. Send Reply Message 5. text 6. Chat completion
  23. 1SJDJOH "UXIBUDPTU { "id": "chatcmpl-abc123", "object": "chat.completion", "created": 1699896916, "model":

    "gpt-4o-mini", "choices": [ { "index": 0, "message": { "role": "assistant", "content": null, "tool_calls": [ { "id": "call_abc123", "type": "function", "function": { "name": “get_products", "arguments": "{¥n¥"ids¥": ¥"¥"¥n}" } } ] }, "logprobs": null, "finish_reason": "tool_calls" } ], "usage": { "prompt_tokens": 82, "completion_tokens": 17, "total_tokens": 99, "completion_tokens_details": { "reasoning_tokens": 0 } } } "MNPTU'SFF