mirror of
https://github.com/lanqian528/chat2api.git
synced 2026-06-13 21:02:46 +08:00
Merge pull request #165 from jasonwu1994/feature/add-token-via-get
Add new GET API for adding single token
This commit is contained in:
commit
fde16c87f0
11
chat2api.py
11
chat2api.py
@ -131,6 +131,17 @@ async def error_tokens():
|
||||
return {"status": "success", "error_tokens": error_tokens_list}
|
||||
|
||||
|
||||
@app.get(f"/{api_prefix}/tokens/add/{{token}}" if api_prefix else "/tokens/add/{token}")
|
||||
async def add_token(token: str):
|
||||
if token.strip() and not token.startswith("#"):
|
||||
globals.token_list.append(token.strip())
|
||||
with open("data/token.txt", "a", encoding="utf-8") as f:
|
||||
f.write(token.strip() + "\n")
|
||||
logger.info(f"Token count: {len(globals.token_list)}, Error token count: {len(globals.error_token_list)}")
|
||||
tokens_count = len(set(globals.token_list) - set(globals.error_token_list))
|
||||
return {"status": "success", "tokens_count": tokens_count}
|
||||
|
||||
|
||||
if enable_gateway:
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def chatgpt_html(request: Request):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user