Skip to content

Commit

Permalink
ci: fix pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelrince committed Mar 16, 2024
1 parent bfce6f3 commit 90d899c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ repos:
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
Expand Down
6 changes: 3 additions & 3 deletions genai_impact/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ def init_instruments() -> None:


def init_openai_instrumentor() -> None:
if importlib.util.find_spec('openai') is not None:
if importlib.util.find_spec("openai") is not None:
from genai_impact.tracers.openai_tracer import OpenAIInstrumentor

instrumentor = OpenAIInstrumentor()
instrumentor.instrument()


def init_anthropic_instrumentor() -> None:
if importlib.util.find_spec('anthropic') is not None:
if importlib.util.find_spec("anthropic") is not None:
from genai_impact.tracers.anthropic_tracer import AnthropicInstrumentor

instrumentor = AnthropicInstrumentor()
instrumentor.instrument()


def init_mistralai_instrumentor() -> None:
if importlib.util.find_spec('mistralai') is not None:
if importlib.util.find_spec("mistralai") is not None:
from genai_impact.tracers.mistralai_tracer import MistralAIInstrumentor

instrumentor = MistralAIInstrumentor()
Expand Down
7 changes: 3 additions & 4 deletions genai_impact/tracers/anthropic_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from genai_impact.compute_impacts import Impacts, compute_llm_impact


try:
from anthropic import Anthropic as _Anthropic
from anthropic.types import Message as _Message
Expand All @@ -23,7 +22,7 @@ class Message(_Message):
impacts: Impacts


def _set_impacts(response):
def _set_impacts(response: Message) -> Impacts:
model_size = _MODEL_SIZES.get(response.model)
output_tokens = response.usage.output_tokens
impacts = compute_llm_impact(
Expand All @@ -41,7 +40,7 @@ def anthropic_chat_wrapper(


class AnthropicInstrumentor:
def __init__(self):
def __init__(self) -> None:
self.wrapped_methods = [
{
"module": "anthropic.resources",
Expand All @@ -50,7 +49,7 @@ def __init__(self):
},
]

def instrument(self):
def instrument(self) -> None:
for wrapper in self.wrapped_methods:
wrap_function_wrapper(
wrapper["module"],
Expand Down
4 changes: 2 additions & 2 deletions genai_impact/tracers/mistralai_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def mistralai_chat_wrapper(


class MistralAIInstrumentor:
def __init__(self):
def __init__(self) -> None:
self.wrapped_methods = [
{
"module": "mistralai.client",
Expand All @@ -48,7 +48,7 @@ def __init__(self):
},
]

def instrument(self):
def instrument(self) -> None:
for wrapper in self.wrapped_methods:
wrap_function_wrapper(
wrapper["module"],
Expand Down
4 changes: 2 additions & 2 deletions genai_impact/tracers/openai_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def openai_chat_wrapper(


class OpenAIInstrumentor:
def __init__(self):
def __init__(self) -> None:
self.wrapped_methods = [
{
"module": "openai.resources.chat.completions",
Expand All @@ -53,7 +53,7 @@ def __init__(self):
},
]

def instrument(self):
def instrument(self) -> None:
for wrapper in self.wrapped_methods:
wrap_function_wrapper(
wrapper["module"],
Expand Down

0 comments on commit 90d899c

Please sign in to comment.