Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .config/api_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"api_base": "https://api.openai.com/v1",
"api_key": "",
"engine": "gpt-3.5-turbo",
"max_tokens": 3600,
Expand Down
2 changes: 2 additions & 0 deletions doc/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

```json
{
// OpenAI Base URL(must endswith "/v1")
"api_base": "https://api.openai.com/v1",
// OpenAI Account API_KEY
"api_key": "",
// ID of the model to use
Expand Down
2 changes: 2 additions & 0 deletions doc/Config_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

```json
{
// OpenAI Base URL(也可以是任意兼容 OpenAI 的 API 服务地址)
"api_base": "https://api.openai.com/v1",
// OpenAI 账户构建的 API_KEY
"api_key": "",
// 需要的模型名称
Expand Down
3 changes: 2 additions & 1 deletion services/chat/ChatGPTAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
"""
Initialize Chatbot with API key (from https://platform.openai.com/account/api-keys)
"""
self.api_base = (config.get("api_base") or "https://api.openai.com/v1").rstrip("/")
self.api_key = config["api_key"]
self.engine = config["engine"]
self.max_tokens = config["max_tokens"]
Expand Down Expand Up @@ -192,7 +193,7 @@ def ask(self, prompt: str, timeout: float = 120, access_internet=False, access_r

try:
response = self.session.post(
url="https://api.openai.com/v1/chat/completions",
url=f"{self.api_base}/chat/completions",
headers={"Authorization": f"Bearer {self.api_key}"},
json={
"model": self.engine,
Expand Down
1 change: 0 additions & 1 deletion shared/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# api model check
with open('.config/api_config.json', encoding='utf-8') as f:
api_config = json.load(f)
f.close()

if api_config['engine'] not in [
'gpt-3.5-turbo',
Expand Down