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
111 changes: 0 additions & 111 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
## Table of Contents

- [Examples](#examples-tldr) 🗂️
- [Migration from v1.3.4 and below](#migration-from-v134-and-below)
- [AI21 Official Documentation](#Documentation)
- [Installation](#Installation) 💿
- [Usage - Chat Completions](#Usage)
- [Conversational RAG (Beta)](#Conversational-RAG-Beta)
- [Older Models Support Usage](#Older-Models-Support-Usage)
- [More Models](#More-Models)
- [Streaming](#Streaming)
- [TSMs](#TSMs)
- [Token Counting](#Token-Counting)
- [Environment Variables](#Environment-Variables)
- [Error Handling](#Error-Handling)
Expand All @@ -48,101 +46,6 @@ If you want to quickly get a glance how to use the AI21 Python SDK and jump stra

Feel free to dive in, experiment, and adapt these examples to suit your needs. We believe they'll help you get up and running quickly.

## Migration from v1.3.4 and below

In `v2.0.0` we introduced a new SDK that is not backwards compatible with the previous version.
This version allows for non-static instances of the client, defined parameters to each resource, modelized responses and
more.

<details>
<summary>Migration Examples</summary>

### Instance creation (not available in v1.3.4 and below)

```python
from ai21 import AI21Client

client = AI21Client(api_key='my_api_key')

# or set api_key in environment variable - AI21_API_KEY and then
client = AI21Client()
```

We No longer support static methods for each resource, instead we have a client instance that has a method for each
allowing for more flexibility and better control.

### Completion before/after

```diff
prompt = "some prompt"

- import ai21
- response = ai21.Completion.execute(model="j2-light", prompt=prompt, maxTokens=2)

+ from ai21 import AI21Client
+ client = ai21.AI21Client()
+ response = client.completion.create(model="j2-light", prompt=prompt, max_tokens=2)
```

This applies to all resources. You would now need to create a client instance and use it to call the resource method.

### Tokenization and Token counting before/after

```diff
- response = ai21.Tokenization.execute(text=prompt)
- print(len(response)) # number of tokens

+ from ai21 import AI21Client
+ client = AI21Client()
+ token_count = client.count_tokens(text=prompt)
```

### Key Access in Response Objects before/after

It is no longer possible to access the response object as a dictionary. Instead, you can access the response object as an object with attributes.

```diff
- import ai21
- response = ai21.Summarize.execute(source="some text", sourceType="TEXT")
- response["summary"]

+ from ai21 import AI21Client
+ from ai21.models import DocumentType
+ client = AI21Client()
+ response = client.summarize.create(source="some text", source_type=DocumentType.TEXT)
+ response.summary
```

---

### AWS Client Creations

### Bedrock Client creation before/after

```diff
- import ai21
- destination = ai21.BedrockDestination(model_id=ai21.BedrockModelID.J2_MID_V1)
- response = ai21.Completion.execute(prompt=prompt, maxTokens=1000, destination=destination)

+ from ai21 import AI21BedrockClient, BedrockModelID
+ client = AI21BedrockClient()
+ response = client.completion.create(prompt=prompt, max_tokens=1000, model_id=BedrockModelID.J2_MID_V1)
```

### SageMaker Client creation before/after

```diff
- import ai21
- destination = ai21.SageMakerDestination("j2-mid-test-endpoint")
- response = ai21.Completion.execute(prompt=prompt, maxTokens=1000, destination=destination)

+ from ai21 import AI21SageMakerClient
+ client = AI21SageMakerClient(endpoint_name="j2-mid-test-endpoint")
+ response = client.completion.create(prompt=prompt, max_tokens=1000)
```

</details>

## Documentation

---
Expand Down Expand Up @@ -220,20 +123,6 @@ asyncio.run(main())

A more detailed example can be found [here](examples/studio/chat/chat_completions.py).

## Older Models Support Usage

<details>
<summary>Examples</summary>

### Supported Models:

- j2-light
- [j2-ultra](#Chat)
- [j2-mid](#Completion)
- [jamba-instruct](#Chat-Completion)

you can read more about the models [here](https://docs.ai21.com/reference/j2-complete-api-ref#jurassic-2-models).

### Chat

```python
Expand Down
11 changes: 0 additions & 11 deletions ai21/clients/bedrock/ai21_bedrock_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
from ai21.clients.aws.aws_authorization import AWSAuthorization
from ai21.clients.bedrock._stream_decoder import _AWSEventStreamDecoder
from ai21.clients.studio.resources.studio_chat import AsyncStudioChat, StudioChat
from ai21.clients.studio.resources.studio_completion import (
AsyncStudioCompletion,
StudioCompletion,
)
from ai21.errors import AccessDenied, APITimeoutError, ModelErrorException, NotFound
from ai21.http_client.async_http_client import AsyncAI21HTTPClient
from ai21.http_client.http_client import AI21HTTPClient
Expand Down Expand Up @@ -101,10 +97,6 @@ def __init__(
BaseBedrockClient.__init__(self, session=session, region=self._region)

self.chat = StudioChat(self)
# Override the chat.create method to match the completions endpoint,
# so it wouldn't get to the old J2 completion endpoint
self.chat.create = self.chat.completions.create
self.completion = StudioCompletion(self)

def _build_request(self, options: RequestOptions) -> httpx.Request:
options = self._prepare_options(options)
Expand Down Expand Up @@ -146,10 +138,7 @@ def __init__(
BaseBedrockClient.__init__(self, session=session, region=self._region)

self.chat = AsyncStudioChat(self)
# Override the chat.create method to match the completions endpoint,
# so it wouldn't get to the old J2 completion endpoint
self.chat.create = self.chat.completions.create
self.completion = AsyncStudioCompletion(self)

def _build_request(self, options: RequestOptions) -> httpx.Request:
options = self._prepare_options(options)
Expand Down
96 changes: 0 additions & 96 deletions ai21/clients/common/completion_base.py

This file was deleted.

94 changes: 0 additions & 94 deletions ai21/clients/studio/resources/studio_completion.py

This file was deleted.

18 changes: 5 additions & 13 deletions ai21/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
from ai21.models.chat_message import ChatMessage
from ai21.models.document_type import DocumentType
from ai21.models.penalty import Penalty
from ai21.models.responses.chat_response import ChatResponse, ChatOutput, FinishReason
from ai21.models.responses.completion_response import (
CompletionsResponse,
Completion,
CompletionFinishReason,
CompletionData,
Prompt,
from ai21.models.responses.chat_response import ChatOutput, ChatResponse, FinishReason
from ai21.models.responses.conversational_rag_response import (
ConversationalRagResponse,
ConversationalRagSource,
)
from ai21.models.responses.conversational_rag_response import ConversationalRagResponse, ConversationalRagSource
from ai21.models.responses.file_response import FileResponse


__all__ = [
"ChatMessage",
"RoleType",
Expand All @@ -21,11 +18,6 @@
"ChatResponse",
"ChatOutput",
"FinishReason",
"CompletionsResponse",
"Completion",
"CompletionFinishReason",
"CompletionData",
"Prompt",
"FileResponse",
"ConversationalRagResponse",
"ConversationalRagSource",
Expand Down
Loading
Loading