Skip to content

Commit bca0424

Browse files
authored
docs: updated migration (#54)
* docs: updated migration * fix: example
1 parent 2a65f23 commit bca0424

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
---
1717

18-
## Migration from v1.3.3 and below
18+
## Migration from v1.3.4 and below
1919

2020
In `v2.0.0` we introduced a new SDK that is not backwards compatible with the previous version.
2121
This version allows for Non static instances of the client, defined parameters to each resource, modelized responses and
@@ -24,7 +24,7 @@ more.
2424
<details>
2525
<summary>Migration Examples</summary>
2626

27-
### Instance creation (not available in v1.3.3 and below)
27+
### Instance creation (not available in v1.3.4 and below)
2828

2929
```python
3030
from ai21 import AI21Client
@@ -43,11 +43,10 @@ allowing for more flexibility and better control.
4343
```diff
4444
prompt = "some prompt"
4545

46-
import ai21
47-
46+
- import ai21
4847
- response = ai21.Completion.execute(model="j2-light", prompt=prompt, maxTokens=2)
4948

50-
49+
+ from ai21 import AI21Client
5150
+ client = ai21.AI21Client()
5251
+ response = client.completion.create(model="j2-light", prompt=prompt, max_tokens=2)
5352
```
@@ -60,10 +59,27 @@ This applies to all resources. You would now need to create a client instance an
6059
- response = ai21.Tokenization.execute(text=prompt)
6160
- print(len(response)) # number of tokens
6261

63-
+ client = ai21.AI21Client()
62+
+ from ai21 import AI21Client
63+
+ client = AI21Client()
6464
+ token_count = client.count_tokens(text=prompt)
6565
```
6666

67+
### Key Access in Response Objects before/after
68+
69+
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.
70+
71+
```diff
72+
- import ai21
73+
- response = ai21.Summarize.execute(source="some text", sourceType="TEXT")
74+
- response["summary"]
75+
76+
+ from ai21 import AI21Client
77+
+ from ai21.models import DocumentType
78+
+ client = AI21Client()
79+
+ response = client.summarize.create(source="some text", source_type=DocumentType.TEXT)
80+
+ response.summary
81+
```
82+
6783
---
6884

6985
### AWS Client Creations

0 commit comments

Comments
 (0)