Class: Slidict::LLMClient
- Inherits:
-
Object
- Object
- Slidict::LLMClient
- 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:) ⇒ LLMClient
constructor
A new instance of LLMClient.
-
#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:) ⇒ LLMClient
Returns a new instance of LLMClient.
14 15 16 17 18 |
# File 'lib/slidict/llm_client.rb', line 14 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
31 32 33 34 |
# File 'lib/slidict/llm_client.rb', line 31 def (deck) content = chat_completion(prompt_for(deck)) (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.
22 23 24 25 26 27 28 29 |
# File 'lib/slidict/llm_client.rb', line 22 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 |