foobara-open-ai-api 0.0.8 → 0.0.10

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: b1134ded66f3c63f8f0def005ed37383f5c69522899e51fe3316dce02c1210f8
4
- data.tar.gz: 0170e54de38d1b4ac99b8d7c110d67ce67dbb2da53bebca8fdf94dda7c0f0027
3
+ metadata.gz: c561a0e79f029a99ffad41fe5c090ddfab2c7e008c7fd0f16b6d21e4d7901085
4
+ data.tar.gz: 284fdd95baef9a2bdbd33fd89aeed1dc1644017a93d36e5045ce17cb58c471f6
5
5
  SHA512:
6
- metadata.gz: be8f41c655f0a08a2c3b44a2c13ad9f5bf2f39fb055b2119b537a3459e344fb476bb672087e2887ae5e3d779bca81b93b0f9a2c0771a56f98b24a72fe26c8f9f
7
- data.tar.gz: 2f091240994a101906585d51cd6915d0153dd7d2eb1f011f63d6cfa8f7e8593144be01ce1877ca47e8096870eef4b91cfa31a8966d617a8d24fce695d0675b39
6
+ metadata.gz: 1e7bd6525404df690f81f902e01bc7e611e23ff5ba71b5d61df07a3743239effb8ae7a96438a52463ef89bee7e3afa6c1941846d66574342b039e996c2e5ea78
7
+ data.tar.gz: 4a13093a70ab33d82a6e2854c622fc2ebae81e447f17c0532251ef84ad5dcfda1ef1e6997e3e5ebd21d14a940749fcbc0b3365b4eb19d74d9145530b64e013ca
data/CHANGELOG.md CHANGED
@@ -1,9 +1,14 @@
1
- ## [0.0.7] - 2025-02-17
1
+ ## [0.0.9] - 2025-02-18
2
+
3
+ - Add a ModelEnum
4
+
5
+ ## [0.0.8] - 2025-02-17
2
6
 
3
7
  - Add support for some newly added fields
4
8
  - Make sure our models don't break when OpenAI adds new attributes to their responses
5
9
  before we have a chance to update them
6
10
  - Implement ListModels
11
+ - Provide a way to set api token on project module
7
12
 
8
13
  ## [0.0.6] - 2025-02-16
9
14
 
@@ -1,4 +1,5 @@
1
- # TODO: consider moving this to src/ and deleting lib/
2
1
  require "foobara/all"
3
2
 
3
+ require_relative "../../src/foobara/ai/open_ai_api"
4
+
4
5
  Foobara::Util.require_directory "#{__dir__}/../../src"
@@ -4,18 +4,24 @@ module Foobara
4
4
  module Ai
5
5
  module OpenAiApi
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.openai.com/v1"
10
14
 
11
15
  inputs do
12
- # TODO: come up with some kind of execution context object to wrap all of these calls upon which
13
- # data wrapping a "request" can live instead of being passed around?
14
16
  api_token :string
15
17
  end
16
18
 
17
19
  def api_token
18
- inputs[:api_token] || ENV.fetch("OPENAI_API_KEY", nil)
20
+ inputs[:api_token] || BaseCommand.api_token || api_token_from_env
21
+ end
22
+
23
+ def api_token_from_env
24
+ ENV.fetch("OPENAI_API_KEY", nil)
19
25
  end
20
26
 
21
27
  def build_request_headers
@@ -8,7 +8,7 @@ module Foobara
8
8
  http_method :post
9
9
 
10
10
  add_inputs do
11
- model :string, default: "gpt-3.5-turbo", one_of: %w[gpt-3.5-turbo gpt-4]
11
+ model :model, default: Types::ModelEnum::GPT_3_5_TURBO
12
12
  messages :array do
13
13
  role :string, one_of: %w[system user assistant]
14
14
  content :string
@@ -0,0 +1,73 @@
1
+ module Foobara
2
+ module Ai
3
+ module OpenAiApi
4
+ module Types
5
+ # Can grab an updated list by running something like:
6
+ #
7
+ # irb(main):001> require "foobara/open_ai_api"
8
+ # irb(main):002> Foobara::Ai::OpenAiApi.api_token = File.read("tokens/open_ai_token.txt") and nil
9
+ # irb(main):003> Foobara::Ai::OpenAiApi::ListModels.run!.map(&:id).sort
10
+ # =>
11
+ # ["babbage-002",
12
+ # "chatgpt-4o-latest",
13
+ # "dall-e-2",
14
+ # "dall-e-3",
15
+ # "davinci-002",
16
+ # "gpt-3.5-turbo",
17
+ # ...
18
+ ModelEnum = Foobara::Enumerated.make_module(
19
+ "babbage-002",
20
+ "chatgpt-4o-latest",
21
+ "dall-e-2",
22
+ "dall-e-3",
23
+ "davinci-002",
24
+ "gpt-3.5-turbo",
25
+ "gpt-3.5-turbo-0125",
26
+ "gpt-3.5-turbo-1106",
27
+ "gpt-3.5-turbo-16k",
28
+ "gpt-3.5-turbo-instruct",
29
+ "gpt-3.5-turbo-instruct-0914",
30
+ "gpt-4",
31
+ "gpt-4-0125-preview",
32
+ "gpt-4-0613",
33
+ "gpt-4-1106-preview",
34
+ "gpt-4-turbo",
35
+ "gpt-4-turbo-2024-04-09",
36
+ "gpt-4-turbo-preview",
37
+ "gpt-4o",
38
+ "gpt-4o-2024-05-13",
39
+ "gpt-4o-2024-08-06",
40
+ "gpt-4o-2024-11-20",
41
+ "gpt-4o-audio-preview",
42
+ "gpt-4o-audio-preview-2024-10-01",
43
+ "gpt-4o-audio-preview-2024-12-17",
44
+ "gpt-4o-mini",
45
+ "gpt-4o-mini-2024-07-18",
46
+ "gpt-4o-mini-audio-preview",
47
+ "gpt-4o-mini-audio-preview-2024-12-17",
48
+ "gpt-4o-mini-realtime-preview",
49
+ "gpt-4o-mini-realtime-preview-2024-12-17",
50
+ "gpt-4o-realtime-preview",
51
+ "gpt-4o-realtime-preview-2024-10-01",
52
+ "gpt-4o-realtime-preview-2024-12-17",
53
+ "o1-mini",
54
+ "o1-mini-2024-09-12",
55
+ "o1-preview",
56
+ "o1-preview-2024-09-12",
57
+ "omni-moderation-2024-09-26",
58
+ "omni-moderation-latest",
59
+ "text-embedding-3-large",
60
+ "text-embedding-3-small",
61
+ "text-embedding-ada-002",
62
+ "tts-1",
63
+ "tts-1-1106",
64
+ "tts-1-hd",
65
+ "tts-1-hd-1106",
66
+ "whisper-1"
67
+ )
68
+
69
+ OpenAiApi.foobara_register_type(:model, :string, one_of: ModelEnum)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -5,6 +5,16 @@ module Foobara
5
5
  module Ai
6
6
  module OpenAiApi
7
7
  foobara_domain!
8
+
9
+ class << self
10
+ def api_token=(token)
11
+ BaseCommand.api_token = token
12
+ end
13
+
14
+ def api_token
15
+ BaseCommand.api_token
16
+ end
17
+ end
8
18
  end
9
19
  end
10
20
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-open-ai-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-17 00:00:00.000000000 Z
10
+ date: 2025-02-18 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara-http-api-command
@@ -44,6 +44,7 @@ files:
44
44
  - src/foobara/ai/open_ai_api/types/chat_completion/message.rb
45
45
  - src/foobara/ai/open_ai_api/types/chat_completion/usage.rb
46
46
  - src/foobara/ai/open_ai_api/types/model.rb
47
+ - src/foobara/ai/open_ai_api/types/model_enum.rb
47
48
  homepage: https://github.com/foobara/open-ai-api
48
49
  licenses:
49
50
  - Apache-2.0