tiny_ollama 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tiny_ollama.rb +3 -27
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 598de0585c4437aec61f9963b09e6f623d7c3988f039440cfb1c6bd6303b7a0b
4
- data.tar.gz: e5b5425dee8e809ba501fa0f8bc6951470191e41afd7d3a1c263d00e6ca238aa
3
+ metadata.gz: ca4fe9ba0bb0854333e7c1e62b6f0deb0e1b944e5f406086c7148524743521b7
4
+ data.tar.gz: 47f4a7b71302ea587ad84fd37b9c9ae2cd3d9514ee8b20eb2fe01128f96e42ab
5
5
  SHA512:
6
- metadata.gz: ead24d28f0395d2431403b83401cd7bd0ac59e7df1861c8691be42932283c2f53612d25843b5382652ce30a255ae0a193250a15184e562ec2cab106f616137aa
7
- data.tar.gz: e71614054eeecd5512b77748f69c9dddb3cf882d9e259b0cdce1baf47be372ff3c8993b5054d96977059779b93323d64bec3b90fac53500097fcdc3f32afa53d
6
+ metadata.gz: dab2b666565a058ff3e48080b9de089316fd0cb5be6b7dc764f6ac6ef3e30de351f7bf2de6fb0de0de14a7a221ca81a3a0e1c713d74b6a851bb74cfc008d9e90
7
+ data.tar.gz: e765aee90aef074d6b5cffd9b71da0a90fe20b443feabc305909fd739c07192446bcde7fb46bfab9f888489a632f76e15933ac5c9eb59db6dd02e209182ec35f
data/lib/tiny_ollama.rb CHANGED
@@ -25,30 +25,6 @@ class TinyOllama
25
25
  @format = format
26
26
  end
27
27
 
28
- # sends a request to POST /api/generate
29
- def generate(prompt)
30
- request_body = {
31
- model: @model,
32
- prompt: prompt,
33
- stream: @stream,
34
- keep_alive: @keep_alive,
35
- options: {
36
- num_ctx: @context_size,
37
- }.merge(@format ? { format: @format } : {})
38
- }.to_json
39
-
40
- uri = URI("http://#{@host}:#{@port}/api/generate")
41
- headers = { 'Content-Type' => 'application/json' }
42
- response = Net::HTTP.post(uri, request_body, headers)
43
-
44
- # Handle potential errors (e.g., non-200 responses)
45
- unless response.is_a?(Net::HTTPSuccess)
46
- raise TinyOllamaModelError.new("Ollama API Error: #{response.code} - #{response.body}")
47
- end
48
-
49
- JSON.parse(response.body)['response']
50
- end
51
-
52
28
  # sends a request to POST /api/chat
53
29
  #
54
30
  # messages: an array of hashes in the following format:
@@ -73,7 +49,7 @@ class TinyOllama
73
49
  #
74
50
  # NOTE: the messages parameter needs to include a system message if you want
75
51
  # to override the model's default instructions
76
- def chat(messages)
52
+ def prompt(messages)
77
53
  request_body = {
78
54
  model: @model,
79
55
  messages: messages,
@@ -91,11 +67,11 @@ class TinyOllama
91
67
 
92
68
  # Handle potential errors (e.g., non-200 responses)
93
69
  unless response.is_a?(Net::HTTPSuccess)
94
- raise TinyOllamaModelError.new("Ollama API Error: #{response.code} - #{response.body}")
70
+ raise TinyOllamaModelError, "Ollama API Error: #{response.code} - #{response.body}"
95
71
  end
96
72
 
97
73
  JSON.parse(response.body)['message']['content']
98
74
  end
99
75
  end
100
76
 
101
- class TinyOllamaModelError; end
77
+ class TinyOllamaModelError < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_ollama
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-26 00:00:00.000000000 Z
11
+ date: 2024-07-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: a tiny gem for using ollama's generate and chat endpoints
14
14
  email: jefflunt@gmail.com