pedicab 0.2.5 → 0.2.6

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: 604cd57e9e82e42814fdc57e4567d4fc5c79cc327dc625661c0a779ae93385a9
4
- data.tar.gz: 6e3529079803118cfd4388e6fcbb306118cf6d1b79d46f327dbae771450456ae
3
+ metadata.gz: 716be3e53c7fa686c33a263f347f479a44c4f73bca8d4a5a7fa9c9fa20880632
4
+ data.tar.gz: b3658d81c0568db065fc8227d238db65de407badc2bd5734471485a782dd03f9
5
5
  SHA512:
6
- metadata.gz: 7102f74829b5728889ce7d873a26107fb404e78801cce68bec4342dfc31ba47df9d0629ea766ca752bc74f711a40cced780c94afab199a43b9133adf5bf65e33
7
- data.tar.gz: 24da9301bb967fd87ed4828885183e76a6900d4dbcf7628672bf3b81b6c68d820f25b9c76c8a5496e7304706104686aba2317f6262635c4393efc1c5478e54a5
6
+ metadata.gz: 954d6b4de05b578e31636af22198c688412bca7f5cd6287210e972e1a75d3439469f140668cca1221962a69d723feee7abdcd7222b24b081f30f17cc5271df6d
7
+ data.tar.gz: 72877701df3210b97e3ac40eef94fa97b2a8581e2f6dd139007c6ee48a7ecba0d6e204f23bb26db0f3ed93a491347d0a18ba72b7f22bf19941c26eca3e36b545
data/lib/pedicab/ride.rb CHANGED
@@ -82,7 +82,7 @@ module Pedicab
82
82
  puts %[#====[ #{@ride.length} ][#{@state[:action]}]\n#{@state[:input]}]
83
83
  Pedicab.on[:before].call(self)
84
84
  @state[:took] = Benchmark.realtime do
85
- Open3.popen3("sudo python3 bin/pedicab.py /models/#{h[:model]}.gguf") do |stdin, stdout, stderr, wait_thread|
85
+ Open3.popen3("sudo python3 lib/pedicab.py /models/#{h[:model]}.gguf") do |stdin, stdout, stderr, wait_thread|
86
86
  x = lambda { stdin.puts(JSON.generate(h)); stdout.gets }
87
87
  begin
88
88
  xx = x.call()
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pedicab
4
- VERSION = "0.2.5"
4
+ VERSION = "0.2.6"
5
5
  end
data/lib/pedicab.py ADDED
@@ -0,0 +1,48 @@
1
+ from llama_cpp.llama import Llama, LlamaGrammar
2
+
3
+ import sys
4
+ import json
5
+
6
+ llm = Llama(
7
+ model_path=sys.argv[1],
8
+ # model_path="/models/planner.gguf",
9
+ # model_path="/models/smollm.gguf",
10
+ verbose=False,
11
+ errors="ignore",
12
+ n_ctx=8192
13
+ )
14
+
15
+ __sys = "A conversation between a curious Human and an all knowing Assistant who responds only to what was asked in simple terms and never repeats itself.\n\nWhen asked to respond with a single value, respond with only that value.\nWhen asked to list items, respond with the list of items sepearated by a newline only and again - never repeat yourself.\nWhen asked to respond with a mathmatical formula, respond with only the bare formula in the format necessary to be evaluated by the ruby eqn gem.\nOtherwise, respond with a single level outline and NEVER repeat yourself."
16
+ #__sys = "A conversation between a Human and an all knowing Llama."
17
+
18
+
19
+ prompt = __sys
20
+ convo = [{ "role": "system", "content": prompt }]
21
+ grammars = {
22
+ "bool": 'root ::= ("yes" | "no")',
23
+ "number": "root ::= (\"-\"?([0-9]+))",
24
+ "string": "root ::= ([^\r\n\x0b\x0c\x85\u2028\u2029]+ \"\n\")"
25
+ }
26
+
27
+
28
+
29
+ while True:
30
+ user = json.loads(input(""))
31
+
32
+ if (user["role"] == "assistant"):
33
+ convo.append({ "role": "user", "content": user["content"] })
34
+ convo.append({ "role": "assistant", "content": user["response"] })
35
+
36
+ if (user["role"] == "system"):
37
+ output = llm( user["content"], stop=["\n"], echo=False, temperature=0.0, grammar=LlamaGrammar.from_string(grammars[user['response']]))["choices"][0]["text"]
38
+ user["role"] = "assistant"
39
+ user["content"] = output
40
+
41
+ if (user["role"] == "user"):
42
+ convo.append({ "role": "user", "content": user["content"] })
43
+ output = llm.create_chat_completion( messages=convo, temperature=0.0)["choices"][0]["message"]["content"]
44
+ convo.append({ "role": "assistant", "content": output })
45
+ user["role"] = "assistant"
46
+ user["content"] = output
47
+
48
+ print(json.dumps(user))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pedicab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Olson
@@ -138,6 +138,7 @@ files:
138
138
  - books/machiavelli-the_prince.txt
139
139
  - books/sun_tzu-art_of_war.txt
140
140
  - books/us_army-bayonette.txt
141
+ - lib/pedicab.py
141
142
  - lib/pedicab.rb
142
143
  - lib/pedicab/calc.rb~
143
144
  - lib/pedicab/link.rb