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) ⇒ Object
slide_texts is an array of slide bodies (1-indexed by position) as produced by Slidict::Lint::SlideParser.
-
#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
32 33 34 35 |
# File 'lib/slidict/llm/client.rb', line 32 def (deck) content = chat_completion(prompt_for(deck)) (content) end |
#lint_slides(slide_texts) ⇒ 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.
40 41 42 43 |
# File 'lib/slidict/llm/client.rb', line 40 def () content = chat_completion(lint_prompt_for()) findings_from(content) 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 27 28 29 30 |
# File 'lib/slidict/llm/client.rb', line 23 def verify_connection! uri = endpoint_uri("models") request = Net::HTTP::Get.new(uri) request["Authorization"] = "Bearer #{@api_key}" response = perform_request(uri, request) raise Error, "#{response.code} #{response.}" unless response.is_a?(Net::HTTPSuccess) end |