Class: Slidict::Llm::Client
- Inherits:
-
Object
- Object
- Slidict::Llm::Client
- Defined in:
- lib/slidict/llm/client.rb
Overview
Talks to any OpenAI Compatible API (OpenAI, Ollama, LM Studio, vLLM, etc.) via the standard /chat/completions endpoint. Configure the target with Slidict::Config (base_url, api_key, model).
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #generate_slides(deck) ⇒ Object
-
#initialize(base_url:, api_key:, model:) ⇒ Client
constructor
A new instance of Client.
-
#lint_slides(slide_texts, translate: nil) ⇒ Object
slide_texts is an array of slide bodies (1-indexed by position) as produced by Slidict::Lint::SlideParser.
-
#list_models ⇒ Object
Returns a sorted array of model IDs available at the endpoint.
-
#verify_connection! ⇒ Object
Checks that the endpoint is reachable before the (slower, more expensive) chat completion request is made.
Constructor Details
#initialize(base_url:, api_key:, model:) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 |
# File 'lib/slidict/llm/client.rb', line 15 def initialize(base_url:, api_key:, model:) @base_url = base_url @api_key = api_key @model = model end |
Instance Method Details
#generate_slides(deck) ⇒ Object
38 39 40 41 |
# File 'lib/slidict/llm/client.rb', line 38 def (deck) content = chat_completion(prompt_for(deck)) (content) end |
#lint_slides(slide_texts, translate: nil) ⇒ Object
slide_texts is an array of slide bodies (1-indexed by position) as produced by Slidict::Lint::SlideParser. Returns an array of Slidict::Lint::Finding.
46 47 48 49 |
# File 'lib/slidict/llm/client.rb', line 46 def (, translate: nil) content = chat_completion(lint_prompt_for(, translate: translate)) findings_from(content) end |
#list_models ⇒ Object
Returns a sorted array of model IDs available at the endpoint.
29 30 31 32 33 34 35 36 |
# File 'lib/slidict/llm/client.rb', line 29 def list_models response = get_models_response raise Error, "#{response.code} #{response.}" unless response.is_a?(Net::HTTPSuccess) Array(JSON.parse(response.body)["data"]).map { |m| m["id"] }.sort rescue JSON::ParserError => e raise Error, "could not parse models response: #{e.}" end |
#verify_connection! ⇒ Object
Checks that the endpoint is reachable before the (slower, more expensive) chat completion request is made. Raises Error on failure.
23 24 25 26 |
# File 'lib/slidict/llm/client.rb', line 23 def verify_connection! response = get_models_response raise Error, "#{response.code} #{response.}" unless response.is_a?(Net::HTTPSuccess) end |