import fastapi import markdown import uvicorn from ctransformers import AutoModelForCausalLM from fastapi.responses import HTMLResponse from fastapi.middleware.cors import CORSMiddleware from sse_starlette.sse import EventSourceResponse from pydantic import BaseModel llm = AutoModelForCausalLM.from_pretrained("NeoDim/starchat-alpha-GGML", model_file="starchat-alpha-ggml-q4_0.bin", model_type="starcoder") app = fastapi.FastAPI(title="Starchat Alpha") app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) @app.get("/") async def index(): with open("README.md", "r", encoding="utf-8") as readme_file: md_template_string = readme_file.read() html_content = markdown.markdown(md_template_string) return HTMLResponse(content=html_content, status_code=200) @app.get("/demo") async def demo(): html_content = """