Module: Lf::LLAMA
- Defined in:
- lib/llamafile.rb
Defined Under Namespace
Classes: Llama
Constant Summary collapse
- DEF =
{ stream: false, grammar: %[root ::= l+\nl ::= i "\n"\ni ::= [^\n\t{|}]+ [.!?]], n_predict: 2048, n_probs: 0, cache_prompt: true, min_keep: 10, min_p: 0.05, mirostat: 2, mirostat_eta: 0.1, mirostat_tau: 5, repeat_lat_n: 256, repeat_penalty: 2, slot_id: -1, temperature: 0, tfs_z: 1, top_k: 95, top_p: 0.95, typical_p: 1, stop: ['</s>','Llama:','User:'] }
Class Method Summary collapse
Class Method Details
.post(h = {}, &b) ⇒ Object
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 |
# File 'lib/llamafile.rb', line 34 def self.post h={}, &b hh = { headers: { "Content-Type": "application/json", "Connection": 'keep-alive', "Priority": 'u=0' }, body: JSON.generate(DEF.merge(h)) } fiber = Fiber.new do |hhh| begin r = Llama.post('/completion', hhh) #puts %[LLAMA CODE: #{r.code}] if r.code == 200 rr = r['content'].gsub(/<.+>/, "").gsub(/\s\s+/, " ").gsub(/\n+/, "\n"); if block_given? Fiber.yield b.call(rr); else Fiber.yield rr; end else Fiber.yield false end rescue => err puts %[LLAMA POST ERR: #{err}] Fiber.yield false end end fiber.resume(hh) end |