Class: LLM::Gemini::Format::CompletionFormat
- Inherits:
-
Object
- Object
- LLM::Gemini::Format::CompletionFormat
- Defined in:
- lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb
Instance Method Summary collapse
- #content ⇒ Object
-
#format ⇒ Hash
Formats the message for the Gemini chat completions API.
- #format_content(content) ⇒ Object
- #format_response(response) ⇒ Object
-
#initialize(message) ⇒ CompletionFormat
constructor
A new instance of CompletionFormat.
- #message ⇒ Object
- #prompt_error!(object) ⇒ Object
Constructor Details
#initialize(message) ⇒ CompletionFormat
10 11 12 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb', line 10 def initialize() = end |
Instance Method Details
#content ⇒ Object
67 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb', line 67 def content = .content |
#format ⇒ Hash
Formats the message for the Gemini chat completions API
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb', line 17 def format catch(:abort) do if Hash === {role: [:role], parts: format_content([:content])} elsif .tool_call? {role: .role, parts: .extra[:original_tool_calls].map { {"functionCall" => _1} }} else {role: .role, parts: format_content(.content)} end end end |
#format_content(content) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb', line 29 def format_content(content) case content when Array content.empty? ? throw(:abort, nil) : content.flat_map { format_content(_1) } when LLM::Response format_response(content) when File content.close unless content.closed? format_content(LLM.File(content.path)) when LLM::File file = content [{inline_data: {mime_type: file.mime_type, data: file.to_b64}}] when String [{text: content}] when LLM::Message format_content(content.content) when LLM::Function::Return [{functionResponse: {name: content.name, response: content.value}}] else prompt_error!(content) end end |
#format_response(response) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb', line 52 def format_response(response) if response.file? file = response [{file_data: {mime_type: file.mime_type, file_uri: file.uri}}] else prompt_error!(content) end end |
#message ⇒ Object
66 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb', line 66 def = |
#prompt_error!(object) ⇒ Object
61 62 63 64 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb', line 61 def prompt_error!(object) raise LLM::PromptError, "The given object (an instance of #{object.class}) " \ "is not supported by the Gemini API" end |