已比較的版本

索引鍵

  • 此行已新增。
  • 此行已移除。
  • 格式已變更。

...

  1. 要先拿到 Assistant ID & User API key

  2. 建立與 Assistant 連線

    1. create thread → get thread ID

  3. expot API KEY,ASSISTANT_ID 以及你的 input

    1. 程式碼區塊
      languagebash
      ASSISTANT_ID="YOUR ASSISTANT ID"
      API_KEY="YOUR API KEY"
      INPUT_MSG="YOUR MESSAGE TO ASSISTANT"
  4. 執行以下腳本

  5. 程式碼區塊
    BASE_URL="https://stag.dvcbot.net/api/assts/v1"
    
    # create thread
    AUTH_HEADER="Authorization: Bearer ${API_KEY}"
    THREAD_URL="${BASE_URL}/threads"
    THREAD_ID=`curl -s --location "${THREAD_URL}" \
    --header 'OpenAI-Beta: assistants=v2' \
    --header 'Content-Type: application/json' \
    --header "${AUTH_HEADER}" \
    --data '{}' | jq .id | tr -d '"'`
    
    # add msg to thread
    CREATE_MSG_DATA=$(< <(cat <<EOF
    {
      "role": "user",
      "content": "$INPUT_MSG"
    }
    EOF
    ))
    MSG_URL="${BASE_URL}/threads/${THREAD_ID}/messages"
    curl -s --location "${MSG_URL}" \
    --header 'OpenAI-Beta: assistants=v2' \
    --header 'Content-Type: application/json' \
    --header "${AUTH_HEADER}" \
    --data "${CREATE_MSG_DATA}" > /dev/null
    
    # run the assistant within thread
    CREATE_RUN_DATA=$(< <(cat <<EOF
    {
      "assistant_id": "$ASSISTANT_ID"
    }
    EOF
    ))
    RUN_URL="${BASE_URL}/threads/${THREAD_ID}/runs"
    RUN_ID=`curl -s --location "${RUN_URL}" \
    --header 'OpenAI-Beta: assistants=v2' \
    --header 'Content-Type: application/json' \
    --header "${AUTH_HEADER}" \
    --data "${CREATE_RUN_DATA}" | jq .id | tr -d '"'`
    
    # get run result
    RUN_STAUS=""
    while [[ $RUN_STAUS != "completed" ]]
    do
        RUN_STAUS=`curl -s --location --request GET "${RUN_URL}/$RUN_ID" \
    --header 'OpenAI-Beta: assistants=v2' \
    --header 'Content-Type: application/json' \
    --header "${AUTH_HEADER}" \ | jq .status | tr -d '"'`;
        sleep 1
    done
    
    #list msg
    RESPONSE_MSG=`curl -s --location --request GET "${MSG_URL}" \
    --header 'OpenAI-Beta: assistants=v2' \
    --header 'Content-Type: application/json' \
    --header "${AUTH_HEADER}" | jq .data[0].content[].text.value`
    
    echo "you: "$INPUT_MSG
    echo ""
    echo "davinci bot: "$RESPONSE_MSG
  6. 即可看到結果如下

    程式碼區塊
    you: "your message here"
    davinci bot: "response from assistant"
  7. 如何發送 user msg 到 Assistant

    1. create message → get message ID

  8. 如何取得 Assistant 的回應

    1. create run → run ID

    2. check run status → if run status == done

    3. list message →

  9. 當 Assistant 要求要執行 plugin 時,你要

    1. 怎樣知道 Assistant 要執行 plugin 以及什麼 plugin,要代入什麼參數?

    2. 打 run_plugin_api 來執行

    3. 將 plugin 結果傳回 Assistant

    4. 補充:file 時,先用 DocChat

程式碼區塊
API_KEY="your api key"
ASS_ID="your ass id"

程式碼區塊
> bash sendMessage.sh

cur dhdsh
cur dghsdeh