Module: LLM::Gemini::ResponseParser
- Defined in:
- lib/llm/providers/gemini/response_parser.rb,
lib/llm/providers/gemini/response_parser/completion_parser.rb
Defined Under Namespace
Classes: CompletionParser
Instance Method Summary
collapse
Instance Method Details
#parse_completion(body) ⇒ Hash
13
14
15
|
# File 'lib/llm/providers/gemini/response_parser.rb', line 13
def parse_completion(body)
CompletionParser.new(body).format(self)
end
|
#parse_embedding(body) ⇒ Hash
21
22
23
24
25
26
|
# File 'lib/llm/providers/gemini/response_parser.rb', line 21
def parse_embedding(body)
{
model: "text-embedding-004",
embeddings: body.dig("embedding", "values")
}
end
|
#parse_image(body) ⇒ Hash
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/llm/providers/gemini/response_parser.rb', line 32
def parse_image(body)
{
urls: [],
images: body["candidates"].flat_map do |c|
parts = c["content"]["parts"]
parts.filter_map do
data = _1.dig("inlineData", "data")
next unless data
StringIO.new(data.unpack1("m0"))
end
end
}
end
|