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 #67

Open
2 tasks done
onuratakan opened this issue Mar 7, 2024 · 2 comments
Open
2 tasks done
Labels

Comments

@onuratakan
Copy link
Member

onuratakan commented Mar 7, 2024

I want to track which models are using in what frequency. Make a counter and create debug log in every 10 call.

Checklist
  • Modify upsonic_on_prem/utils/ai/ai.py0ff6bcc Edit
  • Running GitHub Actions for upsonic_on_prem/utils/ai/ai.pyEdit
@onuratakan
Copy link
Member Author

onuratakan commented Mar 7, 2024

Sweeping

50%

💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: None)

Tip

I can email you when I complete this pull request if you set up your email here!


Actions (click)

  • ↻ Restart Sweep

Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.

https://github.com/Upsonic/On-Prem/blob/977a50d24d4eb91eaecffb023c8a544f4883e3c6/upsonic_on_prem/utils/ai/ai.py#L2-L363


Step 2: ⌨️ Coding

  • upsonic_on_prem/utils/ai/ai.py
Modify upsonic_on_prem/utils/ai/ai.py with contents:
• At the beginning of the `AI_` class, define a dictionary named `model_usage_counter` to track the number of calls for each model. Initialize this dictionary with keys for each model (`"gemma-2b"`, `"gpt-3.5-turbo"`, `"gpt-4"`) and set their values to 0.
• In each model invocation method (`completion`, `gemmma`, `gpt`), increment the counter for the respective model in the `model_usage_counter` dictionary right before the model is called.
• After incrementing the counter, check if the count for the model is a multiple of 10. If it is, use the `debug` function from `upsonic_on_prem/utils/logs.py` to log a message indicating the model's name and how many times it has been called. The message should follow the format: `"Model [model_name] has been called [count] times."`
• Ensure that the `debug` function is properly imported from `upsonic_on_prem/utils/logs.py` if not already imported.
• This modification ensures that each time a model is called, its usage count is incremented and logged every 10 calls, fulfilling the issue's requirements without introducing unnecessary complexity.

Step 3: 🔁 Code Review

Working on it...


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description.
Something wrong? Let us know.

This is an automated message generated by Sweep AI.

@onuratakan
Copy link
Member Author

onuratakan commented Mar 7, 2024

🚀 Here's the PR! #68

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: None)

Tip

I can email you next time I complete a pull request if you set up your email here!


Actions (click)

  • ↻ Restart Sweep

Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.

https://github.com/Upsonic/On-Prem/blob/977a50d24d4eb91eaecffb023c8a544f4883e3c6/upsonic_on_prem/utils/ai/ai.py#L1-L363


Step 2: ⌨️ Coding

  • Modify upsonic_on_prem/utils/ai/ai.py0ff6bcc Edit
Modify upsonic_on_prem/utils/ai/ai.py with contents:
• At the beginning of the `AI_` class definition, introduce a new class variable `model_call_counter` initialized as an empty dictionary. This dictionary will map model names to their respective call counts.
• In the `completion`, `gemmma`, and `gpt` methods, add logic to increment the call count for the specified model in `model_call_counter`. Use the model name as the key. If the model is not yet in the dictionary, initialize its count at 1.
• After incrementing the call count, check if the count is divisible by 10 (using the modulo operator `%`). If so, use the `debug` function (already imported from `upsonic_on_prem/utils`) to log a message indicating the model has been called 10 times. The message should include the model name and the current count.
• Example debug log message format: `debug(f"Model {model_name} has been called {count} times.")`
• Ensure that the counter increment and logging logic are correctly placed within each method to accurately reflect model usage.
--- 
+++ 
@@ -123,6 +123,10 @@
 
     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 @@
 
 
 
+    model_call_counter = {}
+
 AI = AI_()
  • Running GitHub Actions for upsonic_on_prem/utils/ai/ai.pyEdit
Check upsonic_on_prem/utils/ai/ai.py with contents:

Ran GitHub Actions for 0ff6bccf7f6d63811f8f3f2cd008d7127713c17e:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/make_a_counter_system_to_ai_calls_in_ups.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description.
Something wrong? Let us know.

This is an automated message generated by Sweep AI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant