From 7f18a121526d7493e86815204a376a5235277978 Mon Sep 17 00:00:00 2001 From: winternewt Date: Tue, 10 Sep 2024 23:28:56 +0300 Subject: [PATCH 1/3] Custom OpenAI endpoint support --- biochatter/llm_connect.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/biochatter/llm_connect.py b/biochatter/llm_connect.py index 9c2bba6c..c9677e2a 100644 --- a/biochatter/llm_connect.py +++ b/biochatter/llm_connect.py @@ -1319,6 +1319,7 @@ def __init__( prompts: dict, correct: bool = False, split_correction: bool = False, + base_url : str = None, ): """ Connect to OpenAI's GPT API and set up a conversation with the user. @@ -1333,6 +1334,8 @@ def __init__( split_correction (bool): Whether to correct the model output by splitting the output into sentences and correcting each sentence individually. + + base_url (str): Optional OpenAI base_url value to use custom endpoint URL instead of default """ super().__init__( model_name=model_name, @@ -1340,7 +1343,7 @@ def __init__( correct=correct, split_correction=split_correction, ) - + self.base_url = base_url self.ca_model_name = "gpt-3.5-turbo" # TODO make accessible by drop-down @@ -1359,6 +1362,7 @@ def set_api_key(self, api_key: str, user: str) -> bool: """ client = openai.OpenAI( api_key=api_key, + base_url=self.base_url ) self.user = user From c28fc3445266ac7450379d067ca98e6efdccfddb Mon Sep 17 00:00:00 2001 From: winternewt Date: Tue, 10 Sep 2024 23:46:25 +0300 Subject: [PATCH 2/3] Custom OpenAI endpoint support --- biochatter/llm_connect.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/biochatter/llm_connect.py b/biochatter/llm_connect.py index c9677e2a..cbf772d3 100644 --- a/biochatter/llm_connect.py +++ b/biochatter/llm_connect.py @@ -1362,7 +1362,7 @@ def set_api_key(self, api_key: str, user: str) -> bool: """ client = openai.OpenAI( api_key=api_key, - base_url=self.base_url + base_url=self.base_url, ) self.user = user @@ -1372,11 +1372,13 @@ def set_api_key(self, api_key: str, user: str) -> bool: model_name=self.model_name, temperature=0, openai_api_key=api_key, + base_url=self.base_url, ) self.ca_chat = ChatOpenAI( model_name=self.ca_model_name, temperature=0, openai_api_key=api_key, + base_url=self.base_url, ) if user == "community": self.usage_stats = get_stats(user=user) From 49e84d5d3a9f9cd53e8967e255e34683e473d09f Mon Sep 17 00:00:00 2001 From: slobentanzer Date: Thu, 19 Sep 2024 11:16:24 +0200 Subject: [PATCH 3/3] docstring --- biochatter/llm_connect.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/biochatter/llm_connect.py b/biochatter/llm_connect.py index cbf772d3..e375079f 100644 --- a/biochatter/llm_connect.py +++ b/biochatter/llm_connect.py @@ -1167,8 +1167,8 @@ def _primary_query(self): as context. Correct the response if necessary. Returns: - tuple: A tuple containing the response from the Anthropic API and the - token usage. + tuple: A tuple containing the response from the Anthropic API and + the token usage. """ try: history = self._create_history() @@ -1319,7 +1319,7 @@ def __init__( prompts: dict, correct: bool = False, split_correction: bool = False, - base_url : str = None, + base_url: str = None, ): """ Connect to OpenAI's GPT API and set up a conversation with the user. @@ -1335,7 +1335,8 @@ def __init__( splitting the output into sentences and correcting each sentence individually. - base_url (str): Optional OpenAI base_url value to use custom endpoint URL instead of default + base_url (str): Optional OpenAI base_url value to use custom + endpoint URL instead of default """ super().__init__( model_name=model_name,