跳至橫幅的結尾
前往橫幅的開頭

OpenAPI Plugin

跳至中繼資料的結尾
前往中繼資料的開頭

You are viewing an old version of this content. View the current version.

比較目前 View Version History

« 上一頁 版本 8 下一步 »

Introduction

OpenAPI Type 的Plugin,使用符合OpenAPI 格式的yaml檔,只要在 Plugin 中,指定你的yaml 的位置,DaVinci 會去這個 url 下載 yaml 檔案,並且依照裡面的 API format 進行 API 的資訊檢索,OpenAPI Type Plugin example:

{
  "id": "Weather_API",
  "schema_version": "v1",
  "name_for_human": "Weather_API",
  "name_for_model": "Weather_API",
  "description_for_human": "Weather_API",
  "description_for_model": "當你需要查詢未來天氣的相關資料, 請使用這個API, 並且整理相關資訊以表格輸出",
  "api": {
    "type": "openapi",
    "url": "https://example.com/weather.yaml"
  }
}

這是一個 查詢天氣的範例,假設我們要使用 氣象資料開放平台 提供的開源API來索取資料,需要兩個步驟:

  1. 根據氣象資料開放平台的API範例,將各 API 的 url 以及參數,轉換成 yaml 檔案,並且存放到您的伺服器中。

  2. plugin json 檔裡面,修改這兩個地方:

"api": {
    "type": "openapi",
    "url": "https://example.com/weather.yaml"
  }

即可完成Plugin 的製作

註記:為了運作穩定,目前 OpenAPI Plugin 只能運作在 GPT4-Turbo 上,無法在其他 Model 上使用。

OpenAPI Plugin 如何撈取 user_id?

您可以在 Server 端獲得來自 MediaTek DaVinci 發出的 request 之後,從 header 拿到 “Davinci-Cookie”,並透過 userinfo 的 api 撈取到 user_id。

import aiohttp
import quart
import traceback

async def get_username():
    async with aiohttp.ClientSession() as session:
        cookie = quart.request.headers["Davinci-Cookie"]
        url = 'https://prod.dvcbot.net'
        async with session.post(
            f"{url}/api/userinfo",
            json={"cookie": cookie},
            verify_ssl=False,
        ) as resp:
            try:
                result = await resp.json()

                return result["username"]
            except Exception as e:
                error_message = traceback.format_exc()

參考來源:

  • 無標籤