mirror of
https://github.com/OMGeeky/gpt-pilot.git
synced 2026-01-06 19:29:33 +01:00
Refactor so we use array_of_objects_to_string + added debugging file and AgentConvo method to copy js code to clipboard so it can be pasted into OpenAI playground for easier debugging
This commit is contained in:
34
euclid/const/convert_to_playground_convo.js
Normal file
34
euclid/const/convert_to_playground_convo.js
Normal file
@@ -0,0 +1,34 @@
|
||||
let messages = {{messages}}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
async function fill_playground(messages) {
|
||||
let system_messages = messages.filter(msg => msg.role === 'system');
|
||||
if (system_messages.length > 0) {
|
||||
let system_message_textarea = document.querySelector('.chat-pg-instructions').querySelector('textarea');
|
||||
system_message_textarea.focus();
|
||||
document.execCommand("insertText", false, system_messages[0].content);
|
||||
await sleep(100);
|
||||
}
|
||||
|
||||
let other_messages = messages.filter(msg => msg.role !== 'system');
|
||||
|
||||
for (let i = 0; i < other_messages.length - 1; i++) {
|
||||
document.querySelector('.add-message').click()
|
||||
await sleep(100);
|
||||
}
|
||||
|
||||
for (let i = 0; i < other_messages.length; i++) {
|
||||
let all_elements = document.querySelectorAll('.text-input-with-focus');
|
||||
let last_user_document = all_elements[i];
|
||||
|
||||
textarea_to_fill = last_user_document.querySelector('textarea');
|
||||
textarea_to_fill.focus();
|
||||
document.execCommand("insertText", false, other_messages[i].content);
|
||||
await sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
fill_playground(messages)
|
||||
@@ -1,3 +1,5 @@
|
||||
import subprocess
|
||||
from utils.utils import array_of_objects_to_string
|
||||
from utils.llm_connection import get_prompt, create_gpt_chat_completion
|
||||
from utils.utils import get_sys_message, find_role_from_step, capitalize_first_word_with_underscores
|
||||
from logger.logger import logger
|
||||
@@ -33,7 +35,7 @@ class AgentConvo:
|
||||
if isinstance(response, list):
|
||||
if isinstance(response[0], dict):
|
||||
string_response = [
|
||||
f'#{i + 1}\n' + '\n'.join([f'{key}: {value}' for key, value in d.items()])
|
||||
f'#{i + 1}\n' + array_of_objects_to_string(d)
|
||||
for i, d in enumerate(response)
|
||||
]
|
||||
else:
|
||||
@@ -70,4 +72,10 @@ class AgentConvo:
|
||||
print_msg = capitalize_first_word_with_underscores(self.high_level_step)
|
||||
print(colored(f"{print_msg}:\n", "green"))
|
||||
print(f"{content}\n")
|
||||
logger.info(f"{print_msg}: {content}\n")
|
||||
logger.info(f"{print_msg}: {content}\n")
|
||||
|
||||
def to_playground(self, path):
|
||||
with open('const/convert_to_playground_convo.js', 'r', encoding='utf-8') as file:
|
||||
content = file.read()
|
||||
process = subprocess.Popen('pbcopy', stdin=subprocess.PIPE)
|
||||
process.communicate(content.replace('{{messages}}', str(self.messages)).encode('utf-8'))
|
||||
@@ -133,8 +133,7 @@ def get_os_info():
|
||||
os_info["Mac Version"] = platform.mac_ver()[0]
|
||||
|
||||
# Convert the dictionary to a readable text format
|
||||
output = "\n".join(f"{key}: {value}" for key, value in os_info.items())
|
||||
return output
|
||||
return array_of_objects_to_string(os_info)
|
||||
|
||||
|
||||
def execute_step(matching_step, current_step):
|
||||
@@ -146,3 +145,6 @@ def execute_step(matching_step, current_step):
|
||||
|
||||
def generate_app_data(args):
|
||||
return {'app_id': args['app_id'], 'app_type': args['app_type']}
|
||||
|
||||
def array_of_objects_to_string(array):
|
||||
return '\n'.join([f'{key}: {value}' for key, value in array.items()])
|
||||
Reference in New Issue
Block a user