Skip to content

Commit

Permalink
Remove root option for config
Browse files Browse the repository at this point in the history
  • Loading branch information
kladaFOX committed Oct 10, 2024
1 parent aa68a08 commit 28d44b5
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 27 deletions.
18 changes: 0 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,6 @@ This version enhances the flexibility and robustness of the Completions class, e
**New Features:**
* **Root Attribute in Configuration:**
* Introduced a `root` attribute to the Spectre configuration. This allows users to specify a custom root directory for loading prompts or other templates.
* Example usage in initializer:
```ruby
Spectre.setup do |config|
config.api_key = 'your_openai_api_key'
config.root = Rails.root # or any custom path
end
```
* If `root` is not set, Spectre will default to the current working directory (Dir.pwd).
* This is especially useful when integrating Spectre into other gems or non-Rails projects where the root directory might differ.


* **Prompt Path Detection:**
* Prompt paths now use the configured `root` to locate the template files. This ensures that Spectre works correctly in various environments where template paths may vary.


* **Nested Template Support in Prompts**
* You can now organize your prompt files in nested directories and render them using the `Spectre::Prompt.render` method.
* **Example**: To render a template from a nested folder:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ This will create a file at `config/initializers/spectre.rb`, where you can set y
Spectre.setup do |config|
config.api_key = 'your_openai_api_key'
config.llm_provider = :openai
config.root = Rails.root # Optional: Set the root path for the gem
end
```

Expand Down
2 changes: 0 additions & 2 deletions lib/generators/spectre/templates/spectre_initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
config.llm_provider = :openai
# Set the API key for your chosen LLM
config.api_key = ENV.fetch('CHATGPT_API_TOKEN')
# Set the root directory for your project (optional)
# config.root = File.expand_path('..', __dir__)
end
2 changes: 1 addition & 1 deletion lib/spectre.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def spectre(*modules)
end

class << self
attr_accessor :api_key, :llm_provider, :root
attr_accessor :api_key, :llm_provider

def setup
yield self
Expand Down
6 changes: 1 addition & 5 deletions lib/spectre/prompt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ def render(template:, locals: {})

# Detects the appropriate path for prompt templates
def detect_prompts_path
if Spectre.root
File.join(Spectre.root, 'app', 'spectre', 'prompts')
else
File.join(Dir.pwd, 'app', 'spectre', 'prompts')
end
File.join(Dir.pwd, 'app', 'spectre', 'prompts')
end

# Split the template parameter into path and prompt
Expand Down

0 comments on commit 28d44b5

Please sign in to comment.