Skip to content

Commit

Permalink
💎 [Feature] ChatAPIApp: New /readme route
Browse files Browse the repository at this point in the history
  • Loading branch information
Hansimov committed Jan 21, 2024
1 parent 845f414 commit a178fd6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apis/chat_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import argparse
import markdown2
import sys
import uvicorn
from pathlib import Path
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel, Field
from sse_starlette.sse import EventSourceResponse
from conversations import (
Expand All @@ -21,6 +25,7 @@ def __init__(self):
version="1.0",
)
self.setup_routes()
self.app.mount("/docs", StaticFiles(directory="docs", html=True), name="docs")

def get_available_models(self):
self.available_models = {
Expand Down Expand Up @@ -124,6 +129,15 @@ def chat_completions(self, item: ChatCompletionsPostItem):
media_type="text/event-stream",
)

def get_readme(self):
readme_path = Path(__file__).parents[1] / "README.md"
with open(readme_path, "r", encoding="utf-8") as rf:
readme_str = rf.read()
readme_html = markdown2.markdown(
readme_str, extras=["table", "fenced-code-blocks", "highlightjs-lang"]
)
return readme_html

def setup_routes(self):
for prefix in ["", "/v1", "/api", "/api/v1"]:
include_in_schema = True if prefix == "" else False
Expand All @@ -145,6 +159,13 @@ def setup_routes(self):
include_in_schema=include_in_schema,
)(self.chat_completions)

self.app.get(
"/readme",
summary="README of Bing Chat API",
response_class=HTMLResponse,
include_in_schema=False,
)(self.get_readme)


class ArgParser(argparse.ArgumentParser):
def __init__(self, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ aiohttp
fastapi
httpx
openai
markdown2[all]
pydantic
requests
sse_starlette
Expand Down

0 comments on commit a178fd6

Please sign in to comment.