spectre_ai 1.1.1 → 1.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: c7c3acf59b77ad62e0095fb7f91aa0491a50f25d197f94c788ad5ce2bbefbf6f
4
- data.tar.gz: 48b4a9dcda9a013a6dde32ca5008a7dd33a49f4d4678952b8fcbf2089d2ccca6
3
+ metadata.gz: 07e44eac15c5b58b13b2dbbb784f1ca4d5364d6aed7f2fe5a5d797c0ee5fd43d
4
+ data.tar.gz: 3d33fb9b5c228eb4577f678d5e2f310d401671cd242b0ca02bcf9a80df55fad8
5
5
  SHA512:
6
- metadata.gz: be7bf9f1570bad924509a8b8ad2a4671d019d20325696c4a2587e586f4a9314e395d822857cf9a277c84fd69e1d61e1231b356405266b5147187d6ec01d7dd33
7
- data.tar.gz: f80dddebe6a99f7c946a8364f62f15112a974ad6cffe5a031baf5c1a9b151f39c12b870c60945277b8c57e78e51a0f0bb7147c620af11e4a59ed1ce485bfebab
6
+ metadata.gz: 17c0de5cfb63e7d072e1c85d221abbdadabd2eb131276b22ceff834c7eaea05ce3a2a1a02c826887d39b54619c8841d651a7aaa3823a5eabf4f0f3faaf5c263e
7
+ data.tar.gz: 14ffff5c963ea79c2360e9517c9906f36b3bc27494732c3f3bd640c0f492aacdd0bdaf190be2effd5bbb9bc875315afe441c8583c07f3ff2faf6f7a8cdcdcceb
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:** [11th Oct 2024]
73
+ **Release Date:** [10th Oct 2024]
74
74
 
75
75
  **New Features:**
76
76
 
@@ -81,3 +81,16 @@ 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`).
@@ -9,7 +9,7 @@ module Spectre
9
9
  attr_reader :prompts_path
10
10
 
11
11
  def prompts_path
12
- @prompts_path ||= detect_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
- File.join(Dir.pwd, 'app', 'spectre', 'prompts')
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spectre # :nodoc:all
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.2"
5
5
  end
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.1
4
+ version: 1.1.2
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-10-10 00:00:00.000000000 Z
12
+ date: 2024-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-rails