Class: LLM::Gemini::Format::CompletionFormat
- Inherits:
-
Object
- Object
- LLM::Gemini::Format::CompletionFormat
- Defined in:
- 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
-
#initialize(message) ⇒ CompletionFormat
constructor
A new instance of CompletionFormat.
- #message ⇒ Object
Constructor Details
#initialize(message) ⇒ CompletionFormat
Returns a new instance of CompletionFormat.
10 11 12 |
# File 'lib/llm/providers/gemini/format/completion_format.rb', line 10 def initialize() @message = end |
Instance Method Details
#content ⇒ Object
52 |
# File 'lib/llm/providers/gemini/format/completion_format.rb', line 52 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/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 |
# File '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::File file = content [{file_data: {mime_type: file.mime_type, file_uri: file.uri}}] 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 [{text: JSON.dump(content.value)}] else raise LLM::Error::PromptError, "The given object (an instance of #{content.class}) " \ "is not supported by the Gemini API" end end |
#message ⇒ Object
51 |
# File 'lib/llm/providers/gemini/format/completion_format.rb', line 51 def = @message |