Class: Btape::LLM::Generator
- Inherits:
-
Object
- Object
- Btape::LLM::Generator
- Defined in:
- lib/btape/llm/generator.rb
Overview
Turns a description of a recording into a tape, by asking a model for one and then holding it to the language: what comes back is parsed before it is handed on, and a reply that does not parse goes back with the parser's complaint attached.
That loop is the point of generating a tape rather than pasting one out of a chat window. A small local model reliably invents a command or forgets a quote; it just as reliably fixes it when told which line.
Constant Summary collapse
- ATTEMPTS =
3- FENCED =
Models are told not to fence their answer, and fence it anyway.
/```[\w+-]*\n(.*?)```/m
Instance Method Summary collapse
-
#call(description, context: nil) ⇒ Object
Returns the tape as a String.
-
#initialize(client: Client.new, attempts: ATTEMPTS, logger: NullLogger.new) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(client: Client.new, attempts: ATTEMPTS, logger: NullLogger.new) ⇒ Generator
Returns a new instance of Generator.
25 26 27 28 29 |
# File 'lib/btape/llm/generator.rb', line 25 def initialize(client: Client.new, attempts: ATTEMPTS, logger: NullLogger.new) @client = client @attempts = attempts @logger = logger end |
Instance Method Details
#call(description, context: nil) ⇒ Object
Returns the tape as a String. Raises LLM::Error if the model could not be reached, or would not produce a tape that parses.
33 34 35 36 37 38 39 40 41 |
# File 'lib/btape/llm/generator.rb', line 33 def call(description, context: nil) raise Error, 'nothing was said about what to record' if description.to_s.strip.empty? = [ { role: 'system', content: Prompt.system }, { role: 'user', content: Prompt.user(description.strip, context: context) } ] attempt() end |