Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions scope3ai/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from enum import Enum


class PROVIDERS(Enum):
ANTROPIC = "anthropic"
COHERE = "cohere"
OPENAI = "openai"
HUGGINGFACE_HUB = "huggingface_hub"
LITELLM = "litellm"
MISTRALAI = "mistralai"
RESPONSE = "response"
14 changes: 2 additions & 12 deletions scope3ai/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
from contextlib import contextmanager
from contextvars import ContextVar
from enum import Enum
from functools import partial
from os import getenv
from typing import Optional, List
Expand All @@ -14,6 +13,7 @@
from .api.tracer import Tracer
from .api.types import ImpactRow, ImpactResponse, Scope3AIContext
from .api.defaults import DEFAULT_API_URL
from .constants import PROVIDERS

from .worker import BackgroundWorker

Expand Down Expand Up @@ -62,7 +62,7 @@ def init_litellm_instrumentor() -> None:

def init_mistral_v1_instrumentor() -> None:
if importlib.util.find_spec("mistralai") is not None:
from scope3ai.tracers.mistrarlai_v1.instrument import MistralAIInstrumentor
from scope3ai.tracers.mistralai.instrument import MistralAIInstrumentor

instrumentor = MistralAIInstrumentor()
instrumentor.instrument()
Expand All @@ -75,16 +75,6 @@ def init_response_instrumentor() -> None:
instrumentor.instrument()


class PROVIDERS(Enum):
ANTROPIC = "anthropic"
COHERE = "cohere"
OPENAI = "openai"
HUGGINGFACE_HUB = "huggingface_hub"
LITELLM = "litellm"
MISTRALAI = "mistralai"
RESPONSE = "response"


_INSTRUMENTS = {
PROVIDERS.ANTROPIC.value: init_anthropic_instrumentor,
PROVIDERS.COHERE.value: init_cohere_instrumentor,
Expand Down
13 changes: 7 additions & 6 deletions scope3ai/tracers/anthropic/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
from collections.abc import AsyncIterator, Awaitable, Iterator
from types import TracebackType
from typing import Any, Callable, Generic, Optional, TypeVar, Union
from typing_extensions import override

from anthropic import Anthropic, AsyncAnthropic
from anthropic import Stream as _Stream, AsyncStream as _AsyncStream
from anthropic._streaming import _T
from anthropic.lib.streaming import AsyncMessageStream as _AsyncMessageStream
from anthropic.lib.streaming import MessageStream as _MessageStream
from anthropic.types import Message as _Message
from anthropic.types.message_delta_event import MessageDeltaEvent
from anthropic.types.message_start_event import MessageStartEvent
from anthropic.types.message_stop_event import MessageStopEvent
from anthropic.types.raw_message_stream_event import RawMessageStreamEvent
from anthropic.types.raw_message_start_event import RawMessageStartEvent
from anthropic.types.raw_message_delta_event import RawMessageDeltaEvent
from anthropic._streaming import _T
from anthropic.types.raw_message_start_event import RawMessageStartEvent
from anthropic.types.raw_message_stream_event import RawMessageStreamEvent
from typing_extensions import override

from scope3ai.lib import Scope3AI
from scope3ai.api.types import Scope3AIContext, Model, ImpactRow
from scope3ai.constants import PROVIDERS
from scope3ai.lib import Scope3AI

PROVIDER = "anthropic"
PROVIDER = PROVIDERS.ANTROPIC.value

MessageStreamT = TypeVar("MessageStreamT", bound=_MessageStream)
AsyncMessageStreamT = TypeVar("AsyncMessageStreamT", bound=_AsyncMessageStream)
Expand Down
4 changes: 3 additions & 1 deletion scope3ai/tracers/cohere/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
from cohere.types.streamed_chat_response import (
StreamEndStreamedChatResponse as _StreamEndStreamedChatResponse,
)

from scope3ai.constants import PROVIDERS
from scope3ai.lib import Scope3AI
from scope3ai.api.types import Scope3AIContext, Model, ImpactRow

PROVIDER = "cohere"
PROVIDER = PROVIDERS.COHERE.value


class NonStreamedChatResponse(_NonStreamedChatResponse):
Expand Down
3 changes: 2 additions & 1 deletion scope3ai/tracers/cohere/chat_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
)

from scope3ai.api.types import ImpactRow, Model, Scope3AIContext
from scope3ai.constants import PROVIDERS
from scope3ai.lib import Scope3AI

PROVIDER = "cohere"
PROVIDER = PROVIDERS.COHERE.value


class ChatResponse(_ChatResponse):
Expand Down
3 changes: 2 additions & 1 deletion scope3ai/tracers/huggingface/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
from requests import Response

from scope3ai.api.types import Scope3AIContext, Model, ImpactRow
from scope3ai.constants import PROVIDERS
from scope3ai.lib import Scope3AI
from scope3ai.response_interceptor.requests_interceptor import requests_response_capture

PROVIDER = "huggingface_hub"
PROVIDER = PROVIDERS.HUGGINGFACE_HUB.value


@dataclass
Expand Down
3 changes: 2 additions & 1 deletion scope3ai/tracers/huggingface/speech_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

from scope3ai.api.types import Scope3AIContext, Model, ImpactRow
from scope3ai.api.typesgen import Task
from scope3ai.constants import PROVIDERS
from scope3ai.lib import Scope3AI
from scope3ai.response_interceptor.requests_interceptor import requests_response_capture

PROVIDER = "huggingface_hub"
PROVIDER = PROVIDERS.HUGGINGFACE_HUB.value


@dataclass
Expand Down
3 changes: 2 additions & 1 deletion scope3ai/tracers/huggingface/text_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

from scope3ai.api.types import Scope3AIContext, Model, ImpactRow
from scope3ai.api.typesgen import Task
from scope3ai.constants import PROVIDERS
from scope3ai.lib import Scope3AI
from scope3ai.response_interceptor.aiohttp_interceptor import aiohttp_response_capture
from scope3ai.response_interceptor.requests_interceptor import requests_response_capture

PROVIDER = "huggingface_hub"
PROVIDER = PROVIDERS.HUGGINGFACE_HUB.value


@dataclass
Expand Down
3 changes: 2 additions & 1 deletion scope3ai/tracers/huggingface/text_to_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

from scope3ai.api.types import Scope3AIContext, Model, ImpactRow
from scope3ai.api.typesgen import Task
from scope3ai.constants import PROVIDERS
from scope3ai.lib import Scope3AI

PROVIDER = "huggingface_hub"
PROVIDER = PROVIDERS.HUGGINGFACE_HUB.value


@dataclass
Expand Down
3 changes: 2 additions & 1 deletion scope3ai/tracers/huggingface/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

from scope3ai.api.types import Scope3AIContext, Model, ImpactRow
from scope3ai.api.typesgen import Task
from scope3ai.constants import PROVIDERS
from scope3ai.lib import Scope3AI
from scope3ai.response_interceptor.aiohttp_interceptor import aiohttp_response_capture
from scope3ai.response_interceptor.requests_interceptor import requests_response_capture

PROVIDER = "huggingface_hub"
PROVIDER = PROVIDERS.HUGGINGFACE_HUB.value


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions scope3ai/tracers/litellm/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from scope3ai import Scope3AI
from scope3ai.api.types import Scope3AIContext, Model, ImpactRow
from scope3ai.constants import PROVIDERS


PROVIDER = "litellm"
PROVIDER = PROVIDERS.LITELLM.value


class ChatCompletion(ModelResponse):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from scope3ai import Scope3AI
from scope3ai.api.types import Scope3AIContext
from scope3ai.api.typesgen import ImpactRow, Model
from scope3ai.constants import PROVIDERS

PROVIDER = "mistralai"
PROVIDER = PROVIDERS.MISTRALAI.value


class ChatCompletionResponse(_ChatCompletionResponse):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from wrapt import wrap_function_wrapper # type: ignore[import-untyped]

from scope3ai.tracers.mistrarlai_v1.chat import (
from scope3ai.tracers.mistralai.chat import (
mistralai_v1_chat_wrapper,
mistralai_v1_async_chat_wrapper,
mistralai_v1_chat_wrapper_stream,
Expand Down
4 changes: 2 additions & 2 deletions scope3ai/tracers/openai/chat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
from typing import Any, Callable, Optional, Union


from scope3ai.constants import PROVIDERS
from scope3ai.lib import Scope3AI
from scope3ai.api.types import Scope3AIContext, Model, ImpactRow

Expand All @@ -19,7 +19,7 @@
_ChatCompletionChunk = object()


PROVIDER = "openai"
PROVIDER = PROVIDERS.OPENAI.value


class ChatCompletion(_ChatCompletion):
Expand Down
3 changes: 2 additions & 1 deletion scope3ai/tracers/openai/speech_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
)

from scope3ai.api.types import ImpactRow, Model, Scope3AIContext, Task
from scope3ai.constants import PROVIDERS
from scope3ai.lib import Scope3AI

PROVIDER = "openai"
PROVIDER = PROVIDERS.OPENAI.value

logger = logging.getLogger("scope3.tracers.openai.speech_to_text")

Expand Down
4 changes: 3 additions & 1 deletion scope3ai/tracers/openai/text_to_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from openai.resources.audio.speech import AsyncSpeech, Speech, _legacy_response

from scope3ai.api.types import ImpactRow, Model, Scope3AIContext, Task
from scope3ai.constants import PROVIDERS
from scope3ai.lib import Scope3AI


Expand All @@ -19,7 +20,8 @@ def _imported():
return _imported


PROVIDER = "openai"
PROVIDER = PROVIDERS.OPENAI.value

MUTAGEN_MAPPING = {
"mp3": _lazy_import("mutagen.mp3", "MP3"),
"aac": _lazy_import("mutagen.aac", "AAC"),
Expand Down
Loading