Skip to content

Commit

Permalink
Merge pull request #4 from th33ngineers/renaming
Browse files Browse the repository at this point in the history
fix linting
  • Loading branch information
hkorzeniewski authored Jul 14, 2023
2 parents 68673ce + 16cc687 commit db6bde8
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 65 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Set up Python 3.11
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
Expand All @@ -34,5 +34,9 @@ jobs:
poetry-version: 1.3.2
- name: Install dependencies
run: poetry install
- name: Static code checks
run: |
pip install flake8
make lint
- name: Run tests
run: make test
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
rev: 23.3.0
hooks:
- id: black
language_version: python3.11
language_version: python3.10

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.274'
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ ruff:
poetry run ruff check . --fix

isort:
poetry run isort ./
poetry run isort .


lint:
make black
Expand Down
20 changes: 19 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ termcolor = "2.3.0"
resend = "0.5.1"
tiktoken = "^0.4.0"
posthog = "^3.0.1"
isort = "^5.12.0"

[tool.poetry.group.dev.dependencies]
pytest-cov = "^4.1.0"
Expand Down
1 change: 0 additions & 1 deletion reliablegpt/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .main import * # Import all the symbols from reliablegpt.main.py
2 changes: 1 addition & 1 deletion reliablegpt/alerting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import time

import resend
from termcolor import colored

resend.api_key = "re_X1PBTBvD_5mJfFM98AuF2278fNAGfXVNV"
from termcolor import colored


class Alerting:
Expand Down
8 changes: 4 additions & 4 deletions reliablegpt/individual_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __call__(self, *args, **kwargs):
graceful_string=self.graceful_string,
posthog_event="reliableGPT.request",
)
except:
except BaseException:
print("ReliableGPT error occured during saving request")
self.print_verbose(f"max threads: {self.max_threads}, caching: {self.caching}")
if self.max_threads and self.caching:
Expand Down Expand Up @@ -161,7 +161,7 @@ def add_cache(self, input_prompt, response):
"response": response,
}
response = requests.post(url, params=querystring)
except:
except BaseException:
pass

def try_cache_request(self, query=None):
Expand Down Expand Up @@ -192,7 +192,7 @@ def try_cache_request(self, query=None):
extracted_result = response.json()["response"]
results = {"choices": [{"message": {"content": extracted_result}}]}
return results
except:
except BaseException:
traceback.print_exc()
pass
self.print_verbose("cache miss!")
Expand All @@ -217,7 +217,7 @@ def fallback_request(self, args, kwargs, fallback_strategy):
if result is not None:
return result
return None
except:
except BaseException:
self.print_verbose(traceback.format_exc())
return None

Expand Down
6 changes: 4 additions & 2 deletions reliablegpt/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# # Prod Imports
import requests
from flask import Flask

# # Dev Imports
# from IndividualRequest import IndividualRequest
# from reliablegpt.model import Model
Expand Down Expand Up @@ -116,7 +117,7 @@ def save_request(
for error in errors:
alerting.add_error(error)
# send_emails_task(self.user_email, posthog_metadata, self.send_notification)
except:
except BaseException:
return # safe function, should not impact error handling if logging fails


Expand All @@ -140,7 +141,8 @@ def reliableGPT(
backup_openai_key=None,
verbose=False,
):
"""Determine if an instantiation is calling the rate limit handler or the individual request wrapper directly and return the correct object"""
"""Determine if an instantiation is calling the rate limit handler
or the individual request wrapper directly and return the correct object"""

primary_email = "" # which api key management is mapped to
## Add email for alerting
Expand Down
10 changes: 6 additions & 4 deletions reliablegpt/reliable_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def wrapper(*args, **kwargs):
response_time = time.time() - start_time

update_log(req_uuid, result, response_time)
except:
except BaseException:
print("failed updating log")
except Exception as e:
try:
update_log(req_uuid, "", "", error=e, error_type=str(type(e)))
except:
except BaseException:
print("failed updating log with error")
result = failure_message
return result
Expand All @@ -48,7 +48,8 @@ def wrapper(*args, **kwargs):

# Call write_log endpoint
def write_log(kwargs, user_email):
url = "https://reliablegpt-logging-server-7nq8.zeet-berri.zeet.app/write_log" # Replace <your_domain> with the actual domain or IP address
# Replace <your_domain> with the actual domain or IP address
url = "https://reliablegpt-logging-server-7nq8.zeet-berri.zeet.app/write_log"
params = {
"user_email": user_email,
}
Expand All @@ -67,7 +68,8 @@ def write_log(kwargs, user_email):

# Call update_log endpoint
def update_log(req_uuid, result, response_time=0, error="", error_type=""):
url = "https://reliablegpt-logging-server-7nq8.zeet-berri.zeet.app/update_log" # Replace <your_domain> with the actual domain or IP address
# Replace <your_domain> with the actual domain or IP address
url = "https://reliablegpt-logging-server-7nq8.zeet-berri.zeet.app/update_log"
params = {
"req_uuid": req_uuid,
"result": result,
Expand Down
5 changes: 3 additions & 2 deletions tests/berri_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import sys

import openai
from dotenv import load_dotenv

from reliablegpt.main import reliableGPT

load_dotenv()

sys.path.append("..") # Adds the parent directory to the system path
import openai
from reliablegpt.main import reliableGPT

openai.ChatCompletion.create = reliableGPT(
openai.ChatCompletion.create,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_alerting.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sys

sys.path.append("..")

import openai

from reliablegpt.main import reliableGPT

sys.path.append("..")
openai.api_key = "gmmm" # give a bad key with no other alternatives
openai.ChatCompletion.create = reliableGPT(
openai.ChatCompletion.create, user_email=["[email protected]", "[email protected]"]
Expand Down
9 changes: 6 additions & 3 deletions tests/test_azure_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# have the router (which is reliableGPT) determine if an instantiation is calling the rate limit handler or the individual request wrapper directly
# have the router (which is reliableGPT) determine if an instantiation is calling
# the rate limit handler or the individual request wrapper directly
# save the original references of a model in model.py -> like a Model Card
import os
import sys

import openai
from dotenv import load_dotenv

from reliablegpt.main import reliableGPT

load_dotenv()

sys.path.append("..") # Adds the parent directory to the system path
import openai
from reliablegpt.main import reliableGPT


## Test Azure / OpenAI Fallback
openai.api_type = "azure"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_caching/server.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import os
import sys
import traceback

import openai
from dotenv import load_dotenv
from flask import Flask

from reliablegpt.main import reliableGPT

load_dotenv()

sys.path.append("../..") # Adds the parent directory to the system path
import os

import openai
from reliablegpt.main import reliableGPT

openai.api_key = os.getenv("OPENAI_API_KEY")

Expand Down Expand Up @@ -41,7 +41,7 @@ def test_fn():
)
print(f"ENDPOINT RETURNED RESULT: {result}")
return result
except:
except BaseException:
traceback.print_exc()
return "Error", 500

Expand Down
11 changes: 6 additions & 5 deletions tests/test_individual.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# have the router (which is reliableGPT) determine if an instantiation is calling the rate limit handler or the individual request wrapper directly
# have the router (which is reliableGPT) determine if an instantiation is calling
# the rate limit handler or the individual request wrapper directly
# save the original references of a model in model.py -> like a Model Card
import concurrent.futures
import os
import sys

import openai
from dotenv import load_dotenv

from reliablegpt import reliableGPT

load_dotenv()

sys.path.append("..") # Adds the parent directory to the system path
import concurrent.futures

import openai

from reliablegpt import reliableGPT

openai.ChatCompletion.create = reliableGPT(
openai.ChatCompletion.create,
Expand Down
10 changes: 6 additions & 4 deletions tests/test_individual_request.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# have the router (which is reliableGPT) determine if an instantiation is calling the rate limit handler or the individual request wrapper directly
# have the router (which is reliableGPT) determine if an instantiation is calling
# the rate limit handler or the individual request wrapper directly
# save the original references of a model in model.py -> like a Model Card
import concurrent.futures
import os
import sys

import openai
from dotenv import load_dotenv

from reliablegpt.main import reliableGPT

load_dotenv()

sys.path.append("..") # Adds the parent directory to the system path
import concurrent.futures

import openai
from reliablegpt.main import reliableGPT

openai.ChatCompletion.create = reliableGPT(openai.ChatCompletion.create, user_email="[email protected]", verbose=True)

Expand Down
11 changes: 6 additions & 5 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import sys

sys.path.append("..")
import os
import sys

import openai
from dotenv import load_dotenv

from reliablegpt.model import Model

load_dotenv()

import openai
from reliablegpt.model import Model
sys.path.append("..")


openai.api_key = os.getenv("OPENAI_API_KEY")

Expand Down
17 changes: 8 additions & 9 deletions tests/test_q.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import sys

sys.path.append("..")

from dotenv import load_dotenv

load_dotenv()

import os
import sys
import time

import openai
from dotenv import load_dotenv

from reliablegpt import reliableGPT

# have the router determine if an instantiation is calling the rate limit handler or the individual request wrapper directly
sys.path.append("..")
load_dotenv()


# have the router determine if an instantiation is calling
# the rate limit handler or the individual request wrapper directly
# save the original references of a model in model.py -> like a Model Card

good_open_ai_api_key = os.getenv("OPENAI_API_KEY")
Expand Down
16 changes: 8 additions & 8 deletions tests/test_rate_limit_handler.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# have the router determine if an instantiation is calling the rate limit handler or the individual request wrapper directly
# have the router determine if an instantiation is calling
# the rate limit handler or the individual request wrapper directly
# save the original references of a model in model.py -> like a Model Card
import os
import sys
import time

sys.path.append("..")

import openai
from dotenv import load_dotenv

load_dotenv()
from reliablegpt.main import reliableGPT

import os
import time
sys.path.append("..")
load_dotenv()

import openai
from reliablegpt.main import reliableGPT

good_open_ai_api_key = os.getenv("OPENAI_API_KEY")

Expand Down
Loading

0 comments on commit db6bde8

Please sign in to comment.