Skip to content

Commit

Permalink
change exchange to ai_exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
lily-de committed Aug 27, 2024
1 parent 2865f7b commit a77b204
Show file tree
Hide file tree
Showing 40 changed files with 136 additions and 136 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
> `export OPENAI_API_KEY=your-key-here`
``` python
from exchange import Exchange, Message, Tool
from exchange.providers import OpenAiProvider
from ai_exchange import Exchange, Message, Tool
from ai_exchange.providers import OpenAiProvider

def word_count(text: str):
"""Get the count of words in text
Expand Down Expand Up @@ -85,11 +85,11 @@ Your plugin will then be available in your application or other applications bui
through:

``` python
from exchange.providers import get_provider
from ai_exchange.providers import get_provider

provider = get_provider('example').from_env()
```

[CONTRIBUTING]: CONTRIBUTING.md
[openaiprovider]: src/exchange/providers/openai.py
[openaiprovider]: src/ai_exchange/providers/openai.py
[plugins]: https://packaging.python.org/en/latest/guides/creating-and-discovering-plugins/
6 changes: 6 additions & 0 deletions src/ai_exchange/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Classes for interacting with the exchange API."""

from ai_exchange.tool import Tool # noqa
from ai_exchange.content import Text, ToolResult, ToolUse # noqa
from ai_exchange.message import Message # noqa
from ai_exchange.exchange import Exchange # noqa
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/exchange/exchange.py → src/ai_exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from attrs import define, evolve, field
from tiktoken import get_encoding

from exchange.checkpoint import Checkpoint
from exchange.content import ToolResult, ToolUse
from exchange.message import Message
from exchange.moderators import ContextTruncate, Moderator
from exchange.providers import Provider, Usage
from exchange.tool import Tool
from ai_exchange.checkpoint import Checkpoint
from ai_exchange.content import ToolResult, ToolUse
from ai_exchange.message import Message
from ai_exchange.moderators import ContextTruncate, Moderator
from ai_exchange.providers import Provider, Usage
from ai_exchange.tool import Tool


def validate_tool_output(output: str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/exchange/message.py → src/ai_exchange/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from attrs import define, field
from jinja2 import Environment, FileSystemLoader

from exchange.content import CONTENT_TYPES, Content, Text, ToolResult, ToolUse
from exchange.utils import create_object_id
from ai_exchange.content import CONTENT_TYPES, Content, Text, ToolResult, ToolUse
from ai_exchange.utils import create_object_id

Role = Literal["user", "assistant"]

Expand Down
13 changes: 13 additions & 0 deletions src/ai_exchange/moderators/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from functools import cache
from typing import Type

from ai_exchange.moderators.base import Moderator
from ai_exchange.utils import load_plugins
from ai_exchange.moderators.passive import PassiveModerator # noqa
from ai_exchange.moderators.truncate import ContextTruncate # noqa
from ai_exchange.moderators.summarizer import ContextSummarizer # noqa


@cache
def get_moderator(name: str) -> Type[Moderator]:
return load_plugins(group="exchange.moderator")[name]
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Type
from exchange.moderators.base import Moderator
from ai_exchange.moderators.base import Moderator


class PassiveModerator(Moderator):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import List, Literal, Optional, Tuple, Type, Union

from exchange import Message
from exchange.checkpoint import Checkpoint
from exchange.moderators import ContextTruncate, Moderator, PassiveModerator
from ai_exchange import Message
from ai_exchange.checkpoint import Checkpoint
from ai_exchange.moderators import ContextTruncate, Moderator, PassiveModerator

MAX_TOKENS = 112000
SUMMARIZATION_OFFSET = 40000 # Keep a max of this many tokens
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Literal, Optional, Type

from exchange.moderators import PassiveModerator
from exchange.moderators.base import Moderator
from ai_exchange.moderators import PassiveModerator
from ai_exchange.moderators.base import Moderator

MAX_TOKENS = 112000

Expand Down
14 changes: 14 additions & 0 deletions src/ai_exchange/providers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from functools import cache
from typing import Type

from ai_exchange.providers.anthropic import AnthropicProvider # noqa
from ai_exchange.providers.base import Provider, Usage # noqa
from ai_exchange.providers.databricks import DatabricksProvider # noqa
from ai_exchange.providers.openai import OpenAiProvider # noqa
from ai_exchange.providers.azure import AzureProvider # noqa
from ai_exchange.utils import load_plugins


@cache
def get_provider(name: str) -> Type[Provider]:
return load_plugins(group="exchange.provider")[name]
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import httpx

from exchange import Message, Tool
from exchange.content import Text, ToolResult, ToolUse
from exchange.providers.base import Provider, Usage
from exchange.providers.utils import raise_for_status
from ai_exchange import Message, Tool
from ai_exchange.content import Text, ToolResult, ToolUse
from ai_exchange.providers.base import Provider, Usage
from ai_exchange.providers.utils import raise_for_status

ANTHROPIC_HOST = "https://api.anthropic.com/v1/messages"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

import httpx

from exchange.message import Message
from exchange.providers.base import Provider, Usage
from exchange.providers.utils import (
from ai_exchange.message import Message
from ai_exchange.providers.base import Provider, Usage
from ai_exchange.providers.utils import (
messages_to_openai_spec,
openai_response_to_message,
openai_single_message_context_length_exceeded,
raise_for_status,
tools_to_openai_spec,
)
from exchange.tool import Tool
from ai_exchange.tool import Tool


class AzureProvider(Provider):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from attrs import define, field
from typing import List, Tuple, Type

from exchange.message import Message
from exchange.tool import Tool
from ai_exchange.message import Message
from ai_exchange.tool import Tool


@define
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

import httpx

from exchange.content import Text, ToolResult, ToolUse
from exchange.message import Message
from exchange.providers import Provider, Usage
from exchange.providers.utils import raise_for_status
from exchange.tool import Tool
from ai_exchange.content import Text, ToolResult, ToolUse
from ai_exchange.message import Message
from ai_exchange.providers import Provider, Usage
from ai_exchange.providers.utils import raise_for_status
from ai_exchange.tool import Tool

SERVICE = "bedrock-runtime"
UTC = timezone.utc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import httpx

from exchange.message import Message
from exchange.providers.base import Provider, Usage
from exchange.providers.utils import (
from ai_exchange.message import Message
from ai_exchange.providers.base import Provider, Usage
from ai_exchange.providers.utils import (
messages_to_openai_spec,
openai_response_to_message,
raise_for_status,
tools_to_openai_spec,
)
from exchange.tool import Tool
from ai_exchange.tool import Tool


class DatabricksProvider(Provider):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

import httpx

from exchange.message import Message
from exchange.providers.base import Provider, Usage
from exchange.providers.utils import (
from ai_exchange.message import Message
from ai_exchange.providers.base import Provider, Usage
from ai_exchange.providers.utils import (
messages_to_openai_spec,
openai_response_to_message,
openai_single_message_context_length_exceeded,
raise_for_status,
tools_to_openai_spec,
)
from exchange.tool import Tool
from ai_exchange.tool import Tool

OPENAI_HOST = "https://api.openai.com/"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from typing import Any, Dict, List, Tuple

import httpx
from exchange.content import Text, ToolResult, ToolUse
from exchange.message import Message
from exchange.tool import Tool
from ai_exchange.content import Text, ToolResult, ToolUse
from ai_exchange.message import Message
from ai_exchange.tool import Tool


def raise_for_status(response: httpx.Response) -> httpx.Response:
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/tool.py → src/ai_exchange/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from attrs import define

from exchange.utils import json_schema, parse_docstring
from ai_exchange.utils import json_schema, parse_docstring


@define
Expand Down
File renamed without changes.
6 changes: 0 additions & 6 deletions src/exchange/__init__.py

This file was deleted.

13 changes: 0 additions & 13 deletions src/exchange/moderators/__init__.py

This file was deleted.

14 changes: 0 additions & 14 deletions src/exchange/providers/__init__.py

This file was deleted.

8 changes: 4 additions & 4 deletions tests/providers/test_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import httpx
import pytest
from exchange import Message, Text
from exchange.content import ToolResult, ToolUse
from exchange.providers.anthropic import AnthropicProvider
from exchange.tool import Tool
from ai_exchange import Message, Text
from ai_exchange.content import ToolResult, ToolUse
from ai_exchange.providers.anthropic import AnthropicProvider
from ai_exchange.tool import Tool


def example_fn(param: str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/providers/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from unittest.mock import patch

import pytest
from exchange import Message, Text
from exchange.providers.azure import AzureProvider
from ai_exchange import Message, Text
from ai_exchange.providers.azure import AzureProvider


@pytest.fixture
Expand Down
8 changes: 4 additions & 4 deletions tests/providers/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from unittest.mock import patch

import pytest
from exchange.content import Text, ToolResult, ToolUse
from exchange.message import Message
from exchange.providers.bedrock import BedrockProvider
from exchange.tool import Tool
from ai_exchange.content import Text, ToolResult, ToolUse
from ai_exchange.message import Message
from ai_exchange.providers.bedrock import BedrockProvider
from ai_exchange.tool import Tool

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions tests/providers/test_databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from unittest.mock import patch

import pytest
from exchange import Message, Text
from exchange.providers.databricks import DatabricksProvider
from ai_exchange import Message, Text
from ai_exchange.providers.databricks import DatabricksProvider


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/providers/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from unittest.mock import patch

import pytest
from exchange import Message, Text
from exchange.providers.openai import OpenAiProvider
from ai_exchange import Message, Text
from ai_exchange.providers.openai import OpenAiProvider


@pytest.fixture
Expand Down
8 changes: 4 additions & 4 deletions tests/providers/test_provider_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import pytest
from unittest.mock import patch

from exchange.content import Text, ToolResult, ToolUse
from exchange.message import Message
from exchange.providers.utils import (
from ai_exchange.content import Text, ToolResult, ToolUse
from ai_exchange.message import Message
from ai_exchange.providers.utils import (
messages_to_openai_spec,
openai_response_to_message,
raise_for_status,
tools_to_openai_spec,
)
from exchange.tool import Tool
from ai_exchange.tool import Tool

OPEN_AI_TOOL_USE_RESPONSE = response = {
"choices": [
Expand Down
12 changes: 6 additions & 6 deletions tests/test_exchange.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import List

from exchange.content import Text, ToolResult, ToolUse
from exchange.exchange import Exchange
from exchange.message import Message
from exchange.moderators import PassiveModerator
from exchange.providers import Provider, Usage
from exchange.tool import Tool
from ai_exchange.content import Text, ToolResult, ToolUse
from ai_exchange.exchange import Exchange
from ai_exchange.message import Message
from ai_exchange.moderators import PassiveModerator
from ai_exchange.providers import Provider, Usage
from ai_exchange.tool import Tool


def dummy_tool() -> str:
Expand Down
Loading

0 comments on commit a77b204

Please sign in to comment.