Skip to content

Commit

Permalink
Merge pull request #22 from approvers/chore/fix-env-key
Browse files Browse the repository at this point in the history
chore!: 環境変数のKeyを修正
  • Loading branch information
Sho Sakuma authored Aug 6, 2023
2 parents d9e7c0d + 3b22c02 commit be95eba
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ DISCORD_API_TOKEN=

# ChatGPT API のトークンを指定する。
## https://platform.openai.com/
CHATGPT_API_TOKEN=
OPENAI_API_KEY=
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ docker run --env-file=.env -d ichiyo_ai
| Key | Description | Default |
|---------------------|-------------------|---------|
| `DISCORD_API_TOKEN` | Discord API のトークン | - |
| `CHATGPT_API_TOKEN` | ChatGPT API のトークン | - |
| `OPENAI_API_KEY` | OpenAI API のトークン | - |
8 changes: 4 additions & 4 deletions src/api/chatgpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use chatgpt::prelude::{ChatGPT, ChatGPTEngine};
use chatgpt::types::CompletionResponse;
use once_cell::sync::Lazy;

static CHATGPT_API_TOKEN: Lazy<String> = Lazy::new(|| {
env::var("CHATGPT_API_TOKEN").expect("Expected a token in the environment (CHATGPT_API_TOKEN)")
static OPENAI_API_KEY: Lazy<String> = Lazy::new(|| {
env::var("OPENAI_API_KEY").expect("Expected a token in the environment (OPENAI_API_KEY)")
});

/// ChatGPTと会話を行う関数。
Expand All @@ -19,7 +19,7 @@ pub async fn chat_completion(
) -> chatgpt::Result<CompletionResponse> {
let model = model.unwrap_or(ChatGPTEngine::Gpt35Turbo);
let client = ChatGPT::new_with_config(
&*CHATGPT_API_TOKEN,
&*OPENAI_API_KEY,
ModelConfigurationBuilder::default()
.engine(model)
.build()
Expand All @@ -42,7 +42,7 @@ pub async fn chat_directed(
) -> chatgpt::Result<CompletionResponse> {
let model = model.unwrap_or(ChatGPTEngine::Gpt35Turbo);
let client = ChatGPT::new_with_config(
&*CHATGPT_API_TOKEN,
&*OPENAI_API_KEY,
ModelConfigurationBuilder::default()
.engine(model)
.build()
Expand Down

0 comments on commit be95eba

Please sign in to comment.