ai-chat 0.5.6 → 0.5.7
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/README.md +5 -3
- data/ai-chat.gemspec +1 -1
- data/lib/ai/chat.rb +14 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bdaa537e8986ff0070250da8e7c6cc0a2b39fccab163aa4f2c858b3217bb6da3
|
|
4
|
+
data.tar.gz: 6e2077b0e87d86968d43c57b0f5bae1db7341b9fa16aafc1652712b87b67c438
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 145f78aa4de9dd582d2772ab576c3bbe2c3a30623f6f8172eb2189edbdb198132778784855c498d7f28e0368f16ba8b5b1d7d258085b3c3645b833bd1fbaabd4
|
|
7
|
+
data.tar.gz: 48cfe57e2bffdcb039ce0177dd5961edba51f9df8e6c144bdcba8bea1dfc4902365fcfc43bb3cb6c76b11396c9e9e7383d0af327fe1ac82e3e08a45c15e84677
|
data/README.md
CHANGED
|
@@ -238,7 +238,7 @@ See [OpenAI's model documentation](https://platform.openai.com/docs/models) for
|
|
|
238
238
|
|
|
239
239
|
### API key
|
|
240
240
|
|
|
241
|
-
The gem by default looks for
|
|
241
|
+
The gem by default looks for `AICHAT_API_KEY` first. If that is missing (or empty), it falls back to `OPENAI_API_KEY`.
|
|
242
242
|
|
|
243
243
|
You can specify a different environment variable name:
|
|
244
244
|
|
|
@@ -404,7 +404,7 @@ AI::Chat.generate_schema!("A user profile with name (required), email (required)
|
|
|
404
404
|
|
|
405
405
|
This method returns a String containing the JSON schema. The JSON schema also writes (or overwrites) to `schema.json` at the root of the project.
|
|
406
406
|
|
|
407
|
-
Similar to generating messages with `AI::Chat` objects, this class method will
|
|
407
|
+
Similar to generating messages with `AI::Chat` objects, this class method will look for `AICHAT_API_KEY` first, then fall back to `OPENAI_API_KEY` if needed. You can also pass the API key directly or choose a different environment variable key for it to use.
|
|
408
408
|
|
|
409
409
|
```rb
|
|
410
410
|
# Passing the API key directly
|
|
@@ -748,7 +748,9 @@ This is particularly useful for background mode workflows. If you want to retrie
|
|
|
748
748
|
```ruby
|
|
749
749
|
require "openai"
|
|
750
750
|
|
|
751
|
-
|
|
751
|
+
api_key = ENV["AICHAT_API_KEY"]
|
|
752
|
+
api_key = ENV.fetch("OPENAI_API_KEY") if api_key.nil? || api_key.empty?
|
|
753
|
+
client = OpenAI::Client.new(api_key: api_key)
|
|
752
754
|
|
|
753
755
|
response_id = "resp_abc123..." # e.g., load from your database
|
|
754
756
|
response = client.responses.retrieve(response_id)
|
data/ai-chat.gemspec
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = "ai-chat"
|
|
5
|
-
spec.version = "0.5.
|
|
5
|
+
spec.version = "0.5.7"
|
|
6
6
|
spec.authors = ["Raghu Betina", "Jelani Woods"]
|
|
7
7
|
spec.email = ["raghu@firstdraft.com", "jelani@firstdraft.com"]
|
|
8
8
|
spec.homepage = "https://github.com/firstdraft/ai-chat"
|
data/lib/ai/chat.rb
CHANGED
|
@@ -23,8 +23,8 @@ module AI
|
|
|
23
23
|
|
|
24
24
|
BASE_PROXY_URL = "https://prepend.me/api.openai.com/v1"
|
|
25
25
|
|
|
26
|
-
def initialize(api_key: nil, api_key_env_var:
|
|
27
|
-
@api_key = api_key
|
|
26
|
+
def initialize(api_key: nil, api_key_env_var: nil)
|
|
27
|
+
@api_key = self.class.resolve_api_key(api_key: api_key, api_key_env_var: api_key_env_var)
|
|
28
28
|
@proxy = ENV["AICHAT_PROXY"] == "true"
|
|
29
29
|
@messages = []
|
|
30
30
|
@reasoning_effort = nil
|
|
@@ -39,8 +39,8 @@ module AI
|
|
|
39
39
|
@verbosity = :medium
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
def self.generate_schema!(description, location: "schema.json", api_key: nil, api_key_env_var:
|
|
43
|
-
api_key
|
|
42
|
+
def self.generate_schema!(description, location: "schema.json", api_key: nil, api_key_env_var: nil, proxy: nil)
|
|
43
|
+
api_key = resolve_api_key(api_key: api_key, api_key_env_var: api_key_env_var)
|
|
44
44
|
proxy = ENV["AICHAT_PROXY"] == "true" if proxy.nil?
|
|
45
45
|
prompt_path = File.expand_path("../prompts/schema_generator.md", __dir__)
|
|
46
46
|
system_prompt = File.read(prompt_path)
|
|
@@ -73,6 +73,16 @@ module AI
|
|
|
73
73
|
content
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
+
def self.resolve_api_key(api_key: nil, api_key_env_var: nil)
|
|
77
|
+
return api_key if api_key
|
|
78
|
+
return ENV.fetch(api_key_env_var) if api_key_env_var
|
|
79
|
+
|
|
80
|
+
aichat_api_key = ENV["AICHAT_API_KEY"]
|
|
81
|
+
return aichat_api_key if aichat_api_key && !aichat_api_key.empty?
|
|
82
|
+
|
|
83
|
+
ENV.fetch("OPENAI_API_KEY")
|
|
84
|
+
end
|
|
85
|
+
|
|
76
86
|
# :reek:TooManyStatements
|
|
77
87
|
# :reek:NilCheck
|
|
78
88
|
def add(content, role: "user", response: nil, status: nil, image: nil, images: nil, file: nil, files: nil)
|