Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
feat: get config from environment variables (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciuzaak committed May 14, 2023
1 parent a76857b commit 73d0f71
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,21 @@ If you only have access to one of the models, you can still continue to use this

1. Clone this repository.

2. Fill in `config/config.yml` with reference to `config/config.example.yml`.
2. Configure the bot in the following two ways:
1. Create `config/config.yml` and fill in the information with reference to `config/config.example.yml`.
2. Set environment variables:

```bash
export BOT_TOKEN="your bot token"
export USER_IDS="user_id1,user_id2,..."
export CLAUDE_API="your claude api" # ignore it if you don't want to use claude
export BARD_API="your bard api" # ignore it if you don't want to use bard
```

- [How to obtain telegram bot token](https://core.telegram.org/bots/tutorial#obtain-your-bot-token)
- [How to obtain telegram user id](https://bigone.zendesk.com/hc/en-us/articles/360008014894-How-to-get-the-Telegram-user-ID-)

3. Start the bot by:
3. Start the bot in the following two ways:

- **Docker** (with docker engine and docker-compose pre-installed):

Expand Down
26 changes: 17 additions & 9 deletions config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
from yaml import safe_load
from os import getenv, path

# load yaml config
with open('config/config.yml', 'r') as f:
config_yaml = safe_load(f)
from yaml import safe_load

# config parameters
bot_token = config_yaml['telegram']['bot_token']
user_ids = config_yaml['telegram']['user_ids']
claude_api = config_yaml['claude']['api']
bard_api = config_yaml['bard']['api']
if not path.exists('config/config.yml'):
# load env vars
bot_token = getenv('BOT_TOKEN')
user_ids = [int(user_id) for user_id in getenv('USER_IDS').split(',')]
claude_api = getenv('CLAUDE_API')
bard_api = getenv('BARD_API')
else:
# load yaml config
with open('config/config.yml', 'r') as f:
config_yaml = safe_load(f)
# config parameters
bot_token = config_yaml['telegram']['bot_token']
user_ids = config_yaml['telegram']['user_ids']
claude_api = config_yaml['claude']['api']
bard_api = config_yaml['bard']['api']

assert bot_token is not None and user_ids is not None
assert claude_api is not None or bard_api is not None
Expand Down

0 comments on commit 73d0f71

Please sign in to comment.