Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow GPT model to be configured via config file #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ The configuration is described in this [doc](https://icystudio.github.io/TeleGPT
```json
{
"openaiAPIKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"openaiGptModel": "gpt-3.5-turbo",
"botToken": "8888888888:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"adminUsernames": ["cyandev"],
"conversationLimit": 30,
Expand Down
3 changes: 2 additions & 1 deletion config.example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"openaiAPIKey": "sk-************************************************",
"openaiGptModel": "gpt-3.5-turbo",
"botToken": "8888888888:***********************************",
"conversationLimit": 16,
"databasePath": "/telegpt/data/telegpt.sqlite",
Expand All @@ -10,4 +11,4 @@
"i18n": {
"resetPrompt": "Your conversation has been reset."
}
}
}
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ pub struct Config {
#[serde(rename = "botToken")]
pub telegram_bot_token: String,

/// The openai model your want to use in chat.
/// Value is default to "gpt-3.5-turbo".
/// JSON key: `openaiGptModel`
#[serde(default = "default_openai_gpt_model", rename = "openaiGptModel")]
pub openai_gpt_model: String,

/// A timeout in seconds for waiting for the OpenAI server response.
/// JSON key: `openaiAPITimeout`
#[serde(default = "default_openai_api_timeout", rename = "openaiAPITimeout")]
Expand Down Expand Up @@ -155,6 +161,7 @@ define_defaults! {
stream_throttle_interval: u64 = 500,
conversation_limit: u64 = 20,
renders_markdown: bool = false,
openai_gpt_model: String = "gpt-3.5-turbo".to_owned(),
}

define_defaults!(I18nStrings {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl OpenAIClient {
) -> Result<ChatModelStream, Error> {
let client = &self.client;
let req = CreateChatCompletionRequestArgs::default()
.model("gpt-3.5-turbo")
.model(self.config.openai_gpt_model.clone())
.temperature(0.6)
.max_tokens(self.config.max_tokens.unwrap_or(4096))
.messages(msgs)
Expand Down