From 150cc8e1533ed6530b67566bccc414a6731f6150 Mon Sep 17 00:00:00 2001 From: Lakr Aream Date: Tue, 19 Sep 2023 14:23:21 +0800 Subject: [PATCH 1/2] feat: custom endpoint --- config.example.json | 1 + src/config.rs | 6 ++++++ src/modules/openai.rs | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config.example.json b/config.example.json index 4662d05..686c33e 100644 --- a/config.example.json +++ b/config.example.json @@ -1,5 +1,6 @@ { "openaiAPIKey": "sk-************************************************", + "openaiAPIEndpoint": "https://api.openai.com/v1/chat/completions", "botToken": "8888888888:***********************************", "conversationLimit": 16, "databasePath": "/telegpt/data/telegpt.sqlite", diff --git a/src/config.rs b/src/config.rs index 4d663cf..ba1eaef 100644 --- a/src/config.rs +++ b/src/config.rs @@ -56,6 +56,12 @@ pub struct Config { /// JSON key: `openaiAPIKey` #[serde(rename = "openaiAPIKey")] pub openai_api_key: String, + + /// The API Endpoint to be used. + /// JSON key: `openaiAPIEndpoint` + #[serde(rename = "openaiAPIEndpoint")] + pub openai_api_endpoint: String, + /// The token of your Telegram bot. /// JSON key: `botToken` #[serde(rename = "botToken")] diff --git a/src/modules/openai.rs b/src/modules/openai.rs index 43c1b0c..229b828 100644 --- a/src/modules/openai.rs +++ b/src/modules/openai.rs @@ -74,7 +74,9 @@ impl Module for OpenAI { let config: Arc = dep_map.get(); let openai_client = OpenAIClient { - client: Client::new().with_api_key(&config.openai_api_key), + client: Client::new() + .with_api_key(&config.openai_api_key) + .with_api_base(&config.openai_api_endpoint), config: config.as_ref().clone(), }; dep_map.insert(openai_client); From fa849e836b23231f3f8c04430979e272b73c1bd4 Mon Sep 17 00:00:00 2001 From: Lakr Aream Date: Tue, 19 Sep 2023 14:29:46 +0800 Subject: [PATCH 2/2] Update config.example.json --- config.example.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.example.json b/config.example.json index 686c33e..19a4536 100644 --- a/config.example.json +++ b/config.example.json @@ -1,6 +1,6 @@ { "openaiAPIKey": "sk-************************************************", - "openaiAPIEndpoint": "https://api.openai.com/v1/chat/completions", + "openaiAPIEndpoint": "https://api.openai.com/v1", "botToken": "8888888888:***********************************", "conversationLimit": 16, "databasePath": "/telegpt/data/telegpt.sqlite",