Sign inSign up

cloudbeer/brconnector

By cloudbeer

Updated over 2 years ago

An Amazon Bedrock forwarding tool that can issue virtual keys, and manage costs.

Image
Machine learning & AI
0

454

cloudbeer/brconnector repository overview

BRConnector

BRConnector is a bedrock API forwarding tool that can issue virtual keys, log chats, and manage costs.

It is compatible with BRClient and any other OPENAI client that can define Host and API Key.

Deploying BRConnector

Although this project is in rapic iterating, we still provide a relative easy way to deploy the BRConnector server.

Please follow these steps to deploy the BRConnector server:

1. Prepare a server to host BRConnector

Launch an EC2 on AWS or any other server with docker support.

2. Run postgres with docker

Launch a docker container to host postgres with the following shell command:

docker run --name postgres \
  -e POSTGRES_PASSWORD=mysecretpassword \
  -p 5432:5432 \
  -d postgres

Then create a database named brconnector_db with the following command: At first, attach to the prostgress container:

docker exec -it postgres psql -U postgres

Then, in the SQL command line of postgres, run the following command to create the database:

CREATE DATABASE brconnector_db;

The database name is not necessary to be brconnector_db, you can use what ever valid database name you want. If you use your own database name, make sure that you remember the database name and replace brconnector_db with your database name.

3. Start the BRConnector server with docker

Run the following docker command directly to start the BRConnector container.

Make sure to replace the value of access key, secret key, region to be right ones

And, important! replace the value of ADMIN_API_KEY to be a complex key instead of using the simple one in the sample.

docker run --name BRConnector \
 -p 8866:8866 \
 -e AWS_ACCESS_KEY_ID=xxxx \
 -e AWS_SECRET_ACCESS_KEY=xxxxx \
 -e AWS_DEFAULT_REGION=us-east-1 \
 -e PGSQL_HOST=172.17.0.1 \
 -e PGSQL_DATABASE=brconnector_db \
 -e PGSQL_USER=postgres \
 -e PGSQL_PASSWORD=mysecretpassword \
 -e ADMIN_API_KEY=br_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
 -d cloudbeer/brconnector:0.0.1
4. Test the BRConnector server

Now, you have the first admin user with the API_KEY "br_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

And the BRConnector server export port 8866 to the hosting EC2.

Test the server with the API_Key using curl command:

curl "http://localhost:8866/admin/api-key/list"     -H "Authorization: Bearer br_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

You will get something like the following if every things go well:

{"success":true,"data":{"items":[],"total":"0","limit":20,"offset":0}}
5. Creat the first admin user

The API_KEY configed above is only used for booting the server and create first admin user. This API_KEY is not designed to be used as admin user or normal user.

Create the first admin user with the following command:

curl -X POST "http://localhost:8866/admin/api-key/apply" \
     -H "Content-Type: application/json" \
  -H "Authorization: Bearer br_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
     -d '{"name": "adminuser","group_id": 1,"role": "admin","email": "", "month_quota":"20"}'

You will get some response like the following:


{"success":true,"data":{"id":1,"name":"adminuser","email":"","api_key":"br-someotherkeyvaluexxxxx","role":"admin","month_quota":"20.0000000000","balance":"0.0000000000"}}

Record the new api_key for the new user, this api_key can be used to config BRClient to chat. and this api_key can be used to login BRConnector's WebUI to manage other users.

6. Config BRClient to connect to the BRConnector server

As BRClient only support HTTPS, you need to setup a SSL offload service in front of the BRConnector server.

One simple way to do it on AWS is creating a CloudFront CDN to provide SSL support.

For more information about setting up CloudFront on AWS, please refer to official document of AWS.

One note: please enable header forwarding and query string forwarding in your CloudFront, to make sure that all the necessary information from BRClient can be send to back end BRConnector server.

Then, open BRClient, enter configuration page, find a setting name: "Enabel BRConnector", switch the value to "True".

Then you will find a two fields to enter "AWS Endpoint" and "API Key". In the "AWS Endpoint" field, enter the CloudFront url. In the "APK Key" field, enter the API_Key of your first admin user, which is the one you created in step 5.

Then, open a new chat to test.

If every thing goes well, you can start to chat.

7. BRConnector WebUI

If you have not set the environment variable DISABLE_UI, you can now access the BRConnector WebUI via http://localhost:8866/webui.

You can log in and manage it using the API key you just generated. Enter http://localhost:8866 as the Host.

Disclaimer

BRConnector is an open-source software aimed at providing proxy services for using Bedrock Claude. We make our best efforts to ensure the security and legality of the software, but we are not responsible for the users' behavior.

BRConnector is intended solely for personal learning and research purposes. Users shall not use BRConnector for any illegal activities, including but not limited to hacking, spreading illegal information, etc. Otherwise, users shall bear the corresponding legal responsibilities themselves. Users are responsible for complying with the laws and regulations in their respective jurisdictions and shall not use BRConnector for any illegal or non-compliant purposes. The developers and maintainers of this software shall not be liable for any disputes, losses, or legal liabilities arising from the use of BRConnector.

We reserve the right to modify or terminate the BRConnector service at any time without further notice. Users are expected to understand and comply with the relevant local laws and regulations.

If you have any questions regarding this disclaimer, please feel free to contact us through the open-source channels.

Tag summary

Content type

Image

Digest

sha256:7959a5529

Size

411 MB

Last updated

over 2 years ago

docker pull cloudbeer/brconnector:0.0.3