Skip to content

Commit

Permalink
Use rubocop-basic
Browse files Browse the repository at this point in the history
  • Loading branch information
ksylvest committed Jan 18, 2025
1 parent eb26f77 commit 5a51582
Show file tree
Hide file tree
Showing 49 changed files with 845 additions and 857 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ commands:
rm ./cc
orbs:
ruby: circleci/ruby@2.1.3
ruby: circleci/ruby@2.3.1

executors:
default:
docker:
- image: cimg/ruby:3.3.5
- image: cimg/ruby:3.4.1

jobs:
doc:
Expand Down
21 changes: 3 additions & 18 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
inherit_gem:
rubocop-basic: rubocop.yml

require:
- rubocop-rake
- rubocop-rspec

AllCops:
NewCops: enable

RSpec/NestedGroups:
Enabled: false

Expand All @@ -13,15 +13,6 @@ RSpec/SpecFilePathFormat:
OmniAI: omniai
OpenAI: openai

Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Metrics/ClassLength:
Enabled: false

Expand All @@ -30,9 +21,3 @@ Metrics/MethodLength:

Metrics/ParameterLists:
Enabled: false

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.5
3.4.1
21 changes: 11 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

gem 'rake'
gem 'rspec'
gem 'rspec_junit_formatter'
gem 'rubocop'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'simplecov'
gem 'webmock'
gem 'yard'
gem "rake"
gem "rspec"
gem "rspec_junit_formatter"
gem "rubocop"
gem "rubocop-basic"
gem "rubocop-rake"
gem "rubocop-rspec"
gem "simplecov"
gem "webmock"
gem "yard"
44 changes: 23 additions & 21 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
omniai-openai (1.9.1)
omniai-openai (1.9.2)
event_stream_parser
omniai
zeitwerk
Expand All @@ -13,57 +13,57 @@ GEM
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
bigdecimal (3.1.9)
crack (1.0.0)
bigdecimal
rexml
diff-lcs (1.5.1)
docile (1.4.1)
domain_name (0.6.20240107)
event_stream_parser (1.0.0)
ffi (1.17.0)
ffi (1.17.0-aarch64-linux-gnu)
ffi (1.17.0-aarch64-linux-musl)
ffi (1.17.0-arm-linux-gnu)
ffi (1.17.0-arm-linux-musl)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86-linux-gnu)
ffi (1.17.0-x86-linux-musl)
ffi (1.17.0-x86_64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
ffi (1.17.0-x86_64-linux-musl)
ffi (1.17.1)
ffi (1.17.1-aarch64-linux-gnu)
ffi (1.17.1-aarch64-linux-musl)
ffi (1.17.1-arm-linux-gnu)
ffi (1.17.1-arm-linux-musl)
ffi (1.17.1-arm64-darwin)
ffi (1.17.1-x86-linux-gnu)
ffi (1.17.1-x86-linux-musl)
ffi (1.17.1-x86_64-darwin)
ffi (1.17.1-x86_64-linux-gnu)
ffi (1.17.1-x86_64-linux-musl)
ffi-compiler (1.3.2)
ffi (>= 1.15.5)
rake
hashdiff (1.1.1)
hashdiff (1.1.2)
http (5.2.0)
addressable (~> 2.8)
base64 (~> 0.1)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
llhttp-ffi (~> 0.5.0)
http-cookie (1.0.7)
http-cookie (1.0.8)
domain_name (~> 0.5)
http-form_data (2.3.0)
json (2.9.1)
language_server-protocol (3.17.0.3)
llhttp-ffi (0.5.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
omniai (1.9.2)
omniai (1.9.3)
event_stream_parser
http
zeitwerk
parallel (1.26.3)
parser (3.3.6.0)
parser (3.3.7.0)
ast (~> 2.4.1)
racc
public_suffix (6.0.1)
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.10.0)
rexml (3.3.9)
rexml (3.4.0)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand All @@ -76,7 +76,7 @@ GEM
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rspec-support (3.13.2)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.70.0)
Expand All @@ -91,6 +91,7 @@ GEM
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.37.0)
parser (>= 3.3.1.0)
rubocop-basic (0.2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (3.3.0)
Expand All @@ -102,7 +103,7 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
unicode-display_width (3.1.3)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
webmock (3.24.0)
Expand Down Expand Up @@ -131,11 +132,12 @@ DEPENDENCIES
rspec
rspec_junit_formatter
rubocop
rubocop-basic
rubocop-rake
rubocop-rspec
simplecov
webmock
yard

BUNDLED WITH
2.5.21
2.6.3
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

require 'rubocop/rake_task'
require "rubocop/rake_task"

RuboCop::RakeTask.new

Expand Down
8 changes: 4 additions & 4 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'omniai/openai'
require "bundler/setup"
require "omniai/openai"

require 'logger'
require "logger"

CLIENT = OmniAI::OpenAI::Client.new(logger: Logger.new($stdout))

require 'irb'
require "irb"
IRB.start(__FILE__)
28 changes: 14 additions & 14 deletions examples/chat
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'omniai/openai'
require "bundler/setup"
require "omniai/openai"

CLIENT = OmniAI::OpenAI::Client.new

TOOL = OmniAI::Tool.new(
proc { |location:, unit: 'celsius'| "#{rand(20..50)}° #{unit} in #{location}" },
name: 'Weather',
description: 'Lookup the weather in a location',
proc { |location:, unit: "celsius"| "#{rand(20..50)}° #{unit} in #{location}" },
name: "Weather",
description: "Lookup the weather in a location",
parameters: OmniAI::Tool::Parameters.new(
properties: {
location: OmniAI::Tool::Property.string(description: 'e.g. Toronto'),
location: OmniAI::Tool::Property.string(description: "e.g. Toronto"),
unit: OmniAI::Tool::Property.string(enum: %w[celcius farenheit]),
},
required: %i[location]
)
)

def example1(stream: $stdout)
stream.puts '> [USER] Tell me a joke'
response = CLIENT.chat('Tell me a joke')
stream.puts "> [USER] Tell me a joke"
response = CLIENT.chat("Tell me a joke")
stream.puts response.text
end

def example2(stream: $stdout)
stream.puts '> [SYSTEM] Respond in both English and French.'
stream.puts '> [USER] What is the fastest animal?'
stream.puts "> [SYSTEM] Respond in both English and French."
stream.puts "> [USER] What is the fastest animal?"
CLIENT.chat(stream:) do |prompt|
prompt.system 'Respond in both English and French.'
prompt.user 'What is the fastest animal?'
prompt.system "Respond in both English and French."
prompt.user "What is the fastest animal?"
end
end

def example3(stream: $stdout)
stream.puts '> [SYSTEM] You are an expert in weather.'
stream.puts "> [SYSTEM] You are an expert in weather."
stream.puts '> [USER] What is the weather in "London" in celsius and "Madrid" in fahrenheit?'
response = CLIENT.chat(tools: [TOOL]) do |prompt|
prompt.system 'You are an expert in weather.'
prompt.system "You are an expert in weather."
prompt.user 'What is the weather in "London" in celsius and "Madrid" in fahrenheit?'
end
stream.puts response.text
Expand Down
8 changes: 4 additions & 4 deletions lib/omniai/openai.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require 'event_stream_parser'
require 'omniai'
require 'zeitwerk'
require "event_stream_parser"
require "omniai"
require "zeitwerk"

loader = Zeitwerk::Loader.for_gem
loader.push_dir(__dir__, namespace: OmniAI)
loader.inflector.inflect 'openai' => 'OpenAI'
loader.inflector.inflect "openai" => "OpenAI"
loader.setup

module OmniAI
Expand Down
40 changes: 20 additions & 20 deletions lib/omniai/openai/assistant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module OmniAI
module OpenAI
# An OpenAI assistants implementation.
class Assistant
HEADERS = { 'OpenAI-Beta': 'assistants=v2' }.freeze
HEADERS = { "OpenAI-Beta": "assistants=v2" }.freeze

# @!attribute [rw] id
# @return [String, nil]
Expand Down Expand Up @@ -95,7 +95,7 @@ def self.all(limit: nil, client: Client.new)

raise HTTPError, response.flush unless response.status.ok?

response.parse['data'].map { |data| parse(data:, client:) }
response.parse["data"].map { |data| parse(data:, client:) }
end

# @param id [String] required
Expand Down Expand Up @@ -128,45 +128,45 @@ def save!
# @raise [OmniAI::Error]
# @return [OmniAI::OpenAI::Assistant]
def destroy!
raise OmniAI::Error, 'cannot destroy a non-persisted assistant' unless @id
raise OmniAI::Error, "cannot destroy a non-persisted assistant" unless @id

data = self.class.destroy!(id: @id, client: @client)
@deleted = data['deleted']
@deleted = data["deleted"]
self
end

private
private

class << self
private
private

# @param data [Hash] required
# @param client [OmniAI::OpenAI::Client] required
# @return [OmniAI::OpenAI::Assistant]
def parse(data:, client: Client.new)
new(
client:,
id: data['id'],
name: data['name'],
model: data['model'],
description: data['description'],
instructions: data['instructions'],
metadata: data['metadata'],
tools: data['tools']
id: data["id"],
name: data["name"],
model: data["model"],
description: data["description"],
instructions: data["instructions"],
metadata: data["metadata"],
tools: data["tools"]
)
end
end

# @param data [Hash] required
# @return [OmniAI::OpenAI::Assistant]
def parse(data:)
@id = data['id']
@name = data['name']
@model = data['model']
@description = data['description']
@instructions = data['instructions']
@metadata = data['metadata']
@tools = data['tools']
@id = data["id"]
@name = data["name"]
@model = data["model"]
@description = data["description"]
@instructions = data["instructions"]
@metadata = data["metadata"]
@tools = data["tools"]
end

# @return [Hash]
Expand Down
Loading

0 comments on commit 5a51582

Please sign in to comment.