Class: AI21::Client
- Inherits:
-
Object
show all
- Extended by:
- HTTP
- Includes:
- Helper
- Defined in:
- lib/ai21/client.rb
Constant Summary
collapse
- DEFALUT_COMPLETE_MODEL =
"j2-grande"
- DEFAULT_INSTRUCT_MODEL =
"j2-grande-instruct"
Instance Method Summary
collapse
Methods included from HTTP
authorization, content_type, delete, fetch, get, http, post, request, url
Methods included from Helper
#camel_to_snake, #deep_transform_keys!, #snake_to_camel
Constructor Details
#initialize(access_token) ⇒ Client
Returns a new instance of Client.
11
12
13
|
# File 'lib/ai21/client.rb', line 11
def initialize(access_token)
AI21.configuration.access_token = access_token if access_token
end
|
Instance Method Details
#answer(question, context) ⇒ Object
47
48
49
|
# File 'lib/ai21/client.rb', line 47
def answer(question, context)
AI21::Client.post("/experimental/answer", {question: question, context: context})
end
|
#complete(prompt, options = {}) ⇒ Object
15
16
17
18
19
|
# File 'lib/ai21/client.rb', line 15
def complete(prompt, options = {})
model = options.delete(:model) || DEFALUT_COMPLETE_MODEL
AI21::Client.post("/#{model}/complete", {prompt: prompt}.merge(snake_to_camel(options)))
end
|
#correct(prompt) ⇒ Object
31
32
33
|
# File 'lib/ai21/client.rb', line 31
def correct(prompt)
AI21::Client.post("/gec", {text: prompt})
end
|
#custom_model ⇒ Object
59
60
61
|
# File 'lib/ai21/client.rb', line 59
def custom_model
@custom_model ||= AI21::CustomModel.new
end
|
#dataset ⇒ Object
55
56
57
|
# File 'lib/ai21/client.rb', line 55
def dataset
@dataset ||= AI21::Dataset.new
end
|
#improvements(prompt, types = ["fluency"]) ⇒ Object
35
36
37
|
# File 'lib/ai21/client.rb', line 35
def improvements(prompt, types = ["fluency"])
AI21::Client.post("/improvements", {text: prompt, types: types})
end
|
#instruct(prompt, options = {}) ⇒ Object
21
22
23
24
25
|
# File 'lib/ai21/client.rb', line 21
def instruct(prompt, options = {})
model = options.delete(:model) || DEFAULT_INSTRUCT_MODEL
AI21::Client.post("/#{model}/complete", {prompt: prompt}.merge(snake_to_camel(options)))
end
|
#paraphrase(prompt, options = {}) ⇒ Object
27
28
29
|
# File 'lib/ai21/client.rb', line 27
def paraphrase(prompt, options = {})
AI21::Client.post("/paraphrase", {text: prompt}.merge(snake_to_camel(options)))
end
|
#segmentation(prompt, source_type = "TEXT") ⇒ Object
43
44
45
|
# File 'lib/ai21/client.rb', line 43
def segmentation(prompt, source_type = "TEXT")
AI21::Client.post("/segmentation", {source: prompt, sourceType: source_type})
end
|
#summarize(prompt, source_type = "TEXT", options = {}) ⇒ Object
39
40
41
|
# File 'lib/ai21/client.rb', line 39
def summarize(prompt, source_type = "TEXT", options = {})
AI21::Client.post("/summarize", {source: prompt, sourceType: source_type}.merge(snake_to_camel(options)))
end
|
#tokenize(text) ⇒ Object
51
52
53
|
# File 'lib/ai21/client.rb', line 51
def tokenize(text)
AI21::Client.post("/tokenize", {text: text})
end
|