Last active 6 months ago

此 Python 程式碼用於初始化 OpenAI 客戶端,設定 API 金鑰和自定義基礎 URL,並列出可用的模型清單。

timmy revised this gist 6 months ago. Go to revision

1 file changed, 15 insertions

list_openai_models.py(file created)

@@ -0,0 +1,15 @@
1 + import os
2 + from openai import OpenAI
3 +
4 + # 初始化 OpenAI 客戶端,設定 API 金鑰跟自定義 base URL
5 + client = OpenAI(
6 + api_key="sk-olPkgbB0-qQbgW5kO-ovidK4cR-WTmLAUco", # 直接寫入你的金鑰
7 + base_url="http://192.168.88.82:4000" # 指定自定義 API 端點
8 + )
9 +
10 + # 獲取模型列表
11 + models = client.models.list()
12 +
13 + # 印出模型列表
14 + for model in models.data:
15 + print(model.id)
Newer Older