Skip to content

Commit

Permalink
Add log page
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-doerr committed Jul 14, 2022
1 parent 8c28f30 commit 7df797c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,24 @@
# CONFIG_DIR = os.getenv('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
# API_KEYS_LOCATION = os.path.join(CONFIG_DIR, 'openaiapirc')

PROMPTS_LOG_CSV = 'propmts.csv'
RESPONSES_LOG_CSV = 'responses.csv'

if (('log' in st.experimental_get_query_params()) and st.experimental_get_query_params()['log'][0] == 'true'):
st.title('Showing log')
try:
st.write(f'{PROMPTS_LOG_CSV}:')
with open(PROMPTS_LOG_CSV, 'r') as f:
st.write(f.read())

st.write(f'{RESPONSES_LOG_CSV}:')
with open(RESPONSES_LOG_CSV, 'r') as f:
st.write(f.read())
except FileNotFoundError:
st.write('No log found')



PROMPTS_LOG_CSV = 'propmts.csv'

def write_page_load_stats():
with open(LOG_FILE_LOAD_STATS, 'a') as f:
Expand All @@ -123,6 +138,10 @@ def log_prompt(prompt):
with open(PROMPTS_LOG_CSV, 'a') as f:
f.write(f'{time.time()},{prompt}\n')

def log_response(response):
with open(RESPONSES_LOG_CSV, 'a') as f:
f.write(f'{time.time()},{response}\n')


def load_prompts_with_times():
if not os.path.isfile(PROMPTS_LOG_CSV):
Expand Down Expand Up @@ -214,4 +233,6 @@ def initialize_openai_api():

print("completion_all:", completion_all)

log_response(completion_all)


0 comments on commit 7df797c

Please sign in to comment.