Class: SentimentAI::Core::GeminiDriver
- Inherits:
-
Object
- Object
- SentimentAI::Core::GeminiDriver
- Defined in:
- lib/sentiment_ai/core/gemini_driver.rb
Instance Method Summary collapse
- #analyze_sentence(sentence) ⇒ Object
-
#initialize(api_key) ⇒ GeminiDriver
constructor
A new instance of GeminiDriver.
- #positive_check(sentence) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ GeminiDriver
Returns a new instance of GeminiDriver.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sentiment_ai/core/gemini_driver.rb', line 10 def initialize(api_key) @sentiment_ai = Gemini.new( credentials: { service: 'generative-language-api', api_key: api_key }, options: { model: 'gemini-pro', server_sent_events: true } ) end |
Instance Method Details
#analyze_sentence(sentence) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/sentiment_ai/core/gemini_driver.rb', line 21 def analyze_sentence(sentence) text_request = I18n.t('prompt.sentence', sentence: sentence) response = @sentiment_ai.stream_generate_content({ contents: { role: 'user', parts: { text: text_request } }, generationConfig: { temperature: 0 } }) extract_candidates(response) end |
#positive_check(sentence) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/sentiment_ai/core/gemini_driver.rb', line 31 def positive_check(sentence) text_request = I18n.t('prompt.positive_check', sentence: sentence) response = @sentiment_ai.stream_generate_content({ contents: { role: 'user', parts: { text: text_request } }, generationConfig: { temperature: 0 } }) extract_candidates(response) end |