Skip to content

xixuer/llmproxy-vercel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploy on Vercel

LLM API 反向代理

Issues GitHub pull requests

本项目旨在提供一个反向代理服务,解决在部分国家或地区无法直接访问 Google, Groq, Cerebras(Amazon cloudfront)等平台 API 的问题。

功能

通过 Vercel 边缘网络,反向代理 OpenAI、Groq、Google、Cerebras 等平台的 API 请求。

  • 支持供应商:Groq、Google、OpenAI、Cerebras、NVIDIA、Mistral、Sambanova、X.AI
  • 支持流式输出
  • 兼容 OpenAI API 规范

注:大陆不可直接访问 vercel.app 域名。如想直接访问,可参考之前作者的另一个项目llmproxy,通过 cloudflare worker 部署 LLM API 反向代理。

使用

测试 API 地址:https://llmproxy-vercel.vercel.app/ ,部署到 Vercel 后,可使用自己的 API 地址为:https://your-project-name.vercel.app/

示例 1: OpenAI

from openai import OpenAI

client = OpenAI(
    api_key="sk-proj-...",
    base_url="https://llmproxy-vercel.vercel.app/openai", # 没有 /v1 后缀
)

response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "Hello world!"}],
)

print(response.choices[0].message.content)

示例 2: Google Gemini

from openai import OpenAI

client = OpenAI(
    api_key="...",
    base_url="https://llmproxy-vercel.vercel.app/gemini",
)

response = client.chat.completions.create(
    model="gemini-1.5-flash",
    messages=[{"role": "user", "content": "Hello world!"}],
)

print(response.choices[0].message.content)

示例 3: Cerebras

curl --location 'https://llmproxy-vercel.vercel.app/cerebras/chat/completions' \
  --header 'Content-Type: application/json' \
  --header "Authorization: Bearer ${CEREBRAS_API_KEY}" \
  --data '{
    "model": "llama3.1-8b",
    "stream": false,
    "messages": [{"content": "why is fast inference important?", "role": "user"}],
    "temperature": 0,
    "max_tokens": 1024,
    "seed": 0,
    "top_p": 1
}'

Vercel 一键部署

Deploy with Vercel

本地开发测试

pip3 install -r requirements.txt
pip3 install uvicorn
uvicorn main:app --host 0.0.0.0 --port 3000 --reload

License

Copyright © 2024 ultrasev.
This project is MIT licensed.

Support me

"Buy Me A Coffee"

Contacts

  • Twitter Follow
  • GitHub Follow
  • YouTube Channel Subscribers

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%