senior 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 448f1287d6404de5d6a2168f69b2517605310f99865992d7e4db5ffee9fc538a
4
- data.tar.gz: f7d0392887141cd1ee232438483cebc274a6b39607d81c93a5b9033312c62415
3
+ metadata.gz: 3d973cd43135daeb4de71d71a43f52500fe6ab39f6ba507b032833eb65402977
4
+ data.tar.gz: 4bf83499dae649941e881453fd376603faad6399fa49970b1375a843af0a987f
5
5
  SHA512:
6
- metadata.gz: be9c24e647fe23cbb5e5e8580d775ab0822672856b2bc4f1bc0567a61ad9677e455b08e73aad7e95f51a1a3835809abd640220fcb6c8c249f6276376f5203021
7
- data.tar.gz: 8210280b84ae3c47b5442a1a7ae8b6cdf23cd9bdc7b255701d8b6808f7864267e855bc730b424e567abd44d5de8607f7a324256ef5e1762b9a3c92599be81b2d
6
+ metadata.gz: 9d6394a7b1b08fd32299b43febd26143128befb958f1af203106ce05c8e809ec07a3cdd7eec1cc16b0e1ddc369b2f94873b1e9addb91a9b8385231990dcd929f
7
+ data.tar.gz: 6655e71e4676e35cae26aedd96bce779202a33982d028a68f8cdb1ef257ae1fcae1b86755b8c11c70d6c70cfd7dff900da2fc74d4d9d6ba4e456209c84740228
data/CHANGELOG.md CHANGED
@@ -10,6 +10,18 @@
10
10
  - RBS Signatures
11
11
  - Domain exceptions
12
12
 
13
+ ## [0.3.0] - 2023-04-11
14
+
15
+ ### Added
16
+ - Added support for OpenAI's Chat Completion API. Setting `Senior.configuration.open_ai.model`
17
+ to any value of `Senior::Brains::OpenAI::CHAT_MODELS` will cause API requests to be sent to `/chat/completions`.
18
+ Whereas setting `Senior.configuration.open_ai.model` to any value of `Senior::Brains::OpenAI::COMPLETION_MODELS`
19
+ will cause API requests to be sent to `/completions`.
20
+
21
+ ### Changed
22
+ - Updated the gem's summary and description to match the idea of the gem - A senior software engineer assistant.
23
+ - Updated the `bin/setup` script to copy the `.env.example` file to `.env`
24
+
13
25
  ## [0.2.0] - 2023-04-10
14
26
 
15
27
  ### Added
@@ -33,5 +45,6 @@ These configurations are used as default values for the OpenAI API calls.
33
45
 
34
46
  - Initial release
35
47
 
48
+ [0.3.0]: https://github.com/wilsonsilva/senior/compare/v0.2.0...v0.3.0
36
49
  [0.2.0]: https://github.com/wilsonsilva/senior/compare/v0.1.0...v0.2.0
37
50
  [0.1.0]: https://github.com/wilsonsilva/senior/compare/eecec20...v0.1.0
data/README.md CHANGED
@@ -5,8 +5,9 @@
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/87e6e2167d3283e3b79b/test_coverage)](https://codeclimate.com/github/wilsonsilva/senior/test_coverage)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/87e6e2167d3283e3b79b/maintainability)](https://codeclimate.com/github/wilsonsilva/senior/maintainability)
7
7
 
8
- Provides AI-powered debugging and automatic suggestion of code fixes. It makes use of OpenAI's language model to analyze
9
- and modify the source code of broken methods, allowing them to be fixed automatically.
8
+ An AI-powered pair programmer. Provides a user-friendly interface for using AI API's to automatically repair broken code
9
+ and suggest improvements. Simply provide the faulty code as input, and the gem will generate a corrected version using
10
+ advanced machine learning techniques.
10
11
 
11
12
  ## Table of Contents
12
13
 
@@ -48,12 +49,11 @@ environment. You should never hardcode your API credentials directly in your cod
48
49
  Instead, store your API credentials securely, such as using environment variables or a separate configuration file that
49
50
  is excluded from source control.
50
51
 
51
- Once you have configured the library, you can use the Senior module to interact with the OpenAI API.
52
+ Once you have configured the gem, you can use the `Senior` module to interact with the OpenAI API.
52
53
 
53
54
  ### Auto-debugging a broken method
54
- To debug a broken method, call Senior.auto_debug and pass in the broken method, its arguments, and optionally its
55
- source code. The method will be called repeatedly, with modifications made to its source code each time, until it no
56
- longer raises exceptions.
55
+ To debug a broken method, call `Senior.auto_debug` and pass in the broken method and its arguments. The method will be
56
+ called repeatedly, with modifications made to its source code each time, until it no longer raises exceptions.
57
57
 
58
58
  ```ruby
59
59
  def square(n) = n * y
@@ -63,7 +63,7 @@ puts result # => 4
63
63
  ```
64
64
 
65
65
  ### Suggesting a fix for a broken method
66
- To suggest a fix for a broken method, call Senior.suggest_fix and pass in the broken method and its arguments.
66
+ To suggest a fix for a broken method, call `Senior.suggest_fix` and pass in the broken method and its arguments.
67
67
  The method will be analyzed and a fix will be suggested in the form of modified source code.
68
68
 
69
69
  ```ruby
@@ -77,6 +77,9 @@ puts suggestion # => "def square(n) = n * n"
77
77
 
78
78
  After checking out the repo, run `bin/setup` to install dependencies.
79
79
 
80
+ Set your OpenAI API credentials in the environment variables `OPEN_AI_ACCESS_TOKEN` and `OPEN_AI_ORGANIZATION_ID`.
81
+ Either in your machine's environment or in a `.env` file in the root of the project.
82
+
80
83
  To install this gem onto your local machine, run `bundle exec rake install`.
81
84
 
82
85
  You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -10,6 +10,11 @@ module Senior
10
10
  # @api private
11
11
  #
12
12
  class OpenAI
13
+ CHAT_MODELS = %w[gpt-4 gpt-4-0314 gpt-4-32k gpt-4-32k-0314 gpt-3.5-turbo gpt-3.5-turbo-0301].freeze
14
+ COMPLETION_MODELS = %w[text-davinci-003 text-davinci-002 text-curie-001 text-babbage-001 text-ada-001
15
+ davinci curie babbage ada].freeze
16
+ CHAT_SYSTEM_PROMPT = "You're a Ruby dev. Only reply with plain code, no explanations."
17
+
13
18
  # Suggests a fix for a broken method
14
19
  #
15
20
  # @api private
@@ -32,7 +37,13 @@ module Senior
32
37
  ## Updated source:
33
38
  PROMPT
34
39
 
35
- request_completion(prompt)
40
+ if CHAT_MODELS.include?(defaults.model)
41
+ request_chat_completion(prompt)
42
+ elsif COMPLETION_MODELS.include?(defaults.model)
43
+ request_completion(prompt)
44
+ else
45
+ raise "Unknown model '#{defaults.model}'. If this is a mistake, open a PR in github.com/wilsonsilva/senior"
46
+ end
36
47
  end
37
48
 
38
49
  private
@@ -56,7 +67,7 @@ module Senior
56
67
  #
57
68
  # @param prompt [String] The prompt for which to generate a completion
58
69
  #
59
- # @return [String] The create completion
70
+ # @return [String] The created completion
60
71
  #
61
72
  def request_completion(prompt)
62
73
  response = open_ai_client.completions(
@@ -75,6 +86,33 @@ module Senior
75
86
  response.dig('choices', 0, 'text').strip
76
87
  end
77
88
 
89
+ # Creates a chat completion in OpenAI's API
90
+ #
91
+ # @api private
92
+ #
93
+ # @param prompt [String] The prompt for which to generate a chat completion
94
+ #
95
+ # @return [String] The created chat completion
96
+ #
97
+ def request_chat_completion(prompt)
98
+ response = open_ai_client.chat(
99
+ parameters: {
100
+ model: defaults.model,
101
+ max_tokens: defaults.max_tokens,
102
+ n: defaults.n,
103
+ temperature: defaults.temperature,
104
+ messages: [
105
+ { role: 'system', content: CHAT_SYSTEM_PROMPT },
106
+ { role: 'user', content: prompt }
107
+ ]
108
+ }
109
+ )
110
+
111
+ raise 'No chat completion found' unless response['choices'].any?
112
+
113
+ response.dig('choices', 0, 'message', 'content').strip
114
+ end
115
+
78
116
  # Returns the default configuration object for the OpenAI brain
79
117
  #
80
118
  # @api private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Senior
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -1,6 +1,10 @@
1
1
  module Senior
2
2
  module Brains
3
3
  class OpenAI
4
+ CHAT_MODELS: Array[String]
5
+ COMPLETION_MODELS: Array[String]
6
+ CHAT_SYSTEM_PROMPT: String
7
+
4
8
  @open_ai_client: untyped
5
9
 
6
10
  def suggest_fix: (erroneous_source: String, exception_backtrace: String) -> String
@@ -9,6 +13,7 @@ module Senior
9
13
 
10
14
  def open_ai_client: -> untyped
11
15
  def request_completion: (String prompt) -> String
16
+ def request_chat_completion: (String prompt) -> String
12
17
  def defaults: -> Senior::Configuration::OpenAI
13
18
  end
14
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: senior
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilson Silva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-10 00:00:00.000000000 Z
11
+ date: 2023-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source
@@ -361,8 +361,9 @@ dependencies:
361
361
  - !ruby/object:Gem::Version
362
362
  version: '0.9'
363
363
  description: |-
364
- This gem provides a simple interface to OpenAI's GPT API for code repair. Given a piece of broken
365
- code, the gem generates a corrected version.
364
+ An AI-powered pair programmer. Provides a user-friendly interface for using AI API's to
365
+ automatically repair broken code and suggest improvements. Simply provide the faulty code as input, and the gem will
366
+ generate a corrected version using advanced machine learning techniques.
366
367
  email:
367
368
  - wilson.dsigns@gmail.com
368
369
  executables: []
@@ -427,5 +428,5 @@ requirements: []
427
428
  rubygems_version: 3.4.10
428
429
  signing_key:
429
430
  specification_version: 4
430
- summary: AI coding companion
431
+ summary: An AI-powered pair programmer
431
432
  test_files: []