轉錄資料準備腳本會下載 YouTube 影片的字幕,並將其整理好以供 Semantic Search with OpenAI Embeddings and Functions 範例使用。
這些轉錄資料準備腳本已在最新版本的 Windows 11、macOS Ventura 及 Ubuntu 22.04(及以上)上測試過。
Important
建議您將 Azure CLI 更新至最新版本,以確保與 OpenAI 的相容性 請參閱 Documentation
- 建立資源群組
Note
本說明中使用的資源群組名稱為「semantic-video-search」,位置在 East US。 您可以更改資源群組名稱,但若更改資源位置, 請參考 model availability table。
az group create --name semantic-video-search --location eastus- 建立 Azure OpenAI Service 資源。
az cognitiveservices account create --name semantic-video-openai --resource-group semantic-video-search \
--location eastus --kind OpenAI --sku s0- 取得本應用程式使用的端點與金鑰
az cognitiveservices account show --name semantic-video-openai \
--resource-group semantic-video-search | jq -r .properties.endpoint
az cognitiveservices account keys list --name semantic-video-openai \
--resource-group semantic-video-search | jq -r .key1- 部署以下模型:
text-embedding-ada-002版本2或以上,命名為text-embedding-ada-002gpt-35-turbo版本0613或以上,命名為gpt-35-turbo
az cognitiveservices account deployment create \
--name semantic-video-openai \
--resource-group semantic-video-search \
--deployment-name text-embedding-ada-002 \
--model-name text-embedding-ada-002 \
--model-version "2" \
--model-format OpenAI \
--scale-settings-scale-type "Standard"
az cognitiveservices account deployment create \
--name semantic-video-openai \
--resource-group semantic-video-search \
--deployment-name gpt-35-turbo \
--model-name gpt-35-turbo \
--model-version "0613" \
--model-format OpenAI \
--sku-capacity 100 \
--sku-name "Standard"- Python 3.9 或以上版本
執行 YouTube 轉錄資料準備腳本時,需要設定以下環境變數。
建議將變數加入您的 user 環境變數中。
Windows Start > Edit the system environment variables > Environment Variables > User variables for [USER] > New。
AZURE_OPENAI_API_KEY \<your Azure OpenAI Service API key>
AZURE_OPENAI_ENDPOINT \<your Azure OpenAI Service endpoint>
AZURE_OPENAI_MODEL_DEPLOYMENT_NAME \<your Azure OpenAI Service model deployment name>
GOOGLE_DEVELOPER_API_KEY = \<your Google developer API key>
建議將以下 export 指令加入您的 ~/.bashrc 或 ~/.zshrc 檔案中。
export AZURE_OPENAI_API_KEY=<your Azure OpenAI Service API key>
export AZURE_OPENAI_ENDPOINT=<your Azure OpenAI Service endpoint>
export AZURE_OPENAI_MODEL_DEPLOYMENT_NAME=<your Azure OpenAI Service model deployment name>
export GOOGLE_DEVELOPER_API_KEY=<your Google developer API key>-
若尚未安裝,請先安裝 git client。
-
在
Terminal視窗中,將範例程式碼 clone 到您偏好的資料夾。git clone https://github.com/gloveboxes/semanic-search-openai-embeddings-functions.git
-
進入
data_prep資料夾。cd semanic-search-openai-embeddings-functions/src/data_prep -
建立 Python 虛擬環境。
Windows 上:
python -m venv .venvmacOS 和 Linux 上:
python3 -m venv .venv
-
啟動 Python 虛擬環境。
Windows 上:
.venv\Scripts\activate
macOS 和 Linux 上:
source .venv/bin/activate -
安裝所需函式庫。
Windows 上:
pip install -r requirements.txtmacOS 和 Linux 上:
pip3 install -r requirements.txt
.\transcripts_prepare.ps1./transcripts_prepare.sh免責聲明:
本文件由 AI 翻譯服務 Co-op Translator 進行翻譯。雖然我們致力於確保準確性,但請注意自動翻譯可能包含錯誤或不準確之處。原始文件的母語版本應被視為權威來源。對於重要資訊,建議採用專業人工翻譯。我們不對因使用本翻譯而引起的任何誤解或誤釋承擔責任。