1 Star 0 Fork 0

究极进化兽/liteLLM-proxy

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_proxy.py 2.60 KB
一键复制 编辑 原始数据 按行查看 历史
ishaan-jaff 提交于 2023-09-15 01:49 +08:00 . support streaming
from typing import Dict
import requests
FASTREPL_PROXY_URL_BASE = "https://fastrepl-proxy-o8ph.zeet-berri.zeet.app"
FASTREPL_PROXY_ADMIN_KEY = "sk-fastrepl-YWp4Yw0-3_g8eaHLK3EJLw" # TODO
def new_user(monthly_budget: int) -> str:
resp = requests.post(
f"{FASTREPL_PROXY_URL_BASE}/key/new",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {FASTREPL_PROXY_ADMIN_KEY}",
},
json={"total_budget": monthly_budget},
)
print(resp.json())
return resp.json()
def cost_reset(user_api_key: str):
requests.get(
f"{FASTREPL_PROXY_URL_BASE}/cost/reset",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {user_api_key}",
},
json={"api_key": user_api_key},
)
def cost_current(user_api_key: str) -> Dict[str, str]:
resp = requests.get(
f"{FASTREPL_PROXY_URL_BASE}/cost/current",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {user_api_key}",
},
json={"api_key": user_api_key},
)
return resp.json()
def completion_request(user_api_key):
resp = requests.post(
f"{FASTREPL_PROXY_URL_BASE}/chat/completions",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {user_api_key}",
},
json={
"model": "gpt-3.5-turbo",
"messages": [
{
"content": "what is YC?",
"role": "user"
}
]
}
)
return resp.json()
if __name__ == "__main__":
key = new_user(100)["api_key"]
print("new key", key)
for _ in range(20):
print(cost_current(key))
response = completion_request(key)
print(response)
"""
Using the Proxy:
# Step1 Get a key
# Step 2 Make a completion request
playground_api_key = "sk-fastrepl-vSvPSy5YLQxeODhi__GSww"
resp = requests.post(
f"https://fastrepl-proxy-o8ph.zeet-berri.zeet.app/chat/completions",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer sk-fastrepl-vSvPSy5YLQxeODhi__GSww",
},
json={
"model": "gpt-3.5-turbo",
"messages": [
{
"content": "what is YC?",
"role": "user"
}
]
}
)
return resp.json()
"""
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mason_yang/liteLLM-proxy.git
git@gitee.com:mason_yang/liteLLM-proxy.git
mason_yang
liteLLM-proxy
liteLLM-proxy
main

搜索帮助