Module: SummarizeMeeting::Ai
- Defined in:
- lib/summarize-meeting/ai.rb
Defined Under Namespace
Classes: OpenAiError
Constant Summary collapse
- MAX_TOTAL_TOKENS =
4096- WORDS_PER_TOKEN =
0.75
- @@access_token =
ENV["OPENAI_KEY"]
- @@organization_id =
ENV["OPENAI_ORG"]
Class Method Summary collapse
- .access_token ⇒ Object
- .access_token=(token) ⇒ Object
- .calculate_token_word_count(token_count) ⇒ Object
- .calculate_word_token_count(word_count) ⇒ Object
- .chat(messages, client: self.client) ⇒ Object
- .client ⇒ Object
- .new_client(access_token:, organization_id:) ⇒ Object
- .organization_id ⇒ Object
- .organization_id=(id) ⇒ Object
Class Method Details
.access_token ⇒ Object
18 19 20 |
# File 'lib/summarize-meeting/ai.rb', line 18 def self.access_token @@access_token end |
.access_token=(token) ⇒ Object
26 27 28 |
# File 'lib/summarize-meeting/ai.rb', line 26 def self.access_token=(token) @@access_token = token end |
.calculate_token_word_count(token_count) ⇒ Object
34 35 36 |
# File 'lib/summarize-meeting/ai.rb', line 34 def self.calculate_token_word_count(token_count) (token_count * WORDS_PER_TOKEN.to_f).ceil end |
.calculate_word_token_count(word_count) ⇒ Object
38 39 40 |
# File 'lib/summarize-meeting/ai.rb', line 38 def self.calculate_word_token_count(word_count) (word_count / WORDS_PER_TOKEN.to_f).ceil end |
.chat(messages, client: self.client) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/summarize-meeting/ai.rb', line 42 def self.chat(, client: self.client) parameters = { model: "gpt-3.5-turbo", messages: , } response = client.chat(parameters: parameters) content = response.dig("choices", 0, "message", "content") if !content raise OpenAiError, "No response from OpenAI" else content end end |
.client ⇒ Object
10 11 12 |
# File 'lib/summarize-meeting/ai.rb', line 10 def self.client @client ||= new_client(access_token: access_token, organization_id: organization_id) end |
.new_client(access_token:, organization_id:) ⇒ Object
14 15 16 |
# File 'lib/summarize-meeting/ai.rb', line 14 def self.new_client(access_token:, organization_id:) OpenAI::Client.new(access_token: access_token, organization_id: organization_id) end |
.organization_id ⇒ Object
22 23 24 |
# File 'lib/summarize-meeting/ai.rb', line 22 def self.organization_id @@organization_id end |
.organization_id=(id) ⇒ Object
30 31 32 |
# File 'lib/summarize-meeting/ai.rb', line 30 def self.organization_id=(id) @@organization_id = id end |