Class: RubyLlmMesh::Providers::LocalNode
- Defined in:
- lib/ruby_llm_mesh/providers/local_node.rb
Overview
OpenAI-compatible local runtime (Ollama, LM Studio, vLLM, llama.cpp server, etc.)
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from RubyLlmMesh::Providers::Base
Instance Method Details
#complete(prompt:, system: nil, model: nil, **options) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ruby_llm_mesh/providers/local_node.rb', line 11 def complete(prompt:, system: nil, model: nil, **) model ||= config.local_node_model = [] << { role: "system", content: system } if system << { role: "user", content: prompt } body = { model: model, messages: , stream: false, temperature: .fetch(:temperature, 0.7) } body[:options] = { num_predict: [:max_tokens] } if [:max_tokens] response, latency_ms = http_post( "#{config.local_node_base_url.chomp('/')}/v1/chat/completions", headers: { "Content-Type" => "application/json" }, body: body ) # Fallback to Ollama native chat API if OpenAI-compat endpoint is missing if response.code.to_i == 404 response, latency_ms = http_post( "#{config.local_node_base_url.chomp('/')}/api/chat", headers: { "Content-Type" => "application/json" }, body: { model: model, messages: , stream: false } ) raise_for_status!(response) data = parse_json(response) content = data.dig("message", "content").to_s return Response.new( content: content, provider: name, model: model, usage: {}, raw: data, latency_ms: latency_ms ) end raise_for_status!(response) data = parse_json(response) content = data.dig("choices", 0, "message", "content").to_s Response.new( content: content, provider: name, model: data["model"] || model, usage: data["usage"] || {}, raw: data, latency_ms: latency_ms ) end |
#name ⇒ Object
7 8 9 |
# File 'lib/ruby_llm_mesh/providers/local_node.rb', line 7 def name :local_node end |