feather-ai 0.2.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 31f571486891a197ef789e511c429a5433290f5755330eb8c87e9ebd5d2a1f25
4
+ data.tar.gz: ea99ec7efd75ccab6ce2321cd56bf3e712b0d3a79bef4139b4828eb3e23efa1b
5
+ SHA512:
6
+ metadata.gz: 83000667059ba7fc6090b49029051675e54f6b56ccf5a99e39f5156cd36387467fb0ef01136d2fac5aba9de1be52941c312c721dcb8db760fe5a8fb125731ce1
7
+ data.tar.gz: 0b378a24104f4463d487bc7a4523ff479c8e7cda4ef251fe61b88e75ff2936fde4ee9aec77cfb5677e3246a770a987961192199e2284e7f1dedf1e903ed824c2
data/.idea/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Ignored default folder with query files
5
+ /queries/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
9
+ # Editor-based HTTP Client requests
10
+ /httpRequests/
data/.idea/Feather.iml ADDED
@@ -0,0 +1,78 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="jdk" jdkName="rbenv: 3.4.8" jdkType="RUBY_SDK" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="addressable (v2.8.9, rbenv: 3.4.8) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.3, rbenv: 3.4.8) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="base64 (v0.3.0, rbenv: 3.4.8) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="bigdecimal (v4.0.1, rbenv: 3.4.8) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.6.9, rbenv: 3.4.8) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="crack (v1.0.1, rbenv: 3.4.8) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="date (v3.5.1, rbenv: 3.4.8) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.6.2, rbenv: 3.4.8) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="docile (v1.4.1, rbenv: 3.4.8) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="erb (v6.0.2, rbenv: 3.4.8) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="event_stream_parser (v1.0.0, rbenv: 3.4.8) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="faraday (v2.14.1, rbenv: 3.4.8) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="faraday-multipart (v1.2.0, rbenv: 3.4.8) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="faraday-net_http (v3.4.2, rbenv: 3.4.8) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="faraday-retry (v2.4.0, rbenv: 3.4.8) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="hashdiff (v1.2.1, rbenv: 3.4.8) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="io-console (v0.8.2, rbenv: 3.4.8) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="irb (v1.17.0, rbenv: 3.4.8) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="json (v2.19.1, rbenv: 3.4.8) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="json-schema (v6.2.0, rbenv: 3.4.8) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="language_server-protocol (v3.17.0.5, rbenv: 3.4.8) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="lint_roller (v1.1.0, rbenv: 3.4.8) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="logger (v1.7.0, rbenv: 3.4.8) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="marcel (v1.1.0, rbenv: 3.4.8) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="mcp (v0.8.0, rbenv: 3.4.8) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="multipart-post (v2.4.1, rbenv: 3.4.8) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="net-http (v0.9.1, rbenv: 3.4.8) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="parallel (v1.27.0, rbenv: 3.4.8) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="parser (v3.3.10.2, rbenv: 3.4.8) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="pp (v0.6.3, rbenv: 3.4.8) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="prettyprint (v0.2.0, rbenv: 3.4.8) [gem]" level="application" />
45
+ <orderEntry type="library" scope="PROVIDED" name="prism (v1.9.0, rbenv: 3.4.8) [gem]" level="application" />
46
+ <orderEntry type="library" scope="PROVIDED" name="psych (v5.3.1, rbenv: 3.4.8) [gem]" level="application" />
47
+ <orderEntry type="library" scope="PROVIDED" name="public_suffix (v7.0.5, rbenv: 3.4.8) [gem]" level="application" />
48
+ <orderEntry type="library" scope="PROVIDED" name="racc (v1.8.1, rbenv: 3.4.8) [gem]" level="application" />
49
+ <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, rbenv: 3.4.8) [gem]" level="application" />
50
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.3.1, rbenv: 3.4.8) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="rdoc (v7.2.0, rbenv: 3.4.8) [gem]" level="application" />
52
+ <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.11.3, rbenv: 3.4.8) [gem]" level="application" />
53
+ <orderEntry type="library" scope="PROVIDED" name="reline (v0.6.3, rbenv: 3.4.8) [gem]" level="application" />
54
+ <orderEntry type="library" scope="PROVIDED" name="rexml (v3.4.4, rbenv: 3.4.8) [gem]" level="application" />
55
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.13.2, rbenv: 3.4.8) [gem]" level="application" />
56
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.13.6, rbenv: 3.4.8) [gem]" level="application" />
57
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.13.5, rbenv: 3.4.8) [gem]" level="application" />
58
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.13.8, rbenv: 3.4.8) [gem]" level="application" />
59
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.13.7, rbenv: 3.4.8) [gem]" level="application" />
60
+ <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.85.1, rbenv: 3.4.8) [gem]" level="application" />
61
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.49.1, rbenv: 3.4.8) [gem]" level="application" />
62
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-rspec (v3.9.0, rbenv: 3.4.8) [gem]" level="application" />
63
+ <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.13.0, rbenv: 3.4.8) [gem]" level="application" />
64
+ <orderEntry type="library" scope="PROVIDED" name="ruby_llm (v1.14.0, rbenv: 3.4.8) [gem]" level="application" />
65
+ <orderEntry type="library" scope="PROVIDED" name="ruby_llm-schema (v0.3.0, rbenv: 3.4.8) [gem]" level="application" />
66
+ <orderEntry type="library" scope="PROVIDED" name="simplecov (v0.22.0, rbenv: 3.4.8) [gem]" level="application" />
67
+ <orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.13.2, rbenv: 3.4.8) [gem]" level="application" />
68
+ <orderEntry type="library" scope="PROVIDED" name="simplecov_json_formatter (v0.1.4, rbenv: 3.4.8) [gem]" level="application" />
69
+ <orderEntry type="library" scope="PROVIDED" name="stringio (v3.2.0, rbenv: 3.4.8) [gem]" level="application" />
70
+ <orderEntry type="library" scope="PROVIDED" name="tsort (v0.2.0, rbenv: 3.4.8) [gem]" level="application" />
71
+ <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v3.2.0, rbenv: 3.4.8) [gem]" level="application" />
72
+ <orderEntry type="library" scope="PROVIDED" name="unicode-emoji (v4.2.0, rbenv: 3.4.8) [gem]" level="application" />
73
+ <orderEntry type="library" scope="PROVIDED" name="uri (v1.1.1, rbenv: 3.4.8) [gem]" level="application" />
74
+ <orderEntry type="library" scope="PROVIDED" name="vcr (v6.4.0, rbenv: 3.4.8) [gem]" level="application" />
75
+ <orderEntry type="library" scope="PROVIDED" name="webmock (v3.26.2, rbenv: 3.4.8) [gem]" level="application" />
76
+ <orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.7.5, rbenv: 3.4.8) [gem]" level="application" />
77
+ </component>
78
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Ask2AgentMigrationStateService">
4
+ <option name="migrationStatus" value="COMPLETED" />
5
+ </component>
6
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/Feather.iml" filepath="$PROJECT_DIR$/.idea/Feather.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.2
3
+ NewCops: enable
4
+
5
+ plugins:
6
+ - rubocop-rspec
7
+
8
+ Style/StringLiterals:
9
+ EnforcedStyle: double_quotes
10
+
11
+ Style/StringLiteralsInInterpolation:
12
+ EnforcedStyle: double_quotes
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.8
data/CLAUDE.md ADDED
@@ -0,0 +1,87 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## What This Is
6
+
7
+ FeatherAi is a Ruby gem for identifying birds from photos and audio using RubyLLM. It adds multi-modal identification, location-aware results, multi-model consensus, and a Rails integration on top of RubyLLM.
8
+
9
+ ## Commands
10
+
11
+ ```bash
12
+ # Install dependencies
13
+ bin/setup
14
+
15
+ # Run all tests
16
+ bundle exec rspec
17
+
18
+ # Run a single test file
19
+ bundle exec rspec spec/feather_ai/identifier_spec.rb
20
+
21
+ # Run a single example by line number
22
+ bundle exec rspec spec/feather_ai/identifier_spec.rb:15
23
+
24
+ # Lint
25
+ bundle exec rubocop
26
+
27
+ # Lint with auto-fix
28
+ bundle exec rubocop -A
29
+
30
+ # Run tests + lint (default rake task, same as CI)
31
+ bundle exec rake
32
+
33
+ # Interactive console with gem loaded
34
+ bin/console
35
+
36
+ # Build and install locally
37
+ bundle exec rake install
38
+
39
+ # Release (tags, pushes, publishes to RubyGems)
40
+ bundle exec rake release
41
+ ```
42
+
43
+ ## Architecture
44
+
45
+ The gem's only runtime dependency is `ruby_llm`. All classes live under the `FeatherAi` module in `lib/feather_ai/`.
46
+
47
+ ### Data Flow
48
+
49
+ `FeatherAi.identify(image, audio, location:, consensus:)` is the top-level entry point defined in `lib/feather_ai.rb`. It delegates to:
50
+
51
+ 1. **Identifier** (`lib/feather_ai/identifier.rb`) — Core identification logic. Uses RubyLLM's vision for images and `RubyLLM.transcribe` for audio. When both inputs are provided, they're combined into a single multi-modal prompt. Uses `RubyLLM::Schema` for structured output so results are always clean `Result` objects, not raw LLM prose.
52
+
53
+ 2. **Consensus** (`lib/feather_ai/consensus.rb`) — When `consensus: true`, runs identification through two configurable models independently. If they agree on species, returns `confident: true`. If they disagree, returns both as `candidates` with uncertain confidence.
54
+
55
+ 3. **Result** (`lib/feather_ai/result.rb`) — Immutable value object wrapping all identification output. Exposes `common_name`, `species`, `family`, `confidence` (`:high`/`:medium`/`:low`), `confident?`, `region_native?`, `candidates`, `photography_tips`, and `to_h`. Photography tips are lazy-loaded via a second cheap LLM call only when accessed.
56
+
57
+ 4. **PhotographyTips** (`lib/feather_ai/photography_tips.rb`) — Separate LLM call (small model) returning structured shooting advice for the identified species. Only invoked when `result.photography_tips` is called.
58
+
59
+ ### Configuration
60
+
61
+ ```ruby
62
+ FeatherAi.configure do |c|
63
+ c.provider = :anthropic
64
+ c.location = "Perth, Western Australia" # biases results to local species
65
+ c.model = "claude-sonnet-4"
66
+ end
67
+ ```
68
+
69
+ Location can be set globally or per-call via `location:` keyword. It's injected into the system prompt to reduce false positives.
70
+
71
+ ### Rails Integration
72
+
73
+ `lib/feather_ai/rails/` contains a Railtie and `acts_as_sighting` mixin. When included in an ActiveRecord model, it expects `photo` (ActiveStorage) and `location` (string) attributes, and adds an `identify!` method that populates species fields on the record. A generator (`bin/rails generate feather_ai:install`) scaffolds the migration.
74
+
75
+ ## Code Style
76
+
77
+ - Double quotes for all strings (configured in `.rubocop.yml`)
78
+ - `frozen_string_literal: true` in every Ruby file
79
+ - Target Ruby version: >= 3.2 (gemspec requires it; CI tests 3.2, 3.3, 3.4)
80
+ - RSpec with `expect` syntax only (monkey patching disabled)
81
+
82
+ ## Testing
83
+
84
+ - Tests use VCR + WebMock to record/replay real LLM responses — no API keys needed in CI
85
+ - Sample bird images (WA birds) live in `spec/support/fixtures/`
86
+ - SimpleCov for coverage reporting
87
+ - Dev test dependencies go in the `Gemfile`, not the gemspec
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Brandyn Britton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,205 @@
1
+ # FeatherAi
2
+
3
+ A Ruby gem for identifying birds from photos and audio using [RubyLLM](https://github.com/coelacanth/ruby_llm). FeatherAi adds multi-modal identification, location-aware results, multi-model consensus, and a Rails integration on top of RubyLLM.
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ ```ruby
10
+ gem "feather-ai"
11
+ ```
12
+
13
+ Or install directly:
14
+
15
+ ```bash
16
+ gem install feather-ai
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ ```ruby
22
+ FeatherAi.configure do |c|
23
+ c.provider = :anthropic # Default: :anthropic
24
+ c.model = "claude-sonnet-4" # Default: "claude-sonnet-4"
25
+ c.location = "Perth, WA" # Optional: biases results to local species
26
+ c.consensus_models = ["claude-sonnet-4", "claude-haiku-4"] # Models used in consensus mode
27
+ end
28
+ ```
29
+
30
+ RubyLLM must be configured with your provider credentials before using FeatherAi. See the [RubyLLM docs](https://github.com/coelacanth/ruby_llm) for setup.
31
+
32
+ ## Usage
33
+
34
+ ### Basic Identification
35
+
36
+ Identify a bird from an image:
37
+
38
+ ```ruby
39
+ result = FeatherAi.identify("path/to/bird.jpg")
40
+
41
+ result.common_name # => "Western Magpie"
42
+ result.species # => "Gymnorhina tibicen"
43
+ result.family # => "Artamidae"
44
+ result.confidence # => :high
45
+ result.confident? # => true
46
+ result.region_native? # => true
47
+ ```
48
+
49
+ Identify from audio:
50
+
51
+ ```ruby
52
+ result = FeatherAi.identify(nil, "path/to/bird_call.mp3")
53
+ ```
54
+
55
+ Identify from both image and audio:
56
+
57
+ ```ruby
58
+ result = FeatherAi.identify("path/to/bird.jpg", "path/to/bird_call.mp3")
59
+ ```
60
+
61
+ ### Location-Aware Results
62
+
63
+ Pass a location to bias the model toward species native to that region:
64
+
65
+ ```ruby
66
+ result = FeatherAi.identify("path/to/bird.jpg", location: "Perth, Western Australia")
67
+
68
+ result.region_native? # => true/false based on species range
69
+ ```
70
+
71
+ A default location can also be set globally in configuration.
72
+
73
+ ### Consensus Mode
74
+
75
+ Run identification through two models independently. When both agree on species, you get high confidence. When they disagree, you get the candidates:
76
+
77
+ ```ruby
78
+ result = FeatherAi.identify("path/to/bird.jpg", consensus: true)
79
+
80
+ if result.confident?
81
+ puts "Both models agree: #{result.species}"
82
+ else
83
+ puts "Models disagree:"
84
+ result.candidates.each { |c| puts " #{c.common_name} (#{c.species})" }
85
+ end
86
+ ```
87
+
88
+ Consensus models are configurable:
89
+
90
+ ```ruby
91
+ FeatherAi.configure do |c|
92
+ c.consensus_models = ["claude-sonnet-4", "claude-haiku-4"]
93
+ end
94
+ ```
95
+
96
+ ### Photography Tips
97
+
98
+ Results expose lazy-loaded photography tips for the identified species. The tips are only fetched (via a fast, cheap model) when you access them:
99
+
100
+ ```ruby
101
+ tips = result.photography_tips
102
+
103
+ tips[:time_of_day] # => "Early morning or late afternoon for soft light"
104
+ tips[:approach] # => "Move slowly and quietly, approach from below sight line"
105
+ tips[:settings] # => "1/500s or faster, f/2.8-f/4, ISO 400-1600"
106
+ tips[:habitat] # => "Open woodlands, grasslands, and suburban parks"
107
+ ```
108
+
109
+ ### Result Object
110
+
111
+ All identification calls return a `FeatherAi::Result`:
112
+
113
+ | Method | Type | Description |
114
+ |---|---|---|
115
+ | `common_name` | String | Common name (e.g. "Western Magpie") |
116
+ | `species` | String | Scientific name (e.g. "Gymnorhina tibicen") |
117
+ | `family` | String | Bird family (e.g. "Artamidae") |
118
+ | `confidence` | Symbol | `:high`, `:medium`, or `:low` |
119
+ | `confident?` | Boolean | `true` when confidence is `:high` |
120
+ | `region_native?` | Boolean | Whether species is native to the given region |
121
+ | `candidates` | Array | Alternative results when consensus disagrees |
122
+ | `photography_tips` | Hash | Lazy-loaded shooting advice |
123
+ | `to_h` | Hash | All fields as a plain hash |
124
+
125
+ ## Rails Integration
126
+
127
+ ### Setup
128
+
129
+ Run the install generator to scaffold the migration:
130
+
131
+ ```bash
132
+ rails generate feather_ai:install
133
+ # or with a custom model name:
134
+ rails generate feather_ai:install observation
135
+ ```
136
+
137
+ Run the migration:
138
+
139
+ ```bash
140
+ rails db:migrate
141
+ ```
142
+
143
+ ### Model
144
+
145
+ Add `acts_as_sighting` to your ActiveRecord model. The model must have a `photo` attribute (ActiveStorage) and a `location` string column:
146
+
147
+ ```ruby
148
+ class Sighting < ApplicationRecord
149
+ has_one_attached :photo
150
+ acts_as_sighting
151
+ end
152
+ ```
153
+
154
+ The generator adds these columns to the model's table: `common_name`, `species`, `family`, `confidence`, `region_native`.
155
+
156
+ ### Identifying Records
157
+
158
+ Call `identify!` on any instance to run identification and persist the results:
159
+
160
+ ```ruby
161
+ sighting = Sighting.create!(photo: params[:photo], location: "Perth, WA")
162
+ result = sighting.identify!
163
+
164
+ sighting.common_name # => "Western Magpie"
165
+ sighting.species # => "Gymnorhina tibicen"
166
+ sighting.confident? # => true (delegated through result)
167
+ ```
168
+
169
+ `identify!` downloads the attached photo, calls `FeatherAi.identify`, updates the record's identification columns, and returns the `FeatherAi::Result`.
170
+
171
+ ## Development
172
+
173
+ ```bash
174
+ bin/setup # Install dependencies
175
+ bundle exec rspec # Run tests
176
+ bundle exec rubocop # Lint
177
+ bundle exec rake # Tests + lint (same as CI)
178
+ bin/console # Interactive console with gem loaded
179
+ ```
180
+
181
+ Tests use VCR + WebMock to record and replay LLM responses — no API keys are required to run the test suite.
182
+
183
+ ## Thread Safety
184
+
185
+ `FeatherAi.configuration` is a process-level singleton initialised lazily with `||=`. Under MRI Ruby, the Global VM Lock (GVL) makes this safe in practice. If you use JRuby or Ractors, initialise configuration eagerly at boot time before spawning threads:
186
+
187
+ ```ruby
188
+ # In an initialiser or boot file — before any threads are created
189
+ FeatherAi.configure do |c|
190
+ c.provider = :anthropic
191
+ c.model = "claude-sonnet-4"
192
+ end
193
+ ```
194
+
195
+ `FeatherAi.identify` is stateless per-call — each invocation constructs its own `Identifier` or `Consensus` instance and `RubyLLM::Chat` session. Concurrent calls are safe.
196
+
197
+ `FeatherAi::Consensus` parallelises model calls using Ruby threads (`Thread.new`), so two LLM requests run concurrently and the total wall-clock time is roughly that of the slower model, not the sum of both.
198
+
199
+ ## Contributing
200
+
201
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Birdup-Australia/Feather.
202
+
203
+ ## License
204
+
205
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FeatherAi
4
+ # Configuration object for FeatherAi gem settings.
5
+ class Configuration
6
+ attr_accessor :provider, :model, :location, :consensus_models, :tips_model
7
+
8
+ def initialize
9
+ @provider = :anthropic
10
+ @model = "claude-sonnet-4"
11
+ @location = nil
12
+ @consensus_models = %w[claude-sonnet-4 claude-haiku-4]
13
+ @tips_model = "claude-haiku-4"
14
+ end
15
+
16
+ def initialize_copy(source)
17
+ super
18
+ @consensus_models = source.consensus_models.dup
19
+ end
20
+ end
21
+ end