Hansimov commited on
Commit
6e2fad5
1 Parent(s): 37be019

:gem: [Feature] ChatAPIApp: New /readme route

Browse files
Files changed (2) hide show
  1. apis/chat_api.py +18 -0
  2. requirements.txt +1 -0
apis/chat_api.py CHANGED
@@ -1,9 +1,12 @@
1
  import argparse
 
2
  import os
3
  import sys
4
  import uvicorn
5
 
 
6
  from fastapi import FastAPI, Depends
 
7
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
8
  from pydantic import BaseModel, Field
9
  from typing import Union
@@ -123,6 +126,15 @@ class ChatAPIApp:
123
  data_response = streamer.chat_return_dict(stream_response)
124
  return data_response
125
 
 
 
 
 
 
 
 
 
 
126
  def setup_routes(self):
127
  for prefix in ["", "/v1", "/api", "/api/v1"]:
128
  include_in_schema = True if prefix == "" else False
@@ -137,6 +149,12 @@ class ChatAPIApp:
137
  summary="Chat completions in conversation session",
138
  include_in_schema=include_in_schema,
139
  )(self.chat_completions)
 
 
 
 
 
 
140
 
141
 
142
  class ArgParser(argparse.ArgumentParser):
 
1
  import argparse
2
+ import markdown2
3
  import os
4
  import sys
5
  import uvicorn
6
 
7
+ from pathlib import Path
8
  from fastapi import FastAPI, Depends
9
+ from fastapi.responses import HTMLResponse
10
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
11
  from pydantic import BaseModel, Field
12
  from typing import Union
 
126
  data_response = streamer.chat_return_dict(stream_response)
127
  return data_response
128
 
129
+ def get_readme(self):
130
+ readme_path = Path(__file__).parents[1] / "README.md"
131
+ with open(readme_path, "r", encoding="utf-8") as rf:
132
+ readme_str = rf.read()
133
+ readme_html = markdown2.markdown(
134
+ readme_str, extras=["table", "fenced-code-blocks", "highlightjs-lang"]
135
+ )
136
+ return readme_html
137
+
138
  def setup_routes(self):
139
  for prefix in ["", "/v1", "/api", "/api/v1"]:
140
  include_in_schema = True if prefix == "" else False
 
149
  summary="Chat completions in conversation session",
150
  include_in_schema=include_in_schema,
151
  )(self.chat_completions)
152
+ self.app.get(
153
+ "/readme",
154
+ summary="README of HF LLM API",
155
+ response_class=HTMLResponse,
156
+ include_in_schema=False,
157
+ )(self.get_readme)
158
 
159
 
160
  class ArgParser(argparse.ArgumentParser):
requirements.txt CHANGED
@@ -1,6 +1,7 @@
1
  aiohttp
2
  fastapi
3
  httpx
 
4
  openai
5
  pydantic
6
  requests
 
1
  aiohttp
2
  fastapi
3
  httpx
4
+ markdown2[all]
5
  openai
6
  pydantic
7
  requests