
ããã«ã¡ã¯å ¤ã§ãã
æè¿ã¼ã«ãã®ãã¬ã¤æéã100æéãè¶
ãã¾ããããã¾ã£ããçµããæ°é
ããªãã¦å°ã£ã¦ã¾ãã
ãã¦ãæ¬é¡ã§ãããChatGPTã§ã¯ãã©ã°ã¤ã³ãå ¬éããã¦çãä¸ãã£ã¦ãã¾ããï¼
以åç³è«ãã¦ããChatGPT Pluginsã®Developerã®ã¢ã¯ã»ã¹æ¨©ãæè¿ä»ä¸ããã¦ããã®ã§ãå®éã«èªåã§ãä½ããã©ã°ã¤ã³ã使ãã¦ã¿ããã¨æãã¾ãã
ChatGPT Pluginsã¨ã¯
ChatGPT Pluginsã¯ãChatGPTã¨ãµã¼ããã¼ãã£ã®ã¢ããªã±ã¼ã·ã§ã³ãæ¥ç¶ãã¦ãæ¡å¼µæ©è½ã¨ãã¦å©ç¨ã§ããæ©è½ã§ãããµã¼ããã¼ãã£ã®ã¢ããªã±ã¼ã·ã§ã³ã¨æ¥ç¶ãããã¨ã§ãç´ ã®ChatGPTã§ã¯ã§ããªããæ§ã ãªã¿ã¹ã¯ãå®è¡ãããã¨ãã§ãã¾ãã
- ææ°æ å ±ã®åå¾
ChatGPTã¯2021å¹´ã¾ã§ã®æ å ±ããä¿æãã¦ãã¾ãããããã©ã°ã¤ã³ã§ãã©ã¦ã¸ã³ã°çãè¡ããã¨ã§ãææ°ã®æ å ±ãæ±ããã¨ãã§ãã¾ãã
- ã¦ã¼ã¶ã¼ã®ä»£ããã«ã¢ã¯ã·ã§ã³ãè¡ã
ããã«äºç´ãµã¼ãã¹ãã¬ã¹ãã©ã³äºç´ãµã¼ãã¹ãªã©ã¨çµã¿åããããã¨ã§ãChatGPTã¨å¯¾è©±ããªããããã«ãã¬ã¹ãã©ã³ã®äºç´ãå¯è½ã¨ãªãã¾ãã
æ¥æ¬ã®ä¼æ¥ã§ã¯é£ã¹ãã°ãä¾¡æ ¼.comã®ãµã¼ãã¹ãç¾å¨ãã©ã°ã¤ã³ã¨ãã¦å ¬éããã¦ãããå©ç¨ãããã¨ãã§ãã¾ãã
ä½ãæ¹
使æé ã¯å¤§ããåãã¦æ¬¡ã®3ã¤ã«ãªãã¾ãã
- APIã®ä½æ
- ãããã§ã¹ããã¡ã¤ã«ã®ä½æ
- OpenAPI ããã¥ã¡ã³ãã®ä½æ
1. APIã®ä½æ
ãã©ã°ã¤ã³ç¨ã®APIãå®è£ ãã¦ããã¾ãã ä»åã¯ä¾ã¨ãã¦News APIã使ã£ã¦ãã¥ã¼ã¹ãæ¤ç´¢ãã¦ããããã©ã°ã¤ã³ã使ãã¦ã¿ããã¨æãã¾ãã
å ¬å¼ã§ãã©ã°ã¤ã³ã®ãµã³ãã«ãåºã¦ããã®ã§ããããåèã«ä½æãã¾ãã
ãµã³ãã«ã§ã¯TODOãªã¹ãã®ãã©ã°ã¤ã³ã使ãã¦ãããAPI使ã«ã¯quartã¨ãããã¬ã¼ã ã¯ã¼ã¯ã使ç¨ãã¦ããã®ã§ãã¡ãã使ç¨ãã¦ããã¾ãã 使ãããã¡ã¤ã«ã¯ä»¥ä¸ã®éãã§ãã
import json import requests import quart import quart_cors from quart import request app = quart_cors.cors(quart.Quart(__name__), allow_origin="https://chat.openai.com",allow_methods="*") def search_news(query, api_key=API_KEY): url = "https://newsapi.org/v2/everything" parameters = { "q": query, # æ¤ç´¢ã¯ã¨ãªãæå® "pageSize": 10, "apiKey": api_key # èªåã®APIãã¼ãæå® } response = requests.get(url, params=parameters,proxies={"http": None, "https": None}) data = response.json() if response.status_code == 200: articles = data["articles"] news_list = [] for article in articles: title = article["title"] source = article["source"]["name"] description = article["description"] url = article["url"] news = { "title": title, "source": source, "description": description, "url": url } news_list.append(news) return json.dumps(news_list) else: print("ãã¥ã¼ã¹ã®æ¤ç´¢ã«å¤±æãã¾ããã") @app.get("/news/<string:query>") async def get_news(query): news_json = search_news(query) return quart.Response(response=news_json, status=200) @app.get("/logo.png") async def plugin_logo(): filename = 'logo.png' return await quart.send_file(filename, mimetype='image/png') @app.get("/.well-known/ai-plugin.json") async def plugin_manifest(): host = request.headers['Host'] with open("./.well-known/ai-plugin.json") as f: text = f.read() return quart.Response(text, mimetype="text/json") @app.get("/openapi.yaml") async def openapi_spec(): host = request.headers['Host'] with open("openapi.yaml") as f: text = f.read() return quart.Response(text, mimetype="text/yaml") def main(): app.run(debug=True, host="0.0.0.0", port=5002) if __name__ == "__main__": main()
ã¯ã¨ãªãæå®ãã¦News APIãå®è¡ãããã®ã¬ã¹ãã³ã¹ã®ã¿ã¤ãã«ã¨ã½ã¼ã¹ãæ¦è¦ãURLãGetããã ãã®ã·ã³ãã«ãªAPIã§ãã
2. ãããã§ã¹ããã¡ã¤ã«ã®ä½æ
ãããã§ã¹ããã¡ã¤ã«ã«ã¯ããã©ã°ã¤ã³ã®ååãæ¦è¦ããã´ãªã©ãè¨å®ãã¾ãã
{ "schema_version": "v1", "name_for_human": "News Search Plugin", "name_for_model": "newssearch", "description_for_human": "Plugin for News. You can search news by query.", "description_for_model": "Plugin for News. You can search news by query.", "auth": { "type": "none" }, "api": { "type": "openapi", "url": "http://localhost:5002/openapi.yaml", "is_user_authenticated": false }, "logo_url": "http://localhost:5002/logo.png", "contact_email": "[email protected]", "legal_info_url": "http://www.example.com/legal" }
èã¨ãªãã®ã¯description_for_modelã®ã¨ããã§ããããã®èª¬æãã¿ã¦ãChatGPTãããã³ããã«å¿ãã¦ã©ã®ãã©ã°ã¤ã³ã使ç¨ããã夿ãããã¨ã«ãªãã¾ãã
descriptionã®ãã¹ããã©ã¯ãã£ã¹ã«ã¤ãã¦ãå
¬å¼ã®æ¹ã§ã¾ã¨ãããã¦ããã®ã§ç¢ºèªãã¦ã¿ã¦ãã ããã
3. OpenAPI ããã¥ã¡ã³ãã®ä½æ
æå¾ã«OpenAPIã®ããã¥ã¡ã³ããå®ç¾©ãã¾ããOpenAPIã®ããã¥ã¡ã³ãã使ãããã¨ã§ãChatGPTã«å¯¾ãã¦ãã®APIã¯ã©ã®ãããªæ©è½ãæã£ã¦ããã®ããç¥ããããã¨ã«ãªãã¾ãã ä»åã¯ä»¥ä¸ã®ãããªããã¥ã¡ã³ãã使ãã¾ããã
openapi: 3.0.1 info: title: News Search Plugin description: This plugin allows users to input queries and receive the title, description, and source of the relevant news articles. Upon receiving a query, the plugin utilizes the NewsAPI to fetch the latest news data. It then extracts the title, description, and source information from the retrieved articles and presents them as a response. version: 'v1' servers: - url: http://localhost:5002 paths: /news/{query}: get: operationId: getNews summary: Get the list of news parameters: - in: path name: query schema: type: string required: true description: The search query for news articles. responses: "200": description: OK content: application/json: schema: $ref: '#/components/schemas/getNewsResponse' components: schemas: getNewsResponse: type: object properties: : type: array items: type: string description: The list of news.
åä½ç¢ºèª
å¿
è¦ãªãã¡ã¤ã«ããã¹ã¦ä½æã§ããã®ã§ãå®éã«åããã¦ã¿ããã¨æãã¾ãã
ã¾ãã¯ä½æããAPIããã¼ã«ã«ãã¹ãã§èµ·åãã¾ãã
$ python serve.py

ChatGPT Pluginsã®Developer権éãããå ´åãPlugin Storeã®ç»é¢ã«ãDevelop your own pluginãã¨ãã表示ãããã®ã§é¸æãã¾ãã

次ã«ãã¡ã¤ã³ãå ¥åãã¾ããä»åã¯ãã¼ã«ã«ãã¹ãã§èµ·åãã¦ããã®ã§ãlocalhost:5002ããã¡ã¤ã³ã¨ãªãã¾ãã

次ã«ãããã§ã¹ããã¡ã¤ã«ã¨OpenAPIããã¥ã¡ã³ãã®æ¤è¨¼ãè¡ããã¾ãã使ãããã¡ã¤ã«ã«åé¡ããªããã°ãç·ã®ãã§ãã¯ãã¼ã¯ãã¤ãã®ã§ãinstall localhost pluginãã鏿ãã¾ãã

ããã§ã¤ã³ã¹ãã¼ã«ã§ãã¾ããã使ãããã©ã°ã¤ã³ã鏿ãã¦å®éã«ä½¿ã£ã¦ã¿ã¾ãã

ã¡ããã¨æ©è½ãã¦ãã¾ãï¼ç¹ã«æç¤ºã¯ãã¦ãªãã§ããURLãåãè¾¼ãã§ãããããããæãã«è¡¨ç¤ºã§ãã¦ã¾ããã
ã¾ã¨ã
ä»åã¯ChatGPT Pluginãå®éã«ä½æãã¦ã¿ã¾ãããAPIããä½ã£ã¦ãã¾ãã°æå¤ã¨ç°¡åã«ä½ãããªã¨ããã®ãææ³ã§ããä»åã¯å¤é¨ã®APIãå¼ã³åºãã ãã®ã·ã³ãã«ãªãã®ã§ãããããã¯ãã«DBãªã©ã使ã£ã¦èªåã®ãã¼ã¿ãæ±ããããã«ããChatGPT Retrieval Pluginãªã©ãä»å¾è©¦ãã¦ã¿ããã¨æãã¾ãã