spectre_ai 1.1.1 → 1.1.3
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/CHANGELOG.md +23 -1
- data/lib/spectre/openai/completions.rb +0 -21
- data/lib/spectre/prompt.rb +29 -2
- data/lib/spectre/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6cce97e6ac3ab3cde8536f7d422609ff35756847c562769f21305a68421cb89
|
4
|
+
data.tar.gz: cd092c3a8eef87550999630dc77c66eb8900ff24ed4129eff32f8050cb90a5dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4b701d7447eabb48a5c82e0d1bcbf5585c68497a49c513a81a0091e409aa84fd44d3c45e39b2b88ff53ef4643c63e047f24e88a705c3358b08be408cd0f9ed1
|
7
|
+
data.tar.gz: 639a433617ffc983cc078d26a22b516d415086c66e5091e42e1c85219f6885efe64daf924431182e1589db073a19bb8ab330c8a71793a0d5f7a95a2a2e722237
|
data/CHANGELOG.md
CHANGED
@@ -70,7 +70,7 @@ This version enhances the flexibility and robustness of the Completions class, e
|
|
70
70
|
|
71
71
|
# Changelog for Version 1.1.1
|
72
72
|
|
73
|
-
**Release Date:** [
|
73
|
+
**Release Date:** [10th Oct 2024]
|
74
74
|
|
75
75
|
**New Features:**
|
76
76
|
|
@@ -81,3 +81,25 @@ This version enhances the flexibility and robustness of the Completions class, e
|
|
81
81
|
Spectre::Prompt.render(template: 'classification/intent/user', locals: { query: 'What is AI?' })
|
82
82
|
```
|
83
83
|
* This feature allows for better organization and scalability when dealing with multiple prompt categories and complex scenarios.
|
84
|
+
|
85
|
+
|
86
|
+
# Changelog for Version 1.1.2
|
87
|
+
|
88
|
+
**Release Date:** [11th Oct 2024]
|
89
|
+
|
90
|
+
**New Features:**
|
91
|
+
|
92
|
+
* **Dynamic Project Root Detection for Prompts**
|
93
|
+
* The `Spectre::Prompt.render` method now dynamically detects the project root based on the presence of project-specific markers, such as `Gemfile`, `.git`, or `config/application.rb`.
|
94
|
+
* This change allows for greater flexibility when using spectre in different environments and projects, ensuring the prompt templates are found regardless of where spectre is used.
|
95
|
+
* **Example**: If you're using `spectre` inside a gem, the `detect_prompts_path` method will now correctly resolve the prompts path within the gem project root.
|
96
|
+
* If no markers are found, the system falls back to the current working directory (`Dir.pwd`).
|
97
|
+
|
98
|
+
# Changelog for Version 1.1.3
|
99
|
+
|
100
|
+
**Release Date:** [2nd Dec 2024]
|
101
|
+
|
102
|
+
**Fixes:**
|
103
|
+
|
104
|
+
* **Removed unnecessary validations in `Completions` class**
|
105
|
+
* Removed redundant validations in the `Completions` class that were causing unnecessary errors in specific edge cases. LLM providers returns a proper errors messages now.
|
@@ -72,27 +72,6 @@ module Spectre
|
|
72
72
|
if messages.empty?
|
73
73
|
raise ArgumentError, "Messages cannot be empty."
|
74
74
|
end
|
75
|
-
|
76
|
-
# Iterate through each message and perform detailed validation.
|
77
|
-
messages.each_with_index do |msg, index|
|
78
|
-
# Check if each message hash contains the required keys: :role and :content.
|
79
|
-
# These keys are necessary for defining the type of message and its content.
|
80
|
-
unless msg.key?(:role) && msg.key?(:content)
|
81
|
-
raise ArgumentError, "Message at index #{index} must contain both :role and :content keys."
|
82
|
-
end
|
83
|
-
|
84
|
-
# Check if the role is one of the allowed values: 'system', 'user', or 'assistant'.
|
85
|
-
# This ensures that each message has a valid role identifier.
|
86
|
-
unless %w[system user assistant].include?(msg[:role])
|
87
|
-
raise ArgumentError, "Invalid role '#{msg[:role]}' at index #{index}. Valid roles are 'system', 'user', 'assistant'."
|
88
|
-
end
|
89
|
-
|
90
|
-
# Check if the content is a non-empty string.
|
91
|
-
# This prevents empty or non-string content, which would be meaningless in a conversation.
|
92
|
-
unless msg[:content].is_a?(String) && !msg[:content].strip.empty?
|
93
|
-
raise ArgumentError, "Content for message at index #{index} must be a non-empty string."
|
94
|
-
end
|
95
|
-
end
|
96
75
|
end
|
97
76
|
|
98
77
|
# Helper method to generate the request body
|
data/lib/spectre/prompt.rb
CHANGED
@@ -9,7 +9,7 @@ module Spectre
|
|
9
9
|
attr_reader :prompts_path
|
10
10
|
|
11
11
|
def prompts_path
|
12
|
-
@prompts_path
|
12
|
+
@prompts_path = detect_prompts_path
|
13
13
|
end
|
14
14
|
|
15
15
|
# Render a prompt by reading and rendering the YAML template
|
@@ -50,7 +50,34 @@ module Spectre
|
|
50
50
|
|
51
51
|
# Detects the appropriate path for prompt templates
|
52
52
|
def detect_prompts_path
|
53
|
-
|
53
|
+
# Find the first non-spectre, non-ruby core file in the call stack
|
54
|
+
calling_file = caller.find do |path|
|
55
|
+
!path.include?('/spectre/') && !path.include?(RbConfig::CONFIG['rubylibdir'])
|
56
|
+
end
|
57
|
+
|
58
|
+
# Determine the directory from where spectre was invoked
|
59
|
+
start_dir = calling_file ? File.dirname(calling_file) : Dir.pwd
|
60
|
+
|
61
|
+
# Traverse up until we find a Gemfile (or another marker of the project root)
|
62
|
+
project_root = find_project_root(start_dir)
|
63
|
+
|
64
|
+
# Return the prompts path based on the detected project root
|
65
|
+
File.join(project_root, 'app', 'spectre', 'prompts')
|
66
|
+
end
|
67
|
+
|
68
|
+
def find_project_root(dir)
|
69
|
+
while dir != '/' do
|
70
|
+
# Check for Gemfile, .git directory, or config/application.rb (Rails)
|
71
|
+
return dir if File.exist?(File.join(dir, 'Gemfile')) ||
|
72
|
+
File.exist?(File.join(dir, 'config', 'application.rb')) ||
|
73
|
+
File.directory?(File.join(dir, '.git'))
|
74
|
+
|
75
|
+
# Move up one directory
|
76
|
+
dir = File.expand_path('..', dir)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Default fallback if no root markers are found
|
80
|
+
Dir.pwd
|
54
81
|
end
|
55
82
|
|
56
83
|
# Split the template parameter into path and prompt
|
data/lib/spectre/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spectre_ai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Klapatok
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-rails
|