Spaces:
Paused
Paused
:gem: [Feature] ChatAPIApp: New /readme route
Browse files- apis/chat_api.py +21 -0
- requirements.txt +1 -0
apis/chat_api.py
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
import argparse
|
|
|
|
| 2 |
import sys
|
| 3 |
import uvicorn
|
|
|
|
| 4 |
from fastapi import FastAPI
|
|
|
|
|
|
|
| 5 |
from pydantic import BaseModel, Field
|
| 6 |
from sse_starlette.sse import EventSourceResponse
|
| 7 |
from conversations import (
|
|
@@ -21,6 +25,7 @@ class ChatAPIApp:
|
|
| 21 |
version="1.0",
|
| 22 |
)
|
| 23 |
self.setup_routes()
|
|
|
|
| 24 |
|
| 25 |
def get_available_models(self):
|
| 26 |
self.available_models = {
|
|
@@ -124,6 +129,15 @@ class ChatAPIApp:
|
|
| 124 |
media_type="text/event-stream",
|
| 125 |
)
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
def setup_routes(self):
|
| 128 |
for prefix in ["", "/v1", "/api", "/api/v1"]:
|
| 129 |
include_in_schema = True if prefix == "" else False
|
|
@@ -145,6 +159,13 @@ class ChatAPIApp:
|
|
| 145 |
include_in_schema=include_in_schema,
|
| 146 |
)(self.chat_completions)
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
class ArgParser(argparse.ArgumentParser):
|
| 150 |
def __init__(self, *args, **kwargs):
|
|
|
|
| 1 |
import argparse
|
| 2 |
+
import markdown2
|
| 3 |
import sys
|
| 4 |
import uvicorn
|
| 5 |
+
from pathlib import Path
|
| 6 |
from fastapi import FastAPI
|
| 7 |
+
from fastapi.responses import HTMLResponse
|
| 8 |
+
from fastapi.staticfiles import StaticFiles
|
| 9 |
from pydantic import BaseModel, Field
|
| 10 |
from sse_starlette.sse import EventSourceResponse
|
| 11 |
from conversations import (
|
|
|
|
| 25 |
version="1.0",
|
| 26 |
)
|
| 27 |
self.setup_routes()
|
| 28 |
+
self.app.mount("/docs", StaticFiles(directory="docs", html=True), name="docs")
|
| 29 |
|
| 30 |
def get_available_models(self):
|
| 31 |
self.available_models = {
|
|
|
|
| 129 |
media_type="text/event-stream",
|
| 130 |
)
|
| 131 |
|
| 132 |
+
def get_readme(self):
|
| 133 |
+
readme_path = Path(__file__).parents[1] / "README.md"
|
| 134 |
+
with open(readme_path, "r", encoding="utf-8") as rf:
|
| 135 |
+
readme_str = rf.read()
|
| 136 |
+
readme_html = markdown2.markdown(
|
| 137 |
+
readme_str, extras=["table", "fenced-code-blocks", "highlightjs-lang"]
|
| 138 |
+
)
|
| 139 |
+
return readme_html
|
| 140 |
+
|
| 141 |
def setup_routes(self):
|
| 142 |
for prefix in ["", "/v1", "/api", "/api/v1"]:
|
| 143 |
include_in_schema = True if prefix == "" else False
|
|
|
|
| 159 |
include_in_schema=include_in_schema,
|
| 160 |
)(self.chat_completions)
|
| 161 |
|
| 162 |
+
self.app.get(
|
| 163 |
+
"/readme",
|
| 164 |
+
summary="README of Bing Chat API",
|
| 165 |
+
response_class=HTMLResponse,
|
| 166 |
+
include_in_schema=False,
|
| 167 |
+
)(self.get_readme)
|
| 168 |
+
|
| 169 |
|
| 170 |
class ArgParser(argparse.ArgumentParser):
|
| 171 |
def __init__(self, *args, **kwargs):
|
requirements.txt
CHANGED
|
@@ -2,6 +2,7 @@ aiohttp
|
|
| 2 |
fastapi
|
| 3 |
httpx
|
| 4 |
openai
|
|
|
|
| 5 |
pydantic
|
| 6 |
requests
|
| 7 |
sse_starlette
|
|
|
|
| 2 |
fastapi
|
| 3 |
httpx
|
| 4 |
openai
|
| 5 |
+
markdown2[all]
|
| 6 |
pydantic
|
| 7 |
requests
|
| 8 |
sse_starlette
|