Add arbitrary prompt endpoint, get history out to the browser
This commit is contained in:
parent
1b9130c4a5
commit
a38d46aa30
@ -28,9 +28,6 @@
|
||||
screenshotImage.src = imageUrl;
|
||||
screenshotImage.style.display = 'block';
|
||||
})
|
||||
.then(() => {
|
||||
setTimeout(takeScreenshot, 500);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error taking screenshot:', error);
|
||||
});
|
||||
@ -53,10 +50,35 @@
|
||||
});
|
||||
}
|
||||
|
||||
function updateChat() {
|
||||
fetch("/messages")
|
||||
.then(response => response.json())
|
||||
.then(messages => {
|
||||
const historyDiv = document.getElementById('chat-history');
|
||||
historyDiv.innerHTML = "";
|
||||
const definitionList = document.createElement('dl')
|
||||
historyDiv.append(definitionList);
|
||||
messages.forEach(message => {
|
||||
const dt = document.createElement('dt');
|
||||
dt.textContent = message.role;
|
||||
const dd = document.createElement('dd');
|
||||
dd.textContent = message.content[0].text || message.content[1].text;
|
||||
definitionList.append(dt);
|
||||
definitionList.append(dd);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
takeScreenshot();
|
||||
updateChat();
|
||||
setTimeout(refresh, 500);
|
||||
}
|
||||
|
||||
function init() {
|
||||
const clickableImage = document.getElementById('screenshot');
|
||||
clickableImage.addEventListener('click', handleClick);
|
||||
takeScreenshot();
|
||||
refresh();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
@ -67,6 +89,7 @@
|
||||
</div>
|
||||
|
||||
<div class="message" id="click-message"></div>
|
||||
<div id="chat-history"> </div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from flask import Flask, send_file, Response
|
||||
from flask import Flask, send_file, Response, request
|
||||
import base64
|
||||
import os
|
||||
import subprocess
|
||||
@ -68,11 +68,15 @@ def nextmove():
|
||||
image = screenshot
|
||||
)
|
||||
|
||||
@app.route('/promp-in-context')
|
||||
@app.route('/messages')
|
||||
def messages():
|
||||
return chatbot.message_history
|
||||
|
||||
@app.route('/prompt-in-context', methods=['POST'])
|
||||
def prompt():
|
||||
screenshot = game.screenshot()
|
||||
return chatbot.prompt(
|
||||
text = "we're playing Into the Breach. Describe the state of the board. Then tell me the best moves for our mechs to make.",
|
||||
text = request.get_data(as_text = True),
|
||||
image = screenshot
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user