Update ui_html.py
Browse files- ui_html.py +69 -64
ui_html.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
return """
|
| 3 |
<!doctype html>
|
| 4 |
<html>
|
| 5 |
<head>
|
|
@@ -13,8 +12,6 @@ def get_ui_html() -> str:
|
|
| 13 |
padding: 0 16px;
|
| 14 |
line-height: 1.5;
|
| 15 |
}
|
| 16 |
-
h1 { margin-bottom: 8px; }
|
| 17 |
-
p { color: #444; }
|
| 18 |
textarea {
|
| 19 |
width: 100%;
|
| 20 |
min-height: 220px;
|
|
@@ -41,67 +38,75 @@ def get_ui_html() -> str:
|
|
| 41 |
</style>
|
| 42 |
</head>
|
| 43 |
<body>
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
output.textContent = "Sending...";
|
| 82 |
-
|
| 83 |
-
try {
|
| 84 |
-
const res = await fetch("/chat", {
|
| 85 |
-
method: "POST",
|
| 86 |
-
headers: {
|
| 87 |
-
"Content-Type": "application/json"
|
| 88 |
-
},
|
| 89 |
-
body: JSON.stringify(payload)
|
| 90 |
-
});
|
| 91 |
-
|
| 92 |
-
const text = await res.text();
|
| 93 |
-
|
| 94 |
-
try {
|
| 95 |
-
const json = JSON.parse(text);
|
| 96 |
-
output.textContent = JSON.stringify(json, null, 2);
|
| 97 |
-
} catch {
|
| 98 |
-
output.textContent = text;
|
| 99 |
-
}
|
| 100 |
-
} catch (e) {
|
| 101 |
-
output.textContent = "Request failed: " + e.message;
|
| 102 |
-
}
|
| 103 |
}
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
</body>
|
| 106 |
</html>
|
| 107 |
"""
|
|
|
|
| 1 |
+
HOME_HTML = """
|
|
|
|
| 2 |
<!doctype html>
|
| 3 |
<html>
|
| 4 |
<head>
|
|
|
|
| 12 |
padding: 0 16px;
|
| 13 |
line-height: 1.5;
|
| 14 |
}
|
|
|
|
|
|
|
| 15 |
textarea {
|
| 16 |
width: 100%;
|
| 17 |
min-height: 220px;
|
|
|
|
| 38 |
</style>
|
| 39 |
</head>
|
| 40 |
<body>
|
| 41 |
+
|
| 42 |
+
<h1>Trading Game AI V2</h1>
|
| 43 |
+
|
| 44 |
+
<p>
|
| 45 |
+
You can type either:
|
| 46 |
+
<br>- plain text like <b>Solve: x/5 = 12</b>
|
| 47 |
+
<br>- or a full JSON request
|
| 48 |
+
</p>
|
| 49 |
+
|
| 50 |
+
<textarea id="payload"></textarea>
|
| 51 |
+
<br>
|
| 52 |
+
<button onclick="send()">Send</button>
|
| 53 |
+
|
| 54 |
+
<pre id="output">No response yet.</pre>
|
| 55 |
+
|
| 56 |
+
<script>
|
| 57 |
+
async function send() {
|
| 58 |
+
|
| 59 |
+
const raw = document.getElementById("payload").value.trim();
|
| 60 |
+
const output = document.getElementById("output");
|
| 61 |
+
|
| 62 |
+
let payload;
|
| 63 |
+
|
| 64 |
+
try {
|
| 65 |
+
|
| 66 |
+
if (raw.startsWith("{")) {
|
| 67 |
+
payload = JSON.parse(raw);
|
| 68 |
+
} else {
|
| 69 |
+
payload = {
|
| 70 |
+
message: raw,
|
| 71 |
+
chat_history: [],
|
| 72 |
+
tone: 0.5,
|
| 73 |
+
verbosity: 0.5,
|
| 74 |
+
transparency: 0.5
|
| 75 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
}
|
| 77 |
+
|
| 78 |
+
} catch (e) {
|
| 79 |
+
output.textContent = "Invalid JSON: " + e.message;
|
| 80 |
+
return;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
output.textContent = "Sending...";
|
| 84 |
+
|
| 85 |
+
try {
|
| 86 |
+
|
| 87 |
+
const res = await fetch("/chat", {
|
| 88 |
+
method: "POST",
|
| 89 |
+
headers: {
|
| 90 |
+
"Content-Type": "application/json"
|
| 91 |
+
},
|
| 92 |
+
body: JSON.stringify(payload)
|
| 93 |
+
});
|
| 94 |
+
|
| 95 |
+
const text = await res.text();
|
| 96 |
+
|
| 97 |
+
try {
|
| 98 |
+
const json = JSON.parse(text);
|
| 99 |
+
output.textContent = JSON.stringify(json, null, 2);
|
| 100 |
+
} catch {
|
| 101 |
+
output.textContent = text;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
} catch (e) {
|
| 105 |
+
output.textContent = "Request failed: " + e.message;
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
</script>
|
| 109 |
+
|
| 110 |
</body>
|
| 111 |
</html>
|
| 112 |
"""
|