mirror of
https://github.com/sean1832/GPT-Brain
synced 2024-11-18 21:25:53 +00:00
Implement log file limit: add max limit on number of log files allowed, delete oldest if exceeding limit
This commit is contained in:
parent
73cc9caaf6
commit
c9ada48782
@ -1,6 +1,5 @@
|
||||
import streamlit as st
|
||||
from modules import utilities as util
|
||||
import initial_file_creator
|
||||
import brain
|
||||
import check_update
|
||||
import time
|
||||
@ -14,6 +13,8 @@ st.set_page_config(
|
||||
page_title='Seanium Brain'
|
||||
)
|
||||
|
||||
util.remove_oldest_file('.user/log', 10)
|
||||
|
||||
model_options = ['text-davinci-003', 'text-curie-001', 'text-babbage-001', 'text-ada-001']
|
||||
header = st.container()
|
||||
body = st.container()
|
||||
@ -66,7 +67,7 @@ with st.sidebar:
|
||||
summary_model = st.selectbox('Summary Model', model_options)
|
||||
|
||||
temp = st.slider('Temperature', 0.0, 1.0, value=0.1)
|
||||
max_tokens = st.slider('Max Tokens', 850, 2500, value=1000)
|
||||
max_tokens = st.slider('Max Tokens', 850, 4500, value=1000)
|
||||
top_p = st.slider('Top_P', 0.0, 1.0, value=1.0)
|
||||
freq_panl = st.slider('Frequency penalty', 0.0, 1.0, value=0.0)
|
||||
pres_panl = st.slider('Presence penalty', 0.0, 1.0, value=0.0)
|
||||
|
@ -1,5 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
import glob
|
||||
|
||||
|
||||
# def extract_string(text, delimiter):
|
||||
@ -10,29 +11,34 @@ import os
|
||||
|
||||
|
||||
def extract_string(text, delimiter, force=False, join=True, split_mode=False):
|
||||
if not delimiter in text:
|
||||
if force:
|
||||
return ''
|
||||
else:
|
||||
return text
|
||||
# Check if delimiter is not in text
|
||||
if delimiter not in text:
|
||||
# If force is True, return empty string; otherwise, return the original text
|
||||
return '' if force else text
|
||||
# If split_mode is True, split text by delimiter and return the resulting list
|
||||
elif split_mode:
|
||||
return text.split(delimiter)
|
||||
else:
|
||||
if split_mode:
|
||||
return text.split(delimiter)
|
||||
else:
|
||||
substring = text.split(delimiter)
|
||||
result = []
|
||||
for i in range(1, len(substring), 2):
|
||||
result.append(substring[i])
|
||||
if join:
|
||||
return ''.join(result)
|
||||
else:
|
||||
return result
|
||||
substring = text.split(delimiter)
|
||||
result = []
|
||||
# Split text by delimiter and select every second item starting from the second one
|
||||
for i in range(1, len(substring), 2):
|
||||
result.append(substring[i])
|
||||
# If join is True, join the resulting list into a string and return it; otherwise, return the list
|
||||
return ''.join(result) if join else result
|
||||
|
||||
|
||||
def create_not_exist(path):
|
||||
dir = os.path.dirname(path)
|
||||
if not os.path.exists(dir):
|
||||
os.makedirs(dir)
|
||||
def remove_oldest_file(directory, max_files):
|
||||
files = glob.glob(f'{directory}/*')
|
||||
if len(files) >= max_files:
|
||||
oldest_file = min(files, key=os.path.getctime)
|
||||
os.remove(oldest_file)
|
||||
|
||||
|
||||
def create_path_not_exist(path):
|
||||
directory = os.path.dirname(path)
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
|
||||
|
||||
def create_file_not_exist(path):
|
||||
@ -78,7 +84,7 @@ def read_files(file_dir, delimiter='', force=False, single_string=True):
|
||||
|
||||
|
||||
def write_file(content, filepath, mode='w'):
|
||||
create_not_exist(filepath)
|
||||
create_path_not_exist(filepath)
|
||||
with open(filepath, mode, encoding='utf-8') as file:
|
||||
file.write(content)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user