foobara-anthropic-api 1.0.7 → 1.1.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 +4 -4
- data/lib/foobara/anthropic_api.rb +1 -1
- data/src/create_message.rb +59 -0
- data/src/get_model.rb +31 -0
- data/src/{foobara/ai/anthropic_api/types → types}/message_result.rb +3 -1
- data/src/{foobara/ai/anthropic_api/types → types}/model_enum.rb +1 -0
- metadata +15 -14
- data/src/foobara/ai/anthropic_api/create_message.rb +0 -40
- /data/src/{foobara/ai/anthropic_api.rb → anthropic_api.rb} +0 -0
- /data/src/{foobara/ai/anthropic_api/base_command.rb → base_command.rb} +0 -0
- /data/src/{foobara/ai/anthropic_api/get_page_of_models.rb → get_page_of_models.rb} +0 -0
- /data/src/{foobara/ai/anthropic_api/list_models.rb → list_models.rb} +0 -0
- /data/src/{foobara/ai/anthropic_api/types → types}/message.rb +0 -0
- /data/src/{foobara/ai/anthropic_api/types → types}/message_result/content.rb +0 -0
- /data/src/{foobara/ai/anthropic_api/types → types}/message_result/usage.rb +0 -0
- /data/src/{foobara/ai/anthropic_api/types → types}/model.rb +0 -0
- /data/src/{foobara/ai/anthropic_api/types → types}/page_of_models.rb +0 -0
- /data/src/{foobara/ai/anthropic_api/types → types}/role.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 035ce75a8e886f9915e02247e1c5353c8b6b0ce39d48e50420b1b502617c5683
|
|
4
|
+
data.tar.gz: 061bd3fbcd6aaf34e7af8bc159f6b3cee5616b178fa4636c6f8d53936502a2d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a3ea40b32ff300ad9081f618806325443c0693fa47c5fa82a1a4191f41e5b9487826d7969a3a0b3ee6a7e8e93c65c9c1f5cb50ed30b4c8a972f1ab2173a75bd8
|
|
7
|
+
data.tar.gz: 1e100cf3f5117f604f3cc3a4b3b205250edaf5465d46895f52467808025c6ec589c08b75db7a5d26b0353025bb87a87749d367ad1eb117ec3df571c5961d62da
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require_relative "get_model"
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module Ai
|
|
5
|
+
module AnthropicApi
|
|
6
|
+
class CreateMessage < BaseCommand
|
|
7
|
+
path "/messages"
|
|
8
|
+
http_method :post
|
|
9
|
+
|
|
10
|
+
add_inputs do
|
|
11
|
+
system :string
|
|
12
|
+
max_tokens :integer, :allow_nil, "nil means whatever the max allowed is.", default: nil
|
|
13
|
+
model :model_enum, default: AnthropicApi.default_llm_model
|
|
14
|
+
messages [Types::Message]
|
|
15
|
+
# TODO: maybe this shouldn't be supported here?? It's not really part of this API.
|
|
16
|
+
# Maybe relocate this to Foobara::Ai instead.
|
|
17
|
+
fail_if_hitting_token_limit :boolean, default: false
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
result Types::MessageResult
|
|
21
|
+
|
|
22
|
+
possible_error :hit_token_limit, context: { model: :model_enum, max_tokens: :integer }
|
|
23
|
+
|
|
24
|
+
depends_on GetModel
|
|
25
|
+
|
|
26
|
+
def build_request_body
|
|
27
|
+
body = { model:, max_tokens:, messages: }
|
|
28
|
+
|
|
29
|
+
sys = inputs[:system]
|
|
30
|
+
if sys
|
|
31
|
+
body[:system] = sys
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
self.request_body = body
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def max_tokens
|
|
38
|
+
@max_tokens ||= inputs[:max_tokens] ||
|
|
39
|
+
run_subcommand!(GetModel, model:).max_tokens ||
|
|
40
|
+
64_000
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def build_result
|
|
44
|
+
message_result = Types::MessageResult.new(
|
|
45
|
+
response_body,
|
|
46
|
+
# Set this to false to discover new attributes
|
|
47
|
+
ignore_unexpected_attributes: true
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if fail_if_hitting_token_limit && message_result.hit_max_tokens?
|
|
51
|
+
add_runtime_error(:hit_token_limit, model:, max_tokens:)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
message_result
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
data/src/get_model.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require_relative "base_command"
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module Ai
|
|
5
|
+
module AnthropicApi
|
|
6
|
+
class GetModel < BaseCommand
|
|
7
|
+
include CachedCommand
|
|
8
|
+
|
|
9
|
+
self.foobara_cache_expiry = 24 * 60 * 60
|
|
10
|
+
|
|
11
|
+
def foobara_cache_key
|
|
12
|
+
@foobara_cache_key ||= [Util.underscore(self.class.name), model].join("-")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
path { "/models/#{model}" }
|
|
16
|
+
|
|
17
|
+
add_inputs do
|
|
18
|
+
model :model_enum, :required
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
result Types::Model
|
|
22
|
+
|
|
23
|
+
def build_result
|
|
24
|
+
Types::Model.new(response_body,
|
|
25
|
+
# Set this to false to discover new attributes
|
|
26
|
+
ignore_unexpected_attributes: true)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -7,6 +7,7 @@ module Foobara
|
|
|
7
7
|
model_list = ListModels.run!.map(&:id).sort
|
|
8
8
|
ModelEnum = Foobara::Enumerated.make_module(model_list)
|
|
9
9
|
|
|
10
|
+
# TODO: change all 3 projects to use :symbol instead of :string
|
|
10
11
|
AnthropicApi.foobara_register_type(:model_enum, :string, one_of: ModelEnum)
|
|
11
12
|
end
|
|
12
13
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foobara-anthropic-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Miles Georgi
|
|
@@ -65,19 +65,20 @@ extra_rdoc_files: []
|
|
|
65
65
|
files:
|
|
66
66
|
- LICENSE.txt
|
|
67
67
|
- lib/foobara/anthropic_api.rb
|
|
68
|
-
- src/
|
|
69
|
-
- src/
|
|
70
|
-
- src/
|
|
71
|
-
- src/
|
|
72
|
-
- src/
|
|
73
|
-
- src/
|
|
74
|
-
- src/
|
|
75
|
-
- src/
|
|
76
|
-
- src/
|
|
77
|
-
- src/
|
|
78
|
-
- src/
|
|
79
|
-
- src/
|
|
80
|
-
- src/
|
|
68
|
+
- src/anthropic_api.rb
|
|
69
|
+
- src/base_command.rb
|
|
70
|
+
- src/create_message.rb
|
|
71
|
+
- src/get_model.rb
|
|
72
|
+
- src/get_page_of_models.rb
|
|
73
|
+
- src/list_models.rb
|
|
74
|
+
- src/types/message.rb
|
|
75
|
+
- src/types/message_result.rb
|
|
76
|
+
- src/types/message_result/content.rb
|
|
77
|
+
- src/types/message_result/usage.rb
|
|
78
|
+
- src/types/model.rb
|
|
79
|
+
- src/types/model_enum.rb
|
|
80
|
+
- src/types/page_of_models.rb
|
|
81
|
+
- src/types/role.rb
|
|
81
82
|
homepage: https://github.com/foobara/anthropic-api
|
|
82
83
|
licenses:
|
|
83
84
|
- None specified yet
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require_relative "base_command"
|
|
2
|
-
|
|
3
|
-
module Foobara
|
|
4
|
-
module Ai
|
|
5
|
-
module AnthropicApi
|
|
6
|
-
class CreateMessage < BaseCommand
|
|
7
|
-
path "/messages"
|
|
8
|
-
http_method :post
|
|
9
|
-
|
|
10
|
-
add_inputs do
|
|
11
|
-
system :string
|
|
12
|
-
max_tokens :integer, default: 1024
|
|
13
|
-
model :model_enum, default: AnthropicApi.default_llm_model
|
|
14
|
-
messages [Types::Message]
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
result Types::MessageResult
|
|
18
|
-
|
|
19
|
-
def build_request_body
|
|
20
|
-
body = { model:, max_tokens:, messages: }
|
|
21
|
-
|
|
22
|
-
sys = inputs[:system]
|
|
23
|
-
if sys
|
|
24
|
-
body[:system] = sys
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
self.request_body = body
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def build_result
|
|
31
|
-
Types::MessageResult.new(
|
|
32
|
-
response_body,
|
|
33
|
-
# Set this to false to discover new attributes
|
|
34
|
-
ignore_unexpected_attributes: true
|
|
35
|
-
)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|