Skip to content

Commit

Permalink
fixed ssl cert path set if empty, added some basic cleanup of old tem…
Browse files Browse the repository at this point in the history
…p dirs
  • Loading branch information
LostRuins committed Apr 8, 2024
1 parent 125f84a commit fc881b4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions koboldcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,9 @@ def make_url_request(url, data, method='POST', headers={}):
global nocertify
try:
request = None
ssl_cert_dir = os.environ.get('SSL_CERT_DIR')
if not ssl_cert_dir and not nocertify and os.name != 'nt':
os.environ['SSL_CERT_DIR'] = '/etc/ssl/certs'
ssl_context = ssl.create_default_context()
if nocertify:
ssl_context.check_hostname = False
Expand Down Expand Up @@ -2719,6 +2722,31 @@ def loadconfigfile(filename):
for key, value in config.items():
setattr(args, key, value)


def delete_old_pyinstaller():
try:
base_path = sys._MEIPASS
except Exception:
return # not running from pyinstaller
if not base_path:
return

import time, os, shutil
selfdirpath = os.path.abspath(base_path)
temp_parentdir_path = os.path.abspath(os.path.join(base_path, '..'))
for dirname in os.listdir(temp_parentdir_path):
absdirpath = os.path.abspath(os.path.join(temp_parentdir_path, dirname))
if os.path.isdir(absdirpath) and os.path.basename(absdirpath).startswith('_MEI'): #only delete kobold pyinstallers
if absdirpath!=selfdirpath and (time.time() - os.path.getctime(absdirpath)) > 3600: # remove if older than 1 hour
kobold_itemcheck1 = os.path.join(absdirpath, 'koboldcpp_default.dll')
kobold_itemcheck2 = os.path.join(absdirpath, 'koboldcpp_default.so')
if os.path.exists(kobold_itemcheck1) or os.path.exists(kobold_itemcheck2):
try:
shutil.rmtree(absdirpath)
print(f"Deleted orphaned pyinstaller dir: {absdirpath}")
except Exception as e:
print(f"Error deleting orphaned pyinstaller dir: {absdirpath}: {e}")

def sanitize_string(input_string):
# alphanumeric characters, dots, dashes, and underscores
import re
Expand All @@ -2730,6 +2758,10 @@ def main(launch_args,start_server=True):
args = launch_args
embedded_kailite = None
embedded_kcpp_docs = None

#perform some basic cleanup of old temporary directories
delete_old_pyinstaller()

if args.config and len(args.config)==1:
if isinstance(args.config[0], str) and os.path.exists(args.config[0]):
loadconfigfile(args.config[0])
Expand Down

0 comments on commit fc881b4

Please sign in to comment.