Module: LLM::Ollama::ResponseParser

Defined in:
lib/llm/providers/ollama/response_parser.rb

Instance Method Summary collapse

Instance Method Details

#parse_completion(body) ⇒ Hash

Parameters:

  • body (Hash)

    The response body from the LLM provider

Returns:

  • (Hash)


24
25
26
27
28
29
30
31
# File 'lib/llm/providers/ollama/response_parser.rb', line 24

def parse_completion(body)
  {
    model: body["model"],
    choices: [LLM::Message.new(*body["message"].values_at("role", "content"), {response: self})],
    prompt_tokens: body.dig("prompt_eval_count"),
    completion_tokens: body.dig("eval_count")
  }
end

#parse_embedding(body) ⇒ Hash

Parameters:

  • body (Hash)

    The response body from the LLM provider

Returns:

  • (Hash)


11
12
13
14
15
16
17
18
# File 'lib/llm/providers/ollama/response_parser.rb', line 11

def parse_embedding(body)
  {
    model: body["model"],
    embeddings: body["data"].map { _1["embedding"] },
    prompt_tokens: body.dig("usage", "prompt_tokens"),
    total_tokens: body.dig("usage", "total_tokens")
  }
end