openai-mapper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5db92031ac3f71bfca308bfc4e6916ed84eba39dcaa6f0d16c8cad312aeceb88
4
+ data.tar.gz: f08ac67fb56a1e06064639bb03102f169b694cb9c9ccf9a6466f5a004b1434db
5
+ SHA512:
6
+ metadata.gz: 8ffd22700f1f0891e0de4777a98b5402693e95375759007d045b79a3d9bda3a51a16a1e13c027e8830bd183a39d581109ce44d5874d6fa41ce481e00f86a88ed
7
+ data.tar.gz: fdd64f89da5c42a7ed96c1680b52df31fe4cc5e770f077fb5b297b53249537363db4072d3608291a7e09141068f024f19c2fadfb333e6b11fca2d2a546299c58
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,83 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://docs.rubocop.org/rubocop/configuration
11
+
12
+
13
+ require:
14
+ - standard
15
+ - standard-performance
16
+ - rubocop
17
+ - rubocop-rspec
18
+ - rubocop-rake
19
+ - rubocop-performance
20
+ - rubocop-packs
21
+
22
+ inherit_gem:
23
+ standard: config/base.yml
24
+
25
+ AllCops:
26
+ Exclude:
27
+ - 'bin/bundle'
28
+ - '.git/**/*'
29
+ - '.git-hooks/**/*'
30
+ - vendor/**/*
31
+ TargetRubyVersion: 3.2
32
+ NewCops: enable
33
+
34
+
35
+ RSpec:
36
+ Enabled: true # enable rubocop-rspec cops
37
+
38
+ RSpec/DescribeClass:
39
+ Enabled: false # ignore missing comments on classes
40
+
41
+ # Bundler/DuplicatedGem:
42
+ # Enabled: false
43
+
44
+ Metrics/BlockLength:
45
+ Max: 250
46
+ Include:
47
+ - spec/**/*_spec.rb
48
+
49
+ Style/Documentation:
50
+ Enabled: false
51
+
52
+ RSpec/ExampleLength:
53
+ Max: 15
54
+ Include:
55
+ - spec/**/*_spec.rb
56
+
57
+ RSpec/MultipleExpectations:
58
+ Max: 5
59
+ Include:
60
+ - spec/requests/**/*_spec.rb
61
+
62
+ RSpec/PendingWithoutReason:
63
+ Enabled: false
64
+
65
+ Metrics/MethodLength:
66
+ Max: 15
67
+ Include:
68
+ - spec/**/*_spec.rb
69
+
70
+ Lint/ShadowedArgument:
71
+ Enabled: true
72
+ Exclude:
73
+ - app/models/google/file.rb
74
+
75
+ RSpec/VariableName:
76
+ Enabled: true
77
+ Exclude:
78
+ - spec/requests/**/*_spec.rb
79
+
80
+ Metrics/AbcSize:
81
+ Enabled: true
82
+ Exclude:
83
+ - app/views/layouts/*_layout.rb
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-08-11
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at s.bezugliy@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Openai::Mapper
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/openai/mapper`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/openai-mapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/openai-mapper/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## Code of Conduct
34
+
35
+ Everyone interacting in the Openai::Mapper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/openai-mapper/blob/main/CODE_OF_CONDUCT.md).
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,20 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ class Arguments
5
+ attr_accessor :mapper, :params, :body
6
+
7
+ def initialize(request_mapper, **params)
8
+ @mapper = request_mapper
9
+ @params = params
10
+ build_body
11
+ end
12
+
13
+ private
14
+
15
+ def build_body
16
+ @obj = @mapper.new(**@params)
17
+ @body = @obj.to_json
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Chat
5
+ class Completions < ::Openai::Resource::Api
6
+ def initialize
7
+ @path = "/v1/chat/completions"
8
+ super()
9
+ end
10
+
11
+ def request(params)
12
+ @response = @connection.post(
13
+ path: @path,
14
+ body: ::Openai::Request::Chat::Completion.new(**params).to_json
15
+ )
16
+ @data = ::Openai::Mapper::Chat::Completions.from_json(@response.body)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module File
5
+ class Create < ::Openai::Resource::Api
6
+ def request(request)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module FineTune
5
+ class Create < ::Openai::Resource::Api
6
+ def request(request)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Images
5
+ class Create < ::Openai::Resource::Api
6
+ def initialize
7
+ @path = "/v1/images/generations"
8
+ super()
9
+ end
10
+
11
+ def request(**request)
12
+ @response = @connection.post(
13
+ path: @path,
14
+ body: ::Openai::Request::Images::Create.new(**request).to_json
15
+ )
16
+ @data = ::Openai::Mapper::Images::List.from_json(@response.body)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,50 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Images
5
+ class Edit < ::Openai::Resource::Api
6
+ def initialize
7
+ @path = "/v1/images/edits"
8
+ @boundary = ::SecureRandom.hex(4)
9
+
10
+ super()
11
+ end
12
+
13
+ def request(**params)
14
+ @response = @connection.post(
15
+ path: @path,
16
+ headers: multipart_headers,
17
+ body: multipart_body(::Openai::Request::Images::Edit.new(**params))
18
+ ).tap { |r| puts r }
19
+ @data = ::Openai::Mapper::Images::List.from_json(@response.body)
20
+ end
21
+
22
+ private
23
+
24
+ def multipart_headers
25
+ {
26
+ "Content-Type" => %(multipart/form-data; boundary="#{@boundary}"),
27
+ "Authorization" => "Bearer #{ACCESS_TOKEN}"
28
+ }
29
+ end
30
+
31
+ def multipart_body(params)
32
+ body = ""
33
+ body << attach_image("image", "image.png", read_image(params.image))
34
+ body << attach_image("mask", "mask.png", read_image(params.mask)) if params.mask
35
+ body << multipart_fields(params)
36
+ body << "--#{@boundary}--#{Excon::CR_NL}"
37
+ body
38
+ end
39
+
40
+ def multipart_fields(params)
41
+ body = multipart_field("prompt", params.prompt)
42
+ body << multipart_field("n", params.n)
43
+ body << multipart_field("size", params.size)
44
+ body << multipart_field("response_format", params.response_format)
45
+ body << multipart_field("user", params.user)
46
+ body
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,25 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ module Chat
6
+ class CompletionChunk < ::Openai::Mapper::BaseMapper
7
+ attribute :id, ::Shale::Type::String
8
+ attribute :object, ::Shale::Type::String
9
+ attribute :created, ::Shale::Type::Time
10
+ attribute :model, ::Shale::Type::String
11
+ attribute :choices, ::Openai::Mapper::Choices, collection: true
12
+ attribute :usage, ::Openai::Mapper::Usage
13
+
14
+ json do
15
+ map "id", to: :id
16
+ map "object", to: :object
17
+ map "created", using: {from: :from_timestamp, to: :to_timestamp}
18
+ map "model", to: :model
19
+ map "choices", to: :choices
20
+ map "usage", to: :usage
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ module Chat
6
+ class Completions < ::Openai::Mapper::BaseMapper
7
+ attribute :id, ::Shale::Type::String
8
+ attribute :object, ::Shale::Type::String
9
+ attribute :created, ::Shale::Type::Time
10
+ attribute :model, ::Shale::Type::String
11
+ attribute :choices, ::Openai::Mapper::Choices, collection: true
12
+ attribute :usage, ::Openai::Mapper::Usage
13
+
14
+ json do
15
+ map "id", to: :id
16
+ map "object", to: :object
17
+ map "model", to: :model
18
+ map "choices", to: :choices
19
+ map "usage", to: :usage
20
+ map "created", using: {from: :from_timestamp, to: :to_timestamp}
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ class Choices < ::Openai::Mapper::BaseMapper
6
+ attribute :index, ::Shale::Type::Integer
7
+ attribute :finish_reason, ::Shale::Type::String
8
+ attribute :logprobs, ::Shale::Type::String, default: -> {}
9
+ attribute :delta, ::Openai::Mapper::Message, default: -> {}
10
+ attribute :text, ::Shale::Type::String, default: -> {}
11
+ attribute :message, ::Openai::Mapper::Message, default: -> {}
12
+
13
+ json do
14
+ map "index", to: :index
15
+ map "finish_reason", to: :finish_reason
16
+ map "delta", to: :object
17
+ map "message", to: :message
18
+ map "logprobs", to: :logprobs
19
+ map "text", to: :text
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ class File < ::Openai::Mapper::BaseMapper
6
+ end
7
+ end
8
+ end
9
+
10
+ # {
11
+ # "id": "file-abc123",
12
+ # "object": "file",
13
+ # "bytes": 120000,
14
+ # "created_at": 1677610602,
15
+ # "filename": "my_file.jsonl",
16
+ # "purpose": "fine-tune",
17
+ # "status": "uploaded",
18
+ # "status_details": null
19
+ # }
@@ -0,0 +1,15 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ class FunctionCall < ::Openai::Mapper::BaseMapper
6
+ attribute :name, ::Shale::Type::String, default: -> {}
7
+ attribute :arguments, ::Shale::Type::String, default: -> {}
8
+
9
+ json do
10
+ map "name", to: :name
11
+ map "arguments", to: :arguments
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ class Functions < ::Openai::Mapper::BaseMapper
6
+ attribute :name, ::Shale::Type::String, default: -> {}
7
+ attribute :parameters, ::Shale::Type::String, default: -> {}
8
+
9
+ json do
10
+ map "name", to: :name
11
+ map "parameters", to: :parameters
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ module Images
6
+ class Image < ::Openai::Mapper::BaseMapper
7
+ attribute :url, ::Shale::Type::String
8
+ attribute :b64_json, ::Shale::Type::String, default: -> {}
9
+
10
+ json do
11
+ map "url", to: :url
12
+ map "b64_json", to: :b64_json
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ module Images
6
+ class List < ::Openai::Mapper::BaseMapper
7
+ attribute :data, ::Openai::Mapper::Images::Image, collection: true
8
+ attribute :created, ::Shale::Type::Time
9
+
10
+ json do
11
+ map "data", to: :data
12
+ map "created", using: {from: :from_timestamp, to: :to_timestamp}
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ class Message < ::Openai::Mapper::BaseMapper
6
+ attribute :role, ::Shale::Type::String
7
+ attribute :content, ::Shale::Type::String, default: -> {}
8
+ attribute :function_call, ::Openai::Mapper::FunctionCall, default: -> {}
9
+
10
+ json do
11
+ map "role", to: :role
12
+ map "content", to: :content
13
+ map "function_call", to: :function_call
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ class Model < ::Openai::Mapper::BaseMapper
6
+ attribute :id, ::Shale::Type::String
7
+ attribute :object, ::Shale::Type::String
8
+ attribute :created, ::Shale::Type::Time
9
+ attribute :owned_by, ::Shale::Type::String
10
+ attribute :root, ::Shale::Type::String
11
+ attribute :parent, ::Shale::Type::String
12
+ attribute :permission, ::Openai::Mapper::ModelPermission, collection: true
13
+
14
+ json do
15
+ map "id", to: :id
16
+ map "object", to: :object
17
+ map "root", to: :root
18
+ map "parent", to: :parent
19
+ map "owned_by", to: :owned_by
20
+ map "permission", to: :permission
21
+
22
+ map "created", using: {from: :from_timestamp, to: :to_timestamp}
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ class ModelPermission < ::Openai::Mapper::BaseMapper
6
+ attribute :id, ::Shale::Type::String
7
+ attribute :object, ::Shale::Type::String
8
+ attribute :created, ::Shale::Type::Time
9
+ attribute :allow_create_engine, ::Shale::Type::Boolean
10
+ attribute :allow_sampling, ::Shale::Type::Boolean
11
+ attribute :allow_logprobs, ::Shale::Type::Boolean
12
+ attribute :allow_search_indices, ::Shale::Type::Boolean
13
+ attribute :allow_view, ::Shale::Type::Boolean
14
+ attribute :allow_fine_tuning, ::Shale::Type::Boolean
15
+ attribute :organisation, ::Shale::Type::String
16
+ attribute :group, ::Shale::Type::String
17
+ attribute :is_blocking, ::Shale::Type::Boolean
18
+
19
+ json do
20
+ map "id", to: :id
21
+ map "object", to: :object
22
+ map "allow_create_engine", to: :allow_create_engine
23
+ map "allow_sampling", to: :allow_sampling
24
+ map "allow_logprobs", to: :allow_logprobs
25
+ map "allow_search_indices", to: :allow_search_indices
26
+ map "allow_view", to: :allow_view
27
+ map "allow_fine_tuning", to: :allow_fine_tuning
28
+ map "organisation", to: :organisation
29
+ map "group", to: :group
30
+ map "is_blocking", to: :is_blocking
31
+ map "created", using: {from: :from_timestamp, to: :to_timestamp}
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ class Models < ::Openai::Mapper::BaseMapper
6
+ attribute :object, ::Shale::Type::String
7
+ attribute :data, ::Openai::Mapper::Model, collection: true
8
+
9
+ json do
10
+ map "object", to: :object
11
+ map "data", to: :data
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ class Usage < ::Openai::Mapper::BaseMapper
6
+ attribute :prompt_tokens, ::Shale::Type::Integer
7
+ attribute :completion_tokens, ::Shale::Type::Integer
8
+ attribute :total_tokens, ::Shale::Type::Integer
9
+
10
+ json do
11
+ map "prompt_tokens", to: :prompt_tokens
12
+ map "completion_tokens", to: :completion_tokens
13
+ map "total_tokens", to: :total_tokens
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # typed: false
2
+
3
+ module Openai
4
+ module Mapper
5
+ class BaseMapper < ::Shale::Mapper
6
+ def from_timestamp(model, value)
7
+ model.created = Time.at(value)
8
+ end
9
+
10
+ def to_timestamp(model, value)
11
+ # value['created'] = model.created.to_i
12
+ raise NotImplementedError
13
+ end
14
+ end
15
+ end
16
+ end