llamafile 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67dc5a39cf9a4f73b89442e5cd31b9d45112f7309a6ceb0a8eb4d1f7dd84e8e5
4
- data.tar.gz: f1ae12e127ca8ef526f55b4b05d47c0bd6f4a4b803cd5ab26db764a7187a22c6
3
+ metadata.gz: 2f4c56d4887f772001a9d141b7f66901a2c33d21b064aa754475f619a4d5b35b
4
+ data.tar.gz: 60e47d63ec8430daf21f85b8ec2a5894bf9a7b197dd5f33dab154f810c981714
5
5
  SHA512:
6
- metadata.gz: d0e6962367c2496c848d7e22f0201be9a982cc60bd9da741b4809dd4516d90c2bd6873761ff5a52d750b13d5d3083f1d428dd6c95bf3a3ae30f2bbd246349cfc
7
- data.tar.gz: 68102da624b5dc732ff0711b68a0f972b6e79c5d13b2af2252e33c9d7140966f28a9b7ad624f970fefa6625fe39608a7dc1794f74b2daf4b5dbcaaa96106db2d
6
+ metadata.gz: cc2e10c0384169ec2499687ab71e32d99b989dbc7171dc33385e417aacf3f279228385f1ddf61c77ce9751ada9195f0d14f93705fcd8d0ad283ce7f907ddb279
7
+ data.tar.gz: 8921078534377357b9f46f48b2961aaf401037af283bfe3373f5cd9574e12c3fa31fc4686d542ebbfbb5f6c1ccb34f070857d59f0ebd3f8c86b24e18c2b0293e
@@ -1,33 +1,40 @@
1
-
2
- class Llama
3
- attr_accessor :depth, :context, :batch
4
- def initialize
5
- @i = []
6
- @o = []
7
- @context = 2048
8
- @batch = 128
9
- @depth = 1
10
- end
11
- def args
12
- %[-c #{@context} -b #{@batch}]
13
- end
14
- def llama i
15
- `llama #{args} -p "#{i}" 2> /dev/null`.strip.gsub(i,"").strip
16
- end
17
- def trim i,o
18
- @i << i
19
- @o << o
20
- [@i,@o].each { |e| if e.length > @depth; e.shift; end; }
21
- end
22
- def process k
23
- o = llama(%[#{k}\n])
24
- if o != nil
25
- trim p, o
26
- end
27
- if "#{o}".length == 0
28
- o = "I don't know."
29
- end
30
- return { input: k, output: o }
31
- end
1
+ require 'httparty'
2
+ module LLAMA
3
+ class Llama
4
+ include HTTParty
5
+ base_uri 'http://127.0.0.1:8080'
6
+ end
7
+
8
+ @@P = {
9
+ respond: %[Respond simply and directly with as few words possible.],
10
+ answer: %[Answer questions from the user as honestly and correctly as possible.],
11
+ friend: %[Respond in a helpful friendly manner.],
12
+ nanny: %[Construct a story based upon things you are told.],
13
+ truth: %[Respond truthfully.]
14
+ }
15
+
16
+ def self.prompt
17
+ @@P
18
+ end
19
+
20
+
21
+ def self.flagz
22
+ Llama.get('/flagz')
23
+ end
24
+
25
+ def self.post p, *i
26
+ h = LLAMA.flagz.to_h
27
+ h['prompt'] = p
28
+ h['messages'] = [i].flatten
29
+ puts %[LLAMA POST #{h}]
30
+ r = Llama.post('/v1/chat/completions',
31
+ body: JSON.generate(h),
32
+ headers: {
33
+ 'Content-Type' => 'application/json',
34
+ 'Accept' => 'application/json',
35
+ 'Prefer' => 'wait'
36
+ })
37
+ r['choices'][0]['message']['content']
38
+ end
32
39
  end
33
40
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Llamafile
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/llamafile.rb CHANGED
@@ -6,10 +6,26 @@ require_relative "llamafile/llama"
6
6
 
7
7
  module Llamafile
8
8
  class Error < StandardError; end
9
+
10
+ attr_accessor :prompt
11
+
12
+ def self.prompt
13
+ LLAMA.prompt
14
+ end
15
+
16
+ def prompt
17
+ Llamafile.prompt
18
+ end
19
+
9
20
  def self.llama i
10
- Llama.new().process(i)
21
+ LLAMA.post(LLAMA.prompt[:truth], { role: 'user', content: i })
11
22
  end
23
+
12
24
  def llama i
13
- Llamafile.process(i)
25
+ Llamafile.llama i
26
+ end
27
+
28
+ def self.<< i
29
+ Llamafile.llama i
14
30
  end
15
31
  end
data/llamafile.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  # Uncomment to register a new dependency of your gem
34
- # spec.add_dependency "example-gem", "~> 1.0"
34
+ spec.add_dependency "httparty"
35
35
 
36
36
  # For more information and examples about making a new gem, check out our
37
37
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llamafile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Olson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-21 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2025-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Wraps a locally installed llamafile in an a pure ruby object.
14
28
  email:
15
29
  - xorgnak@gmail.com
@@ -50,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
64
  - !ruby/object:Gem::Version
51
65
  version: '0'
52
66
  requirements: []
53
- rubygems_version: 3.3.15
67
+ rubygems_version: 3.4.20
54
68
  signing_key:
55
69
  specification_version: 4
56
70
  summary: llamafile wrapper