@@ -28,6 +28,7 @@ class LLMChatClient(QWidget):
2828 def __init__ (self , ai_api : "LiteLLMAIAPI" , parent = None , context : Context = None ):
2929 super (LLMChatClient , self ).__init__ (parent )
3030 self .model = ai_api .get_model ()
31+ self .custom_endpoint = ai_api .get_custom_endpoint ()
3132 self .ai_api = ai_api
3233 self .context = context
3334 self .setWindowTitle ('LLM Chat' )
@@ -65,6 +66,7 @@ def __init__(self, ai_api: "LiteLLMAIAPI", parent=None, context: Context = None)
6566
6667 # Chat history
6768 self .chat_history = []
69+ self .thread = None
6870
6971 # model check
7072 if not self .model :
@@ -152,7 +154,9 @@ def send_message(self, add_text=True, role="user"):
152154 self .send_button .setDisabled (True )
153155
154156 # Start a thread to get the response
155- self .thread = LLMThread (self .chat_history , self .model )
157+ self .thread = LLMThread (
158+ self .chat_history , self .model , custom_endpoint = self .custom_endpoint , api_key = self .ai_api .api_key
159+ )
156160 self .thread .response_received .connect (lambda msg : self .receive_message (msg ))
157161 self .thread .start ()
158162
@@ -183,10 +187,12 @@ def closeEvent(self, event):
183187class LLMThread (QThread ):
184188 response_received = pyqtSignal (str )
185189
186- def __init__ (self , chat_history , model_name ):
190+ def __init__ (self , chat_history , model_name , custom_endpoint = None , api_key = None ):
187191 super ().__init__ ()
188192 self .chat_history = chat_history .copy ()
189193 self .model_name = model_name
194+ self .custom_endpoint = custom_endpoint
195+ self .api_key = api_key
190196
191197 def run (self ):
192198 import litellm
@@ -196,8 +202,9 @@ def run(self):
196202 response = litellm .completion (
197203 model = self .model_name ,
198204 messages = self .chat_history ,
199- timeout = 60 ,
200-
205+ timeout = 60 if not self .custom_endpoint else 300 ,
206+ api_base = self .custom_endpoint if self .custom_endpoint else None , # Use custom endpoint if set
207+ api_key = self .api_key if not self .custom_endpoint else "dummy" # In most of cases custom endpoint doesn't need the api_key
201208 )
202209 litellm .modify_params = False
203210
0 commit comments