## 模块 1：准备运行 Python 代码

### 步骤 1. 打开终端

- 在浏览器中打开你自己的 [VS Code](${LAB:HTTPS_REVERSE_PROXY_URL}?next=${LAB:"/vscode/?folder=/root/tidb-lab-ai"|urlencode} "VS Code")。

- 在弹出的窗口中点击 `Yes, I trust the authors`（是的，我信任作者）。

  ![90%](https://lab-static.pingcap.com/quick-demo/vscode-trust.jpg)

- 点击左上角的 `≡`，选择 `Terminal`，然后点击 `New Terminal` 打开一个新的终端窗口。

  ![90%](https://public-pingcap-innovation.s3.us-west-2.amazonaws.com/demo-405/405-open-terminal-0307.jpg)

### 步骤 2. 安装 Python 依赖

安装 Python 依赖。

```bash
pip install -r requirements.txt
```

```output
Collecting aiohappyeyeballs==2.6.1 (from -r requirements.txt (line 1))
  Downloading aiohappyeyeballs-2.6.1-py3-none-any.whl.metadata (5.9 kB)
Collecting aiohttp==3.11.16 (from -r requirements.txt (line 2))
  Downloading aiohttp-3.11.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (7.7 kB)
Collecting aiosignal==1.3.2 (from -r requirements.txt (line 3))
  Downloading aiosignal-1.3.2-py2.py3-none-any.whl.metadata (3.8 kB)
...
[notice] A new release of pip is available: 24.0 -> 25.1
[notice] To update, run: pip install --upgrade pip
```

### 步骤 3. 创建 .env 文件

- 在 `openai` 文件夹中创建 `.env`。

  ![90%](https://public-pingcap-innovation.s3.us-west-2.amazonaws.com/demo-409/409-new-env-0427.jpg)

- 向 `.env` 文件中添加以下内容并保存。请将 `<Your OpenAI API Key>` 占位符更改为您的实际 OpenAI API Key。

  ```properties
  OPENAI_API_KEY=<Your OpenAI API Key>

  TIDB_HOST=${LAB:SERVERLESS_CLUSTER_HOST}
  TIDB_PORT=${LAB:SERVERLESS_CLUSTER_PORT}
  TIDB_USERNAME='${LAB:SERVERLESS_CLUSTER_USERNAME}'
  TIDB_PASSWORD='${LAB:SERVERLESS_CLUSTER_PASSWORD}'
  TIDB_DATABASE=${LAB:SERVERLESS_CLUSTER_DATABASE_NAME}
  ```
