Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep: Make a counter system to AI calls in upsonic_on_prem/utils/ai/ai.py (✓ Sandbox Passed) #68

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
0ff6bcc
feat: Updated upsonic_on_prem/utils/ai/ai.py
onuratakan Mar 7, 2024
c3b0cf1
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 8, 2024
b5fb425
feat: Updated upsonic_on_prem/utils/ai/ai.py
onuratakan Mar 8, 2024
15b0283
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 8, 2024
2603b97
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 8, 2024
aae1d2a
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 8, 2024
27cb98c
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 8, 2024
8ed2b76
feat: Updated upsonic_on_prem/utils/db/__init__.py
onuratakan Mar 8, 2024
e421d70
feat: Updated upsonic_on_prem/utils/ai/ai.py
onuratakan Mar 8, 2024
450b294
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 9, 2024
26fe72f
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 9, 2024
b57d795
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 9, 2024
e1ef3a6
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 9, 2024
8bbedcb
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 9, 2024
8222c30
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 9, 2024
f940c9f
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 9, 2024
c1c8faa
Merge main into sweep/make_a_counter_system_to_ai_calls_in_ups
onuratakan Mar 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions upsonic_on_prem/utils/ai/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_4

from upsonic_on_prem.utils import debug, info, warning, failed, successfully

Expand Down Expand Up @@ -123,6 +124,19 @@

def completion(self, input_text, model):
result = None
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_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:

Check warning on line 138 in upsonic_on_prem/utils/ai/ai.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Unbound local variables

Local variable 'call_count' might be referenced before assignment
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":
Expand Down Expand Up @@ -361,4 +375,6 @@



model_call_counter = {}

AI = AI_()
1 change: 1 addition & 0 deletions upsonic_on_prem/utils/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading