Browse Source

serve tinychat static

Alex Cheema 1 year ago
parent
commit
a94bdbb9bd
1 changed files with 7 additions and 0 deletions
  1. 7 0
      exo/api/chatgpt_api.py

+ 7 - 0
exo/api/chatgpt_api.py

@@ -2,6 +2,7 @@ import uuid
 import time
 import time
 import asyncio
 import asyncio
 import json
 import json
+from pathlib import Path
 from transformers import AutoTokenizer
 from transformers import AutoTokenizer
 from typing import List, Literal, Union
 from typing import List, Literal, Union
 from aiohttp import web
 from aiohttp import web
@@ -124,6 +125,12 @@ class ChatGPTAPI:
                 allow_methods="*",
                 allow_methods="*",
             )
             )
         })
         })
+        self.static_dir = Path(__file__).parent.parent.parent / 'tinychat/examples/tinychat'
+        self.app.router.add_get('/', self.handle_root)
+        self.app.router.add_static('/', self.static_dir, name='static', show_index=False)
+
+    async def handle_root(self, request):
+        return web.FileResponse(self.static_dir / 'index.html')
 
 
     async def handle_post(self, request):
     async def handle_post(self, request):
         data = await request.json()
         data = await request.json()