File size: 1,997 Bytes
b7fc6a5
e9462cd
 
 
1486a50
5b9d653
e9462cd
1486a50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9462cd
 
 
b7fc6a5
5b9d653
b7fc6a5
 
 
98fe651
b7fc6a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9462cd
b7fc6a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9462cd
 
1486a50
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
HOME_HTML = """
<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <title>GameAI</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      max-width: 900px;
      margin: 40px auto;
      padding: 0 16px;
      line-height: 1.5;
    }
    textarea {
      width: 100%;
      min-height: 220px;
      font-family: monospace;
      font-size: 14px;
      padding: 12px;
      box-sizing: border-box;
      margin-top: 12px;
    }
    button {
      margin-top: 12px;
      padding: 10px 16px;
      font-size: 14px;
      cursor: pointer;
    }
    pre {
      background: #f6f6f6;
      padding: 12px;
      border-radius: 8px;
      white-space: pre-wrap;
      word-wrap: break-word;
      margin-top: 16px;
    }
  </style>
</head>
<body>

<h1>GameAI</h1>

<p>
You can type either:
<br>- plain text
<br>- or a full JSON request
</p>

<textarea id="payload"></textarea>
<br>
<button onclick="send()">Send</button>

<pre id="output">No response yet.</pre>

<script>
async function send() {

  const raw = document.getElementById("payload").value.trim();
  const output = document.getElementById("output");

  let payload;

  try {

    if (raw.startsWith("{")) {
      payload = JSON.parse(raw);
    } else {
      payload = {
        message: raw,
        chat_history: [],
        tone: 0.5,
        verbosity: 0.5,
        transparency: 0.5
      };
    }

  } catch (e) {
    output.textContent = "Invalid JSON: " + e.message;
    return;
  }

  output.textContent = "Sending...";

  try {

    const res = await fetch("/chat", {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify(payload)
    });

    const text = await res.text();

    try {
      const json = JSON.parse(text);
      output.textContent = JSON.stringify(json, null, 2);
    } catch {
      output.textContent = text;
    }

  } catch (e) {
    output.textContent = "Request failed: " + e.message;
  }
}
</script>

</body>
</html>
"""