From 0ff6bccf7f6d63811f8f3f2cd008d7127713c17e Mon Sep 17 00:00:00 2001 From: Onur ULUSOY Date: Fri, 8 Mar 2024 01:19:19 +0300 Subject: [PATCH 1/4] feat: Updated upsonic_on_prem/utils/ai/ai.py --- upsonic_on_prem/utils/ai/ai.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/upsonic_on_prem/utils/ai/ai.py b/upsonic_on_prem/utils/ai/ai.py index c235ea56..2f4e8b9e 100644 --- a/upsonic_on_prem/utils/ai/ai.py +++ b/upsonic_on_prem/utils/ai/ai.py @@ -123,6 +123,10 @@ def search_by_documentation(self, the_contents, question, min_score=0.5, how_man def completion(self, input_text, model): result = None + self.model_call_counter[model] = self.model_call_counter.get(model, 0) + 1 + call_count = self.model_call_counter[model] + if call_count % 10 == 0: + debug(f"Model {model} has been called {call_count} times.") if model == "gemma-2b": result = self.gemmma(input_text) elif model == "gpt-3.5-turbo": @@ -361,4 +365,6 @@ def check_prime(number): + model_call_counter = {} + AI = AI_() From b5fb4252962cdf17b8322df9d6b831c8394d1dc6 Mon Sep 17 00:00:00 2001 From: Onur ULUSOY Date: Fri, 8 Mar 2024 21:04:44 +0300 Subject: [PATCH 2/4] feat: Updated upsonic_on_prem/utils/ai/ai.py --- upsonic_on_prem/utils/ai/ai.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/upsonic_on_prem/utils/ai/ai.py b/upsonic_on_prem/utils/ai/ai.py index 2f4e8b9e..a1a008f3 100644 --- a/upsonic_on_prem/utils/ai/ai.py +++ b/upsonic_on_prem/utils/ai/ai.py @@ -18,6 +18,7 @@ from langchain_community.vectorstores import Chroma from upsonic_on_prem.utils import storage +from upsonic_on_prem.utils.scope import storage_3 from upsonic_on_prem.utils import debug, info, warning, failed, successfully @@ -123,8 +124,17 @@ def search_by_documentation(self, the_contents, question, min_score=0.5, how_man def completion(self, input_text, model): result = None - self.model_call_counter[model] = self.model_call_counter.get(model, 0) + 1 - call_count = self.model_call_counter[model] + import json + import traceback + try: + self.model_call_counter[model] = self.model_call_counter.get(model, 0) + 1 + call_count = self.model_call_counter[model] + if call_count % 10 == 0: + debug(f"Model {model} has been called {call_count} times.") + + storage_3.set("ai_model_call_counts", json.dumps(self.model_call_counter)) + except Exception as e: + debug(f"Failed to persist model call counts: {str(e)}") if call_count % 10 == 0: debug(f"Model {model} has been called {call_count} times.") if model == "gemma-2b": From 8ed2b76f825a45946c908045dcd34e7007a5bb27 Mon Sep 17 00:00:00 2001 From: Onur ULUSOY Date: Sat, 9 Mar 2024 02:28:57 +0300 Subject: [PATCH 3/4] feat: Updated upsonic_on_prem/utils/db/__init__.py --- upsonic_on_prem/utils/db/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/upsonic_on_prem/utils/db/__init__.py b/upsonic_on_prem/utils/db/__init__.py index a0e0442c..852b11f9 100644 --- a/upsonic_on_prem/utils/db/__init__.py +++ b/upsonic_on_prem/utils/db/__init__.py @@ -35,6 +35,7 @@ def can_access_to_config(): storage = redis_client_() storage_2 = redis_client_(db=1) storage_3 = redis_client_(db=2) + storage_4 = redis_client_(db=3) succed = True except: warning("Redis configuration failed retrying in 5 seconds") From e421d701ede163b944d1dc09560c1e3d87edb2f7 Mon Sep 17 00:00:00 2001 From: Onur ULUSOY Date: Sat, 9 Mar 2024 02:29:30 +0300 Subject: [PATCH 4/4] feat: Updated upsonic_on_prem/utils/ai/ai.py --- upsonic_on_prem/utils/ai/ai.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/upsonic_on_prem/utils/ai/ai.py b/upsonic_on_prem/utils/ai/ai.py index a1a008f3..af716058 100644 --- a/upsonic_on_prem/utils/ai/ai.py +++ b/upsonic_on_prem/utils/ai/ai.py @@ -18,7 +18,7 @@ from langchain_community.vectorstores import Chroma from upsonic_on_prem.utils import storage -from upsonic_on_prem.utils.scope import storage_3 +from upsonic_on_prem.utils.scope import storage_4 from upsonic_on_prem.utils import debug, info, warning, failed, successfully @@ -132,7 +132,7 @@ def completion(self, input_text, model): if call_count % 10 == 0: debug(f"Model {model} has been called {call_count} times.") - storage_3.set("ai_model_call_counts", json.dumps(self.model_call_counter)) + storage_4.set("ai_model_call_counts", json.dumps(self.model_call_counter)) except Exception as e: debug(f"Failed to persist model call counts: {str(e)}") if call_count % 10 == 0: