Update ui_html.py
Browse files- ui_html.py +91 -24
ui_html.py
CHANGED
|
@@ -1,40 +1,107 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
<!doctype html>
|
| 3 |
<html>
|
| 4 |
<head>
|
| 5 |
-
<meta charset=
|
| 6 |
-
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
|
| 7 |
<title>Trading Game AI V2</title>
|
| 8 |
<style>
|
| 9 |
-
body {
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
</style>
|
| 14 |
</head>
|
| 15 |
<body>
|
| 16 |
<h1>Trading Game AI V2</h1>
|
| 17 |
-
<p>
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
\"session_id\": \"test-session-1\",
|
| 25 |
-
\"user_id\": \"test-user-1\"
|
| 26 |
-
}</textarea>
|
| 27 |
<br>
|
| 28 |
-
<button onclick=
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
<script>
|
| 31 |
async function send() {
|
| 32 |
-
const
|
| 33 |
-
const
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
}
|
| 37 |
</script>
|
| 38 |
</body>
|
| 39 |
</html>
|
| 40 |
-
"""
|
|
|
|
| 1 |
+
def get_ui_html() -> str:
|
| 2 |
+
return """
|
| 3 |
<!doctype html>
|
| 4 |
<html>
|
| 5 |
<head>
|
| 6 |
+
<meta charset="utf-8" />
|
|
|
|
| 7 |
<title>Trading Game AI V2</title>
|
| 8 |
<style>
|
| 9 |
+
body {
|
| 10 |
+
font-family: Arial, sans-serif;
|
| 11 |
+
max-width: 900px;
|
| 12 |
+
margin: 40px auto;
|
| 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;
|
| 21 |
+
font-family: monospace;
|
| 22 |
+
font-size: 14px;
|
| 23 |
+
padding: 12px;
|
| 24 |
+
box-sizing: border-box;
|
| 25 |
+
margin-top: 12px;
|
| 26 |
+
}
|
| 27 |
+
button {
|
| 28 |
+
margin-top: 12px;
|
| 29 |
+
padding: 10px 16px;
|
| 30 |
+
font-size: 14px;
|
| 31 |
+
cursor: pointer;
|
| 32 |
+
}
|
| 33 |
+
pre {
|
| 34 |
+
background: #f6f6f6;
|
| 35 |
+
padding: 12px;
|
| 36 |
+
border-radius: 8px;
|
| 37 |
+
white-space: pre-wrap;
|
| 38 |
+
word-wrap: break-word;
|
| 39 |
+
margin-top: 16px;
|
| 40 |
+
}
|
| 41 |
</style>
|
| 42 |
</head>
|
| 43 |
<body>
|
| 44 |
<h1>Trading Game AI V2</h1>
|
| 45 |
+
<p>
|
| 46 |
+
You can paste either:
|
| 47 |
+
<br>- plain text, e.g. <code>Solve: x/5 = 12</code>
|
| 48 |
+
<br>- or a full JSON request body
|
| 49 |
+
</p>
|
| 50 |
+
|
| 51 |
+
<textarea id="payload" placeholder='Type a message or paste full JSON here'></textarea>
|
|
|
|
|
|
|
|
|
|
| 52 |
<br>
|
| 53 |
+
<button onclick="send()">Send</button>
|
| 54 |
+
|
| 55 |
+
<pre id="output">No response yet.</pre>
|
| 56 |
+
|
| 57 |
<script>
|
| 58 |
async function send() {
|
| 59 |
+
const raw = document.getElementById("payload").value.trim();
|
| 60 |
+
const output = document.getElementById("output");
|
| 61 |
+
|
| 62 |
+
let payload;
|
| 63 |
+
|
| 64 |
+
try {
|
| 65 |
+
if (raw.startsWith("{")) {
|
| 66 |
+
payload = JSON.parse(raw);
|
| 67 |
+
} else {
|
| 68 |
+
payload = {
|
| 69 |
+
message: raw,
|
| 70 |
+
chat_history: [],
|
| 71 |
+
tone: 0.5,
|
| 72 |
+
verbosity: 0.5,
|
| 73 |
+
transparency: 0.5
|
| 74 |
+
};
|
| 75 |
+
}
|
| 76 |
+
} catch (e) {
|
| 77 |
+
output.textContent = "Invalid JSON: " + e.message;
|
| 78 |
+
return;
|
| 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 |
</script>
|
| 105 |
</body>
|
| 106 |
</html>
|
| 107 |
+
"""
|