Class: GenAI::Language::GooglePalm
- Defined in:
- lib/gen_ai/language/google_palm.rb
Constant Summary collapse
- DEFAULT_ROLE =
'0'
- EMBEDDING_MODEL =
'textembedding-gecko-001'
- COMPLETION_MODEL =
'text-bison-001'
- CHAT_COMPLETION_MODEL =
'chat-bison-001'
Instance Method Summary collapse
- #chat(message, context: nil, history: [], examples: [], **options) ⇒ Object
- #complete(prompt, options = {}) ⇒ Object
- #embed(input, model: nil) ⇒ Object
-
#initialize(token:, options: {}) ⇒ GooglePalm
constructor
A new instance of GooglePalm.
Methods included from Dependency
Constructor Details
#initialize(token:, options: {}) ⇒ GooglePalm
Returns a new instance of GooglePalm.
11 12 13 14 15 |
# File 'lib/gen_ai/language/google_palm.rb', line 11 def initialize(token:, options: {}) depends_on 'google_palm_api' @client = ::GooglePalmApi::Client.new(api_key: token) end |
Instance Method Details
#chat(message, context: nil, history: [], examples: [], **options) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gen_ai/language/google_palm.rb', line 41 def chat(, context: nil, history: [], examples: [], **) parameters = (, context, history, examples, ) response = handle_errors { client.(**parameters) } build_result( model: parameters[:model], raw: response.merge('usage' => {}), parsed: (response) ) end |
#complete(prompt, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gen_ai/language/google_palm.rb', line 29 def complete(prompt, = {}) parameters = (prompt, ) response = handle_errors { client.generate_text(**parameters) } build_result( model: parameters[:model], raw: response.merge('usage' => {}), parsed: extract_completions(response) ) end |
#embed(input, model: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gen_ai/language/google_palm.rb', line 17 def (input, model: nil) responses = array_wrap(input).map do |text| handle_errors { client.(text: text, model: model) } end build_result( model: model || EMBEDDING_MODEL, raw: { 'data' => responses, 'usage' => {} }, parsed: (responses) ) end |