1515
1616---
1717
18- ## Migration from v1.3.3 and below
18+ ## Migration from v1.3.4 and below
1919
2020In ` v2.0.0 ` we introduced a new SDK that is not backwards compatible with the previous version.
2121This version allows for Non static instances of the client, defined parameters to each resource, modelized responses and
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
3030from ai21 import AI21Client
@@ -43,11 +43,10 @@ allowing for more flexibility and better control.
4343``` diff
4444prompt = "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