|
3 | 3 | import os |
4 | 4 |
|
5 | 5 | import requests |
6 | | -from fastapi import FastAPI, Form, Request |
| 6 | +from fastapi import FastAPI, Form |
7 | 7 | from fastapi.responses import HTMLResponse |
8 | 8 | from fastapi.staticfiles import StaticFiles |
9 | 9 | from fastapi.responses import JSONResponse |
| 10 | +from fastapi.responses import FileResponse |
10 | 11 |
|
11 | 12 | app = FastAPI() |
12 | 13 | app.mount("/static", StaticFiles(directory="static"), name="static") |
|
22 | 23 | MODEL_ID = os.getenv("LLM_MODEL", "gpt-4-turbo") |
23 | 24 |
|
24 | 25 | # Get the API key for the LLM |
25 | | -# For development, you can use your local API key. In production, the LLM gateway service will override the need for it. |
| 26 | +# For development, you have the option to use your local API key. In production, the LLM gateway service will override the need for it. |
26 | 27 | def get_api_key(): |
27 | 28 | return os.getenv("OPENAI_API_KEY", "") |
28 | 29 |
|
29 | 30 | # Home page form |
30 | 31 | @app.get("/", response_class=HTMLResponse) |
31 | 32 | async def home(): |
32 | | - return """ |
33 | | - <html> |
34 | | - <head> |
35 | | - <title>Ask the AI Model</title> |
36 | | - <script type="text/javascript" src="./static/app.js"></script> |
37 | | - </head> |
38 | | - <body> |
39 | | - <h1>Ask the AI Model</h1> |
40 | | - <form method="post" id="askForm" onsubmit="event.preventDefault(); submitForm(event);"> |
41 | | - <textarea id="prompt" name="prompt" autofocus="autofocus" rows="5" cols="60" placeholder="Enter your question here..." |
42 | | - onkeydown="if(event.key==='Enter'&&!event.shiftKey){event.preventDefault();this.form.dispatchEvent(new Event('submit', {cancelable:true}));}"></textarea> |
43 | | - <br><br> |
44 | | - <input type="submit" value="Ask"> |
45 | | - </form> |
46 | | - <hr> |
47 | | - <h2>Model's Reply:</h2> |
48 | | - <p id="reply"></p> |
49 | | - </body> |
50 | | - </html> |
51 | | - """ |
| 33 | + return FileResponse("static/index.html", media_type="text/html") |
52 | 34 |
|
53 | 35 | # Handle form submission |
54 | 36 | @app.post("/ask", response_class=JSONResponse) |
|
0 commit comments