FastOAI (OpenAI-like API Server)
Motivation
This project is a simple API server that can be used to serve language models. It is designed to be simple to use and easy to deploy. It is built using FastAPI, Pydantic and openai-python.
Quick Start
The following example shows a case to overriding the
original streaming response, we append [ollama] to every chunk content.
from fastapi.responses import StreamingResponse
from fastoai import FastOAI
from fastoai.requests import CompletionCreateParams
from fastoai.routers import router
from openai import AsyncOpenAI
app = FastOAI()
@app.post("/chat/completions")
async def create_chat_completions(params: CompletionCreateParams):
client = AsyncOpenAI(api_key="ollama", base_url="http://localhost:11434/v1")
response = await client.chat.completions.create(**params.model_dump())
if params.stream:
async def _stream():
async for chunk in response:
for choice in chunk.choices:
choice.delta.content += " [ollama]"
yield f"data: {chunk.model_dump_json()}\n\n"
else:
yield "data: [DONE]\n\n"
return StreamingResponse(_stream())
return response
# Order matters, you should firstly define your own entrypoint functions, then
# include the existing router in order to override the original process with
# yours
app.include_router(router)
And that's it! You can now run the server using uvicorn:
uvicorn examples.main:app --reload
Architecture
graph TD
client["`*openai client* (Python/Node.js/RESTful)`"]-->fastoai[FastOAI server]
fastoai-->ChatCompletion[OpenAI Chat Completion API]
fastoai-->openai[OpenAI API]
fastoai-->others[Any other API]
Metadata
Release files for fastoai 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fastoai-1.0.3.tar.gz | 181.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastoai-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 216.3 kB
Release files / fastoai-1.0.3.tar.gz
| Download URL | fastoai-1.0.3.tar.gz |
|---|---|
| Size | 181.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
967bc4596ab574aa976958c42a19e056477ae813e7809dbd9a18c753f46b6d0d
|
|
BLAKE2b-256 checksum How to use checksums |
cccb9bdebc38d5eae837252485e4fec387c6ae3c27feaad5132767c538febd0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|
Release files / fastoai-1.0.3-py3-none-any.whl
| Download URL | fastoai-1.0.3-py3-none-any.whl |
|---|---|
| Size | 34.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e2c2996716c480dd183952bef0a69211d24484c3e60f2ab715362cb952ac29f
|
|
BLAKE2b-256 checksum How to use checksums |
0f2fce295c520930b293266748b4e0175c7a2e42e0a6783094c938a7ba172c85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|
Security for fastoai 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.