LostRuins / koboldcpp

Run GGUF models easily with a KoboldAI UI. One File. Zero Install.
https://github.com/lostruins/koboldcpp
GNU Affero General Public License v3.0
5.27k stars 360 forks source link

[patch] Fix path calculation when symbolic link is present #1110

Closed yurivict closed 1 month ago

yurivict commented 2 months ago

Sorry that I can't fork this repository due to some GitHub glitch.

This patch:

--- koboldcpp.py.orig   2024-09-01 15:51:59 UTC
+++ koboldcpp.py
@@ -4159,8 +4159,9 @@ def main(launch_args,start_server=True):

     #load embedded lite
+    basepath = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+
     try:
-        basepath = os.path.abspath(os.path.dirname(__file__))
         with open(os.path.join(basepath, "klite.embd"), mode='rb') as f:
             embedded_kailite = f.read()
             # patch it with extra stuff
@@ -4174,7 +4175,6 @@ def main(launch_args,start_server=True):
         print("Could not find KoboldAI Lite. Embedded KoboldAI Lite will not be available.")

     try:
-        basepath = os.path.abspath(os.path.dirname(__file__))
         with open(os.path.join(basepath, "kcpp_docs.embd"), mode='rb') as f:
             embedded_kcpp_docs = f.read()
             print("Embedded API docs loaded.")
@@ -4182,7 +4182,6 @@ def main(launch_args,start_server=True):
         print("Could not find Embedded KoboldCpp API docs.")

     try:
-        basepath = os.path.abspath(os.path.dirname(__file__))
         with open(os.path.join(basepath, "kcpp_sdui.embd"), mode='rb') as f:
             embedded_kcpp_sdui = f.read()
             if args.sdmodel:

fixes the problem when /usr/local/bin/kobold is a symlink to the path where kobold.py is installed. In such case the embedded files were looked for in /usr/local/bin instead of the linked location.

"os.path.realpath" is necessary there. Plus it fixes code duplication in this area of code.

LostRuins commented 2 months ago

Alright, can you check if the latest experimental solves it for you?

yurivict commented 1 month ago

The latest release is free of this problem. Thank you.