boxcars 0.7.1 → 0.7.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 +4 -4
- data/Gemfile.lock +2 -2
- data/lib/boxcars/conversation.rb +1 -1
- data/lib/boxcars/conversation_prompt.rb +1 -1
- data/lib/boxcars/engine/cerebras.rb +6 -6
- data/lib/boxcars/version.rb +1 -1
- metadata +2 -3
- data/lib/boxcars/engine/intelligence/client.rb +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 517934e9dae206e574b969cd8645b3bfe287ab0cf2a5567a25f83f9b87257b67
|
4
|
+
data.tar.gz: 1208007664c046fa3da7d92e367b4032d1eeabef18635b74358d09a89130305d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e410138d08fd6744a5ef27aa8724db7839b9ff272e319df9d79b9d1ad1e0d27088da932b83367d82b6458e319eb1710038f0c9e03212b7b3f59c8dee61ac4e2
|
7
|
+
data.tar.gz: '09716daacbcecba8debb27c3b243e25087f609c033fdccad40dd5ddad4f9b311d0764ab9a816d0a9d1ae5bfb51b0fdaa5c13fffbb7eb2034c5f39ea78d11e906'
|
data/Gemfile.lock
CHANGED
data/lib/boxcars/conversation.rb
CHANGED
@@ -95,7 +95,7 @@ module Boxcars
|
|
95
95
|
raise KeyError, "Prompt format error: #{first_line}"
|
96
96
|
end
|
97
97
|
|
98
|
-
def as_intelligence_conversation(inputs
|
98
|
+
def as_intelligence_conversation(inputs: nil)
|
99
99
|
conversation = Intelligence::Conversation.new
|
100
100
|
no_history.each do |ln|
|
101
101
|
message = Intelligence::Message.new(ln[0])
|
@@ -56,7 +56,7 @@ module Boxcars
|
|
56
56
|
# @param inputs [Hash] The inputs to use for the prompt
|
57
57
|
# @return [Intelligence::Conversation] The converted conversation
|
58
58
|
def as_intelligence_conversation(inputs: nil)
|
59
|
-
conversation.
|
59
|
+
conversation.as_intelligence_conversation(inputs: inputs)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -60,17 +60,17 @@ module Boxcars
|
|
60
60
|
def client(prompt:, inputs: {}, api_key: nil, **kwargs)
|
61
61
|
params = cerebras_params.merge(kwargs)
|
62
62
|
adapter = Cerebras.adapter(api_key: api_key, params: params)
|
63
|
-
raise Error, "
|
63
|
+
raise Error, "Cerebras: No response from API" unless adapter
|
64
64
|
|
65
65
|
convo = prompt.as_intelligence_conversation(inputs: inputs)
|
66
|
-
|
67
|
-
# Add content processing
|
68
|
-
Boxcars.debug("Sending to Cerebras:\n#{convo}", :cyan) if Boxcars.configuration.log_prompts
|
66
|
+
raise Error, "Cerebras: No conversation" unless convo
|
69
67
|
|
70
68
|
# Make API call
|
71
69
|
request = Intelligence::ChatRequest.new(adapter: adapter)
|
72
70
|
response = request.chat(convo)
|
73
|
-
|
71
|
+
return JSON.parse(response.body) if response.success?
|
72
|
+
|
73
|
+
raise Error, "Cerebras: #{response.reason_phrase}"
|
74
74
|
rescue StandardError => e
|
75
75
|
Boxcars.error("Cerebras Error: #{e.message}", :red)
|
76
76
|
raise
|
@@ -95,7 +95,7 @@ module Boxcars
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def check_response(response)
|
98
|
-
return response.
|
98
|
+
return if response.present? && response.key?("choices")
|
99
99
|
|
100
100
|
raise KeyError, "CEREBRAS_API_KEY not valid" if response&.reason_phrase == "Unauthorized"
|
101
101
|
|
data/lib/boxcars/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boxcars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francis Sullivan
|
@@ -172,7 +172,6 @@ files:
|
|
172
172
|
- lib/boxcars/engine/gpt4all_eng.rb
|
173
173
|
- lib/boxcars/engine/groq.rb
|
174
174
|
- lib/boxcars/engine/intelligence.rb
|
175
|
-
- lib/boxcars/engine/intelligence/client.rb
|
176
175
|
- lib/boxcars/engine/ollama.rb
|
177
176
|
- lib/boxcars/engine/openai.rb
|
178
177
|
- lib/boxcars/engine/perplexityai.rb
|
@@ -231,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
231
230
|
- !ruby/object:Gem::Version
|
232
231
|
version: '0'
|
233
232
|
requirements: []
|
234
|
-
rubygems_version: 3.5.
|
233
|
+
rubygems_version: 3.5.16
|
235
234
|
signing_key:
|
236
235
|
specification_version: 4
|
237
236
|
summary: Boxcars is a gem that enables you to create new systems with AI composability.
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Boxcars
|
4
|
-
class Intelligence
|
5
|
-
# Client for interacting with the Intelligence API
|
6
|
-
class Client
|
7
|
-
BASE_URL = "https://api.intelligence.com/v1"
|
8
|
-
DEFAULT_TIMEOUT = 120
|
9
|
-
|
10
|
-
def initialize(api_key:)
|
11
|
-
@api_key = api_key
|
12
|
-
@connection = Faraday.new(
|
13
|
-
url: BASE_URL,
|
14
|
-
headers: {
|
15
|
-
"Content-Type" => "application/json",
|
16
|
-
"Authorization" => "Bearer #{@api_key}"
|
17
|
-
},
|
18
|
-
request: {
|
19
|
-
timeout: DEFAULT_TIMEOUT
|
20
|
-
}
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Generate a response from the Intelligence API
|
25
|
-
def generate(parameters:)
|
26
|
-
response = @connection.post("/generate") do |req|
|
27
|
-
req.body = parameters.to_json
|
28
|
-
end
|
29
|
-
|
30
|
-
handle_response(response)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Stream a response from the Intelligence API
|
34
|
-
def stream(parameters:, &block)
|
35
|
-
@connection.post("/generate") do |req|
|
36
|
-
req.options.on_data = block
|
37
|
-
req.headers["Accept"] = "text/event-stream"
|
38
|
-
req.body = parameters.to_json
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def handle_response(response)
|
45
|
-
case response.status
|
46
|
-
when 200
|
47
|
-
JSON.parse(response.body)
|
48
|
-
when 401
|
49
|
-
raise KeyError, "Invalid API key"
|
50
|
-
when 429
|
51
|
-
raise ValueError, "Rate limit exceeded"
|
52
|
-
when 400..499
|
53
|
-
raise ArgumentError, "Bad request: #{response.body}"
|
54
|
-
when 500..599
|
55
|
-
raise Error, "Intelligence API server error"
|
56
|
-
else
|
57
|
-
raise Error, "Unexpected response: #{response.status}"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|