File size: 1,988 Bytes
85582c9
 
c8f03da
 
 
 
 
 
 
49158eb
c8f03da
85582c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
808ec17
2f3bde3
 
 
85582c9
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
import logging

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Initialize FastAPI app
app = FastAPI()

# Serve HTML page
@app.get("/", response_class=HTMLResponse)
async def serve_html():
    logger.info("Serving HTML page")
    return """
    <html>
    <head>
        <title>AI Chemistry Chat</title>
        <style>
            body { font-family: Arial, sans-serif; margin: 20px; }
            #response { white-space: pre-wrap; border: 1px solid #ccc; padding: 10px; min-height: 100px; }
            input { width: 300px; padding: 5px; }
            button { padding: 5px 10px; }
        </style>
    </head>
    <body>
        <h1>AI Chemistry Chat</h1>
        <input type="text" id="prompt" placeholder="Ask about chemistry..." value="Tell me something I might not know about chemistry." />
        <button onclick="sendPrompt()">Send</button>
        <div id="response"></div>
        <script src="https://js.puter.com/v2/"></script>
        <script>
            async function sendPrompt() {
                const prompt = document.getElementById('prompt').value;
                const responseDiv = document.getElementById('response');
                responseDiv.innerHTML = 'Loading...';
                try {
                    const resp = await puter.ai.chat(prompt, { model: 'grok-beta', stream: true });
                    responseDiv.innerHTML = '';
                    for await (const part of resp) {
                        responseDiv.innerHTML += part?.text?.replaceAll('\\n', '<br>') || '';
                    }
                } catch (error) {
                    responseDiv.innerHTML = 'Error: ' + error.message;
                }
            }
        </script>
    </body>
    </html>
    """

# Health check endpoint
@app.get("/health")
async def health():
    logger.info("Health check requested")
    return {"status": "healthy"}