Skip to content

Commit

Permalink
feat: create Bard-Proxy project
Browse files Browse the repository at this point in the history
1. init project.
  • Loading branch information
xuyuan23 committed Jul 31, 2023
1 parent c2d12ef commit cc0e923
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# see bard.google.com -> F12 -> Application -> Cookies (https://bard.google.com) -> __Secure-1PSID
BARD_PROXY_API_KEY={your-bard-key}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
.vscode
*.so
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 使用 Python 3.8 作为基础镜像
FROM python:3.8

# 将当前目录下的文件复制到容器的 /app 目录中
COPY . /app

# 设置工作目录为 /app
WORKDIR /app

# 安装依赖包
RUN pip install -r requirements.txt

# 暴露容器的端口
EXPOSE 8671

# 运行应用
CMD ["python", "main.py"]
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# Bard-Proxy
A proxy for Bard LLM
Proxy for Bard LLM

## How to get your bard key

Access from <a ref="https://bard.google.com/">Bard</a>

<p align="left">
<img src="./assets/bard_key.png" width="600px" />
</p>


## Quick Start

### Method 1: Quick Start by Docker

```commandline
# use your own bard key 'YOUR-BARD-KEY' instead.
docker run -p 8671:8671 -e BARD_PROXY_API_KEY=YOUR-BARD-KEY bard_proxy
```

### Method 2: Start In Current Project
1. set your bard key in .env file
2. start python project
> python main.py
Binary file added assets/bard_key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
from flask import Flask, request
import bardapi
from dotenv import load_dotenv

load_dotenv()

app = Flask(__name__)

token = os.getenv("BARD_PROXY_API_KEY", "Not config")


@app.route('/api/openai/v1/chat/completions', methods=['POST'])
def do_request():
print(f'token={token}')
input_text = request.json.get('input')
response = bardapi.core.Bard(token).get_answer(input_text)
if response and response.get('content'):
return response['content']
return f"bard request error: response={str(response)}"


if __name__ == '__main__':
app.run(host='0.0.0.0', port=8671)
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bardapi==0.1.29
flask
python-dotenv

0 comments on commit cc0e923

Please sign in to comment.