Skip to content

Instantly share code, notes, and snippets.

@mribbons
Created October 29, 2023 09:27
Show Gist options
  • Select an option

  • Save mribbons/5250a8d1db6bf14d1becafafb00cb892 to your computer and use it in GitHub Desktop.

Select an option

Save mribbons/5250a8d1db6bf14d1becafafb00cb892 to your computer and use it in GitHub Desktop.
Files from latest autogen inference
# Usage:
# python autogen_get_output_files.py
# * Currently only the latest cache entry is processed for # filenames
# * .db location may need to be adjusted, I have no idea how the db file is named
# files are saved in _output
import os
import sqlite3
import json
con = sqlite3.connect(".cache/41/cache.db")
cursor = con.cursor()
cache = cursor.execute("SELECT * from Cache").fetchall()
messages = json.loads(cache[-1][1])['messages']
file = None
for message in messages:
string = ""
if message['role'] == 'assistant':
lines: list[str] = message['content'].split('\n')
for line in lines:
filename_pos = line.find('# filename')
if filename_pos > -1:
filename = line[filename_pos + 12: len(line)]
print(f'writing to {os.path.join("_output", filename)}...')
if file:
file.close()
file = None
file = open(os.path.join("_output", filename), 'w')
elif (file != None):
if (line == '```'):
file.close()
file = None
else:
file.write(f'{line}\n')
con.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment