foobara-anthropic-api 0.0.5 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 397ca8262c02350325ef056b1515b62690470a725cd991221b7bab6cc85ee6df
4
- data.tar.gz: 5b077cc5e81663bb5c414fd121a87104527ae5918ffbbb1a8c7ca8495103c545
3
+ metadata.gz: 3a629bb7a306c6821ca14a1465cd815158560b6437ddec195e027e9a3f365fd6
4
+ data.tar.gz: 2bf5bae93564985de2d9ccd8732a6bbc0b5dea855087eb1e659a360b90e27d0b
5
5
  SHA512:
6
- metadata.gz: 22f52f6c00e4f81c0c709a39128189c98210f4f92745d430a1cf0057cfa34cdce6f9421e7e2580fb453323b03bf576a7cdc7b92092dc2f05ab037467bc71cc3b
7
- data.tar.gz: ece188c59cd4d84974ed4ce43e1f31098f6a1406f34de934cd6d3ddcdbfdac5e4b2b7425466e113c367617f78b46df63a3e30c1d1ba6298c8c8c7c95d6d33bae
6
+ metadata.gz: 199549653a34847e9093e917c274861b515f7de12a928d824ee96338a543e1a9ea4efef36c8a3532e237219fd771bb2c894cb939cae93dda6c827b1012cc8f6b
7
+ data.tar.gz: c07ada1b3ecc2d7f127554818d0a760876048cc34026b06bfb17d7ea4043211301b7215ca9e7c773d4706a950f42e4375572a0f8ad792573128418925a33c46b
@@ -4,6 +4,10 @@ module Foobara
4
4
  module Ai
5
5
  module AnthropicApi
6
6
  class BaseCommand < Foobara::Command
7
+ class << self
8
+ attr_accessor :api_token
9
+ end
10
+
7
11
  include HttpApiCommand
8
12
 
9
13
  base_url "https://api.anthropic.com/v1"
@@ -22,7 +26,11 @@ module Foobara
22
26
  end
23
27
 
24
28
  def api_token
25
- inputs[:api_token] || ENV.fetch("ANTHROPIC_API_KEY", nil)
29
+ inputs[:api_token] || BaseCommand.api_token || api_token_from_env
30
+ end
31
+
32
+ def api_token_from_env
33
+ ENV.fetch("ANTHROPIC_API_KEY", nil)
26
34
  end
27
35
 
28
36
  def anthropic_version
@@ -10,7 +10,7 @@ module Foobara
10
10
  add_inputs do
11
11
  system :string
12
12
  max_tokens :integer, default: 1024
13
- model :model, default: Types::ModelEnum::CLAUDE_3_5_SONNET
13
+ model :model, default: Types::ModelEnum::CLAUDE_3_5_SONNET_20241022
14
14
  messages [Types::Message]
15
15
  end
16
16
 
@@ -3,7 +3,7 @@ require_relative "base_command"
3
3
  module Foobara
4
4
  module Ai
5
5
  module AnthropicApi
6
- class ListModels < Foobara::Command
6
+ class ListModels < BaseCommand
7
7
  description "A convenience command that will repeatedly fetch pages of models until all are fetched"
8
8
 
9
9
  inputs do
@@ -2,12 +2,31 @@ module Foobara
2
2
  module Ai
3
3
  module AnthropicApi
4
4
  module Types
5
- module ModelEnum
6
- CLAUDE_3_5_SONNET = "claude-3-5-sonnet-20240620".freeze
7
- CLAUDE_3_OPUS = "claude-3-opus-20240229".freeze
8
- CLAUDE_3_SONNET = "claude-3-sonnet-20240229".freeze
9
- CLAUDE_3_HAIKU = "claude-3-haiku-20240307".freeze
10
- end
5
+ # Can grab an updated list by running something like:
6
+ #
7
+ # > require "foobara/anthropic_api"
8
+ # > Foobara::Ai::AnthropicApi.api_token = File.read("tokens/anthropic_token.txt") and nil
9
+ # > Foobara::Ai::AnthropicApi::ListModels.run!.map(&:id).sort
10
+ # => [
11
+ # "claude-2.0",
12
+ # "claude-2.1",
13
+ # "claude-3-5-haiku-20241022",
14
+ # "claude-3-5-sonnet-20240620",
15
+ # "claude-3-5-sonnet-20241022",
16
+ # "claude-3-haiku-20240307",
17
+ # "claude-3-opus-20240229",
18
+ # "claude-3-sonnet-20240229"
19
+ # ]
20
+ ModelEnum = Foobara::Enumerated.make_module(
21
+ "claude-2.0",
22
+ "claude-2.1",
23
+ "claude-3-5-haiku-20241022",
24
+ "claude-3-5-sonnet-20240620",
25
+ "claude-3-5-sonnet-20241022",
26
+ "claude-3-haiku-20240307",
27
+ "claude-3-opus-20240229",
28
+ "claude-3-sonnet-20240229"
29
+ )
11
30
 
12
31
  AnthropicApi.foobara_register_type(:model, :string, one_of: ModelEnum)
13
32
  end
@@ -7,6 +7,16 @@ module Foobara
7
7
 
8
8
  module AnthropicApi
9
9
  foobara_domain!
10
+
11
+ class << self
12
+ def api_token=(token)
13
+ BaseCommand.api_token = token
14
+ end
15
+
16
+ def api_token
17
+ BaseCommand.api_token
18
+ end
19
+ end
10
20
  end
11
21
  end
12
22
  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: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi