Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API server #114

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Add API server #114

wants to merge 11 commits into from

Conversation

lloydzhou
Copy link

@lloydzhou lloydzhou commented Jul 17, 2023

Add API server

start

python rwkv/api.py RWKV-4-World-3B-v1-20230619-ctx4096_Q5_1.bin world 0.0.0.0 8000

/completions

curl localhost:8000/v1/completions -X POST -H 'Content-Type: application/json' -d '{"prompt": "你是一个历史老师,请告诉我周文王是谁?", "stream": false}'

--> 

{
  "object":"text_completion",
  "response":"周文王是中国春秋时期的一位著名君主,他统一了周围的诸侯国,并且在其统治时期内,周朝成为了中国历史上最为繁荣和强大的王朝之一。",
  "model":"rwkv",
  "choices":[{
    "text":"周文王是中国春秋时期的一位著名君主,他统一了周围的诸侯国,并且在其统治时期内,周朝成为了中国历史上最为繁荣和强大的王朝之一。",
    "index":0,
    "finish_reason":"stop"
  }],
  "usage":{
    "prompt_tokens":26,
    "completion_tokens":63
  }
}

/chat/completions

curl localhost:8000/v1/chat/completions -X POST -H 'Content-Type: application/json' -d '{
  "messages": [{
    "role": "system",
    "content": "你是一个历史老师"
  }, {
    "role": "user",
    "content": "请告诉我周文王是谁?"
  }],
  "stream": false
}'

--> 
{
  "object":"chat.completion",
  "response":"周文王是中国春秋时期的一位著名君主,他统一了周围的诸侯国,建立了周朝,并且推行了许多改革和改革措施,如推行新的制度、推广农业生产、实行法律和秩序等等。他的统治时期被称为“周文王时代”\n\n",
  "model":"rwkv",
  "choices":[{
    "delta": {
      "content": "周文王是中国春秋时期的一位著名君主,他统一了周围的诸侯国,建立了周朝,并且推行了许多改革和改革措施,如推行新的制度、推广农业生产、实行法律和秩序等等。他的统治时期被称为“周文王时代”\n\n"
    },
    "index":0,
    "finish_reason":"stop"
  }],
  "usage":{
    "prompt_tokens":55,
    "completion_tokens":94
  }
}

@l1006986533
Copy link

l1006986533 commented Jul 18, 2023

少导入了一个
from fastapi import HTTPException,status
而且也没有处理跨域问题

from fastapi.middleware.cors import CORSMiddleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

注:我纯路人,不是rwkv.cpp的开发者

@lloydzhou
Copy link
Author

Add dockerfile

docker build -t lloydzhou/rwkv-cpp-api -f Dockerfile .

# run docker
docker run --rm -it -v `pwd`/RWKV-4-World-3B-v1-20230619-ctx4096_Q4_0.bin:/RWKV-4-World-3B-v1-20230619-ctx4096_Q4_0.bin -e MODEL_PATH=/RWKV-4-World-3B-v1-20230619-ctx4096_Q4_0.bin -p 8000:8000 lloydzhou/rwkv-cpp-api 

# test 
curl localhost:8000/v1/chat/completions -X POST -H 'Content-Type: application/json' -d '{"messages": [{"role": "system", "content": "你是一个历史老师"}, {"role": "user", "content": "请告诉我周文王是谁?"}], "stream": false}'

@az13js
Copy link

az13js commented Jan 23, 2024

这个是兼容OpenAI的接口吗?

@lloydzhou
Copy link
Author

@az13js 格式是和openai的api一样的,也支持stream模式

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants