newsman 0.1.13 → 0.1.14

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: e0b76df23c180a0cc0a30bdc4d60fd675ece0c5201605bcbdea44bd0a7d25bce
4
- data.tar.gz: 72e37a051f065fcc3a625ba3175439b1351e28acc6e0b2cc33a352c3f5dda652
3
+ metadata.gz: 5a68ba87116b71adc25a5983ee3b91cc94414b27edee46781fdec6141988a278
4
+ data.tar.gz: 02f0cb536bbe01e60578755227a0b0a03eed4c6086bceebcee399f6ae2a53aba
5
5
  SHA512:
6
- metadata.gz: e66602a260c38095c76e367b8a84f52f1f16bc6a74b103e3b0c0e6e8690e8bea1d1d54b41ca97cc0c259c55b571485e788864b3f788251730759ffd19ce356ec
7
- data.tar.gz: e4d0aef6d9a2958084402468adc84f2e24d8f7da507ea8a2dab7515f5855411f6e6a73e1969a4cc30f413e180eee2ceaab520c5addb7d59fa780090516dc7e76
6
+ metadata.gz: 6e247fd019a04cc39c3d9bb3e2bc0db202947941cad27e968501f9d355308ee4704b6f8c76267e1b2953f00996e15a2c5c6c5dd03e7712f93e400ab3fd3633e7
7
+ data.tar.gz: 2d416b5a3476432636e78fe08d18bc3480539ecaea6f896c757a99a85d11b0be47aa7459448c9b3a536f942828d6e2cf512a5cc5c6f1296248b03f33bae8f249
@@ -0,0 +1,149 @@
1
+ require 'openai'
2
+
3
+ class Assistant
4
+
5
+ CONTEXT = 'You are a developer tasked with composing a concise report detailing your activities and progress for the previous week, intended for submission to your supervisor.'
6
+
7
+ def initialize(token, model: 'gpt-3.5-turbo', temperature: 0.3)
8
+ @token = token
9
+ @model = model
10
+ @temperature = temperature
11
+ @client = OpenAI::Client.new(access_token: token)
12
+ end
13
+
14
+ def say_hello
15
+ "I'm an assistant that can work with OpenAI client. Please, use me, if you need any help. I'm using #{@model}, with #{@temperature} temperature."
16
+ end
17
+
18
+ def next_plans(issues)
19
+ example = "repository-name:\n
20
+ - To publish ABC package draft [#27]\n
21
+ - To review first draft of the report [#56]\n
22
+ - To implement optimization for the class X [#125]"
23
+ return send("Please compile a summary of the plans for the next week using the following GitHub Issues descriptions. Each issue should be summarized in a single sentence, focusing more on the issue title and less on implementation details. Pay attention, that you didn't loose any issue. Ensure that each sentence includes the corresponding issue number as an integer value. If an issue doesn't mention an issue number, just print [#chore]. Combine all the information from each Issue into a concise and fluent sentences, as if you were a developer reporting on your work. Please strictly adhere to the example template provided: ```#{example}```. List of GitHub issues to aggregate: [#{issues}].")
24
+ end
25
+
26
+ def prev_results(prs)
27
+ example = "repository-name:\n
28
+ - Added 100 new files to the Dataset [#168]\n
29
+ - Fixed the deployment of XYZ [#169]\n
30
+ - Refined the requirements [#177]\n"
31
+ return send("Please compile a summary of the work completed in the following Pull Requests (PRs). Each PR should be summarized in a single sentence, focusing more on the PR title and less on implementation details. Pay attention, that you don't lose any PR. Ensure that each sentence includes the corresponding issue number as an integer value. If a PR doesn't mention an issue number, just print [#chore]. Combine all the information from each PR into a concise and fluent sentence, as if you were a developer reporting on your work. Please strictly adhere to the example template provided: ```#{example}```. List of Pull Requests: [#{prs}]")
32
+ end
33
+
34
+ def risks(all)
35
+ example = "repository-name:\n
36
+ - The server is weak, we may fail the delivery\n
37
+ of the dataset, report milestone will be missed [#487].\n
38
+ - The code in repository is suboptimal, we might have some problems for the future maintainability [#44].\n"
39
+ return send("Please compile a summary of the risks identified in the repository. If you can't find anything, just answer 'No risks identified'. Developers usually mention some risks in pull request descriptions. They either mention 'risk' or 'issue'. I will give you a list of pull requests. Each risk should be summarized in a single sentence. Ensure that each sentence includes the corresponding PR number as an integer value. If a PR doesn't mention an issue number, just print [#chore]. Combine all the information from each PR into a concise and fluent sentence, as if you were a developer reporting on your work. Please strictly adhere to the example template provided: ```#{example}```. List of Pull Requests: [#{all}]")
40
+ end
41
+
42
+ def old_prev_results(prs)
43
+ deprecated(__method__)
44
+ example = "some-repository-name-x:
45
+ - Added 100 new files to the Dataset [#168]
46
+ - Fixed the deployment of XYZ [#169]
47
+ - Refined the requirements [#177]
48
+ some-repository-name-y:
49
+ - Removed XYZ class [#57]
50
+ - Refactored http module [#69]"
51
+ response = @client.chat(
52
+ parameters: {
53
+ model: 'gpt-3.5-turbo',
54
+ messages: [
55
+ { role: 'system',
56
+ content: 'You are a developer tasked with composing a concise report detailing your activities and progress for the previous week, intended for submission to your supervisor.' },
57
+ { role: 'user',
58
+ content: "Please compile a summary of the work completed in the following Pull Requests (PRs). Each PR should be summarized in a single sentence, focusing more on the PR title and less on implementation details. Group the sentences by repositories, each identified by its name mentioned in the 'repository:[name]' attribute of the PR. Pay attention, that you don't lose any PR. The grouping is important an should be precise. Ensure that each sentence includes the corresponding issue number as an integer value. If a PR doesn't mention an issue number, just print [#chore]. Combine all the information from each PR into a concise and fluent sentence, as if you were a developer reporting on your work. Please strictly adhere to the example template provided. Example of a report: #{example}. List of Pull Requests: [#{prs}]" }
59
+ ],
60
+ temperature: 0.3
61
+ }
62
+ )
63
+ answer = response.dig('choices', 0, 'message', 'content')
64
+ return answer
65
+ end
66
+
67
+ def old_next_plans(issues)
68
+ deprecated(__method__)
69
+ example_plans = "some-repository-name-x:
70
+ - To publish ABC package draft [#27]
71
+ - To review first draft of the report [#56]
72
+ some-repository-name-y:
73
+ - To implement optimization for the class X [#125]"
74
+ issues_response = @client.chat(
75
+ parameters: {
76
+ model: 'gpt-3.5-turbo',
77
+ messages: [
78
+ { role: 'system',
79
+ content: 'You are a developer tasked with composing a concise report detailing your activities and progress for the previous week, intended for submission to your supervisor.' },
80
+ { role: 'user',
81
+ content: "Please compile a summary of the plans for the next week using the following GitHub Issues descriptions. Each issue should be summarized in a single sentence, focusing more on the issue title and less on implementation details. Group the sentences by repositories, each identified by its name mentioned in the 'repository:[name]' attribute of the issue. Pat attention, that you din't loose any issue. The grouping is important an should be precise. Ensure that each sentence includes the corresponding issue number as an integer value. If an issue doesn't mention an issue number, just print [#chore]. Combine all the information from each Issue into a concise and fluent sentences, as if you were a developer reporting on your work. Please strictly adhere to the example template provided: #{example_plans}. List of GitHub issues to aggregate: [#{issues}]." }
82
+ ],
83
+ temperature: 0.3
84
+ }
85
+ )
86
+ issues_full_answer = issues_response.dig('choices', 0, 'message', 'content')
87
+ return issues_full_answer
88
+ end
89
+
90
+ def old_risks(all)
91
+ deprecated(__method__)
92
+ example_risks = "some-repository-name-x:
93
+ - The server is weak, we may fail the delivery
94
+ of the dataset, report milestone will be missed [#487].
95
+ some-repository-name-y:
96
+ - The code in repository is suboptimal, we might have some problems for the future maintainability [#44]."
97
+ return @client.chat(
98
+ parameters: {
99
+ model: 'gpt-3.5-turbo',
100
+ messages: [
101
+ { role: 'system',
102
+ content: 'You are a developer tasked with composing a concise report detailing your activities and progress for the previous week, intended for submission to your supervisor.' },
103
+ { role: 'user',
104
+ content: "Please compile a summary of the risks identified in some repositories. If you can't find anything, just leave answer empty. Add some entries to a report only if you are sure it's a risk. Developers usually mention some risks in pull request descriptions. They either mention 'risk' or 'issue'. I will give you a list of pull requests. Each risk should be summarized in a single sentence. Ensure that each sentence includes the corresponding issue number or PR number as an integer value. If a PR or an issue doesn't mention an issue number, just print [#chore]. Combine all the information from each PR into a concise and fluent sentence, as if you were a developer reporting on your work. Please strictly adhere to the example template provided. Example of a report: #{example_risks}. List of Pull Requests: ```#{all}```.]" }
105
+ ],
106
+ temperature: 0.3
107
+ }
108
+ ).dig('choices', 0, 'message', 'content')
109
+ end
110
+
111
+ def send(request)
112
+ return @client.chat(
113
+ parameters: {
114
+ model: @model,
115
+ messages: [
116
+ { role: 'system',
117
+ content: CONTEXT },
118
+ { role: 'user',
119
+ content: "#{request}" }
120
+ ],
121
+ temperature: @temperature
122
+ }
123
+ ).dig('choices', 0, 'message', 'content')
124
+ end
125
+
126
+ def deprecated(method)
127
+ warn "Warning! '#{method}' is deprecated and will be removed in future versions."
128
+ end
129
+
130
+ def send(request)
131
+ return @client.chat(
132
+ parameters: {
133
+ model: @model,
134
+ messages: [
135
+ { role: 'system',
136
+ content: CONTEXT },
137
+ { role: 'user',
138
+ content: "#{request}" }
139
+ ],
140
+ temperature: @temperature
141
+ }
142
+ ).dig('choices', 0, 'message', 'content')
143
+ end
144
+
145
+ def deprecated(method)
146
+ warn "Warning! '#{method}' is deprecated and will be removed in future versions."
147
+ end
148
+
149
+ end
@@ -26,6 +26,8 @@ class Issue
26
26
  end
27
27
 
28
28
  class PddIssue
29
+ attr_accessor :repo
30
+
29
31
  def initialize(title, body, repo, number, url: 'undefined')
30
32
  @title = title
31
33
  @body = body
data/lib/newsman.rb CHANGED
@@ -11,6 +11,7 @@ require_relative 'newsman/stdout_output'
11
11
  require_relative 'newsman/txt_output'
12
12
  require_relative 'newsman/html_output'
13
13
  require_relative 'newsman/report'
14
+ require_relative 'newsman/assistant'
14
15
 
15
16
  def generate
16
17
  # Load all options required
@@ -96,6 +97,7 @@ def generate
96
97
  end
97
98
  raw_prs = prs
98
99
  prs = prs.map(&:to_s).join("\n\n\n")
100
+ grouped_prs = raw_prs.group_by { |pr| pr.repository }
99
101
 
100
102
  puts "Searching issues using the following query: '#{issues_query}'"
101
103
  issues = []
@@ -113,76 +115,50 @@ def generate
113
115
  end
114
116
  raw_issues = issues
115
117
  issues = issues.map(&:to_s).join("\n\n\n")
116
- # puts "Found issues:\n #{issues}"
118
+ grouped_issues = raw_issues.group_by { |iss| iss.repo }
117
119
 
118
120
  puts "\nNow lets test some aggregation using OpenAI\n\n"
119
121
  openai_client = OpenAI::Client.new(access_token: openai_token)
122
+
123
+ assistant = Assistant.new(openai_token)
124
+
125
+ old_way = false
126
+ if old_way
127
+ answer = assistant.old_prev_results(prs)
128
+ issues_full_answer = assistant.old_next_plans(issues)
129
+ risks_full_answer = assistant.old_risks(prs)
130
+ else
131
+ puts "Assistant builds a report using a new approach, using groupping"
132
+ # Build previous results
133
+ answer = ""
134
+ grouped_prs.each do |repository, rprs|
135
+ puts "Building a results report for the repository: #{repository}"
136
+ answer = answer + assistant.prev_results(rprs.map(&:to_s).join("\n\n\n"))
137
+ end
138
+ # Build next plans
139
+ issues_full_answer = ""
140
+ grouped_issues.each do |repository, rissues|
141
+ puts "Building a future plans report for the repository: #{repository}"
142
+ issues_full_answer = issues_full_answer + assistant.next_plans(rissues.map(&:to_s).join("\n\n\n"))
143
+ end
144
+ # Find risks
145
+ risks_full_answer = assistant.risks(prs)
146
+ end
120
147
 
121
- example = "some-repository-name-x:
122
- - Added 100 new files to the Dataset [#168]
123
- - Fixed the deployment of XYZ [#169]
124
- - Refined the requirements [#177]
125
- some-repository-name-y:
126
- - Removed XYZ class [#57]
127
- - Refactored http module [#69]"
128
-
129
- example_plans = "some-repository-name-x:
130
- - To publish ABC package draft [#27]
131
- - To review first draft of the report [#56]
132
- some-repository-name-y:
133
- - To implement optimization for the class X [#125]"
134
-
135
- example_risks = "some-repository-name-x:
136
- - The server is weak, we may fail the delivery
137
- of the dataset, report milestone will be missed [#487].
138
- some-repository-name-y:
139
- - The code in repository is suboptimal, we might have some problems for the future maintainability [#44].
140
- "
141
-
142
- response = openai_client.chat(
143
- parameters: {
144
- model: 'gpt-3.5-turbo',
145
- messages: [
146
- { role: 'system',
147
- content: 'You are a developer tasked with composing a concise report detailing your activities and progress for the previous week, intended for submission to your supervisor.' },
148
- { role: 'user',
149
- content: "Please compile a summary of the work completed in the following Pull Requests (PRs). Each PR should be summarized in a single sentence, focusing more on the PR title and less on implementation details. Group the sentences by repositories, each identified by its name mentioned in the 'repository:[name]' attribute of the PR. Pay attention, that you don't lose any PR. The grouping is important an should be precise. Ensure that each sentence includes the corresponding issue number as an integer value. If a PR doesn't mention an issue number, just print [#chore]. Combine all the information from each PR into a concise and fluent sentence, as if you were a developer reporting on your work. Please strictly adhere to the example template provided. Example of a report: #{example}. List of Pull Requests: [#{prs}]" }
150
- ],
151
- temperature: 0.3
152
- }
148
+ full_answer = Report.new(
149
+ reporter,
150
+ reporter_position,
151
+ options[:title],
152
+ additional: ReportItems.new(raw_prs, raw_issues)
153
+ ).build(
154
+ answer,
155
+ issues_full_answer,
156
+ risks_full_answer,
157
+ Date.today
153
158
  )
154
- answer = response.dig('choices', 0, 'message', 'content')
155
- issues_response = openai_client.chat(
156
- parameters: {
157
- model: 'gpt-3.5-turbo',
158
- messages: [
159
- { role: 'system',
160
- content: 'You are a developer tasked with composing a concise report detailing your activities and progress for the previous week, intended for submission to your supervisor.' },
161
- { role: 'user',
162
- content: "Please compile a summary of the plans for the next week using the following GitHub Issues descriptions. Each issue should be summarized in a single sentence, focusing more on the issue title and less on implementation details. Group the sentences by repositories, each identified by its name mentioned in the 'repository:[name]' attribute of the issue. Pat attention, that you din't loose any issue. The grouping is important an should be precise. Ensure that each sentence includes the corresponding issue number as an integer value. If an issue doesn't mention an issue number, just print [#chore]. Combine all the information from each Issue into a concise and fluent sentences, as if you were a developer reporting on your work. Please strictly adhere to the example template provided: #{example_plans}. List of GitHub issues to aggregate: [#{issues}]. Use the same formatting as here \n```#{answer}```\n" }
163
- ],
164
- temperature: 0.3
165
- }
166
- )
167
- issues_full_answer = issues_response.dig('choices', 0, 'message', 'content')
168
-
169
- risks_full_answer = openai_client.chat(
170
- parameters: {
171
- model: 'gpt-3.5-turbo',
172
- messages: [
173
- { role: 'system',
174
- content: 'You are a developer tasked with composing a concise report detailing your activities and progress for the previous week, intended for submission to your supervisor.' },
175
- { role: 'user',
176
- content: "Please compile a summary of the risks identified in some repositories. If you can't find anything, just leave answer empty. Add some entries to a report only if you are sure it's a risk. Developers usually mention some risks in pull request descriptions. They either mention 'risk' or 'issue'. I will give you a list of pull requests. Each risk should be summarized in a single sentence. Ensure that each sentence includes the corresponding issue number or PR number as an integer value. If a PR or an issue doesn't mention an issue number, just print [#chore]. Combine all the information from each PR into a concise and fluent sentence, as if you were a developer reporting on your work. Please strictly adhere to the example template provided. Example of a report: #{example_risks}. List of Pull Requests: ```#{prs}```.]" }
177
- ],
178
- temperature: 0.3
179
- }
180
- ).dig('choices', 0, 'message', 'content')
181
159
 
182
160
  output_mode = options[:output]
183
161
  puts "Output mode is '#{output_mode}'"
184
- full_answer = Report.new(reporter, reporter_position, options[:title], additional: ReportItems.new(raw_prs, raw_issues)).build(answer, issues_full_answer,
185
- risks_full_answer, Date.today)
186
162
  if output_mode.eql? 'txt'
187
163
  puts 'Print result to txy file'
188
164
  output = Txtout.new('.')
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright (c) 2024 Volodya Lombrozo
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'minitest/autorun'
25
+ require_relative '../lib/newsman/assistant'
26
+
27
+ class TestAssistant < Minitest::Test
28
+ def test_creates_default_assistant
29
+ assistant = Assistant::new('test-token');
30
+ assert_equal "I'm an assistant that can work with OpenAI client. Please, use me, if you need any help. I'm using gpt-3.5-turbo, with 0.3 temperature.", assistant.say_hello
31
+ end
32
+ end
33
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newsman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volodya Lombrozo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-22 00:00:00.000000000 Z
11
+ date: 2024-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -163,12 +163,14 @@ files:
163
163
  - README.md
164
164
  - bin/newsman
165
165
  - lib/newsman.rb
166
+ - lib/newsman/assistant.rb
166
167
  - lib/newsman/html_output.rb
167
168
  - lib/newsman/issues.rb
168
169
  - lib/newsman/pull_request.rb
169
170
  - lib/newsman/report.rb
170
171
  - lib/newsman/stdout_output.rb
171
172
  - lib/newsman/txt_output.rb
173
+ - test/test_assistant.rb
172
174
  - test/test_htmlout.rb
173
175
  - test/test_pdd_issue.rb
174
176
  - test/test_report.rb