Class: Assistant

Inherits:
Object
  • Object
show all
Defined in:
lib/newsman/assistant.rb

Overview

This class mimics a robot that can analyse a developer activity. The assistant uses OpenAI API to analyze.

Constant Summary collapse

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.'

Instance Method Summary collapse

Constructor Details

#initialize(token, model: 'gpt-3.5-turbo', temperature: 0.3) ⇒ Assistant

Returns a new instance of Assistant.



33
34
35
36
37
38
# File 'lib/newsman/assistant.rb', line 33

def initialize(token, model: 'gpt-3.5-turbo', temperature: 0.3)
  @token = token
  @model = model
  @temperature = temperature
  @client = OpenAI::Client.new(access_token: token)
end

Instance Method Details

#deprecated(method) ⇒ Object



133
134
135
# File 'lib/newsman/assistant.rb', line 133

def deprecated(method)
  warn "Warning! '#{method}' is deprecated and will be removed in future versions."
end

#format(report) ⇒ Object

rubocop:enable Metrics/MethodLength



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/newsman/assistant.rb', line 107

def format(report)
  prompt = <<~PROMPT
    I have a weekly report with different parts that use various formatting styles.
    Please format the entire report into a single cohesive format while preserving the original text without any changes.
    Ensure that the formatting is consistent throughout the document.

    Here is the report:

    #{report}
  PROMPT
  send(prompt)
end

#next_plans(issues) ⇒ Object

rubocop:disable Metrics/MethodLength



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/newsman/assistant.rb', line 49

def next_plans(issues)
  example = "repository-name:\n
    - To publish ABC package draft [#27]\n
    - To review first draft of the report [#56]\n
    - To implement optimization for the class X [#125]"
  prompt = <<~PROMPT
    Please compile a summary of the plans for the next week using the GitHub Issues.
    Each issue should be summarized in a single sentence.
    Combine all the information from each Issue into a concise and fluent sentence.
    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].
    If several issues have the same number, combine them into a single sentence.
    Please strictly adhere to the example template provided: "#{example}".
    List of GitHub Issues in JSON format: ```json #{issues}```.
  PROMPT
  send(prompt)
end

#prev_results(prs) ⇒ Object

rubocop:disable Metrics/MethodLength



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/newsman/assistant.rb', line 69

def prev_results(prs)
  example = "repository-name:\n
    - Added 100 new files to the Dataset [#168]\n
    - Fixed the deployment of XYZ [#169]\n
    - Refined the requirements [#177]\n"
  prompt = <<~PROMPT
    Please compile a summary of the work completed in the following Pull Requests (PRs).
    Each PR should be summarized in a single sentence, focusing on the PR title rather than the implementation details.
    Ensure no PR is omitted.
    Each sentence must include the corresponding issue number as an integer value. If a PR does not mention an issue number, use [#chore].
    If several PRs have the same number, combine them into a single sentence.
    Combine the information from each PR into a concise and fluent sentence.
    Follow the provided example template strictly: "#{example}".
    List of Pull Requests in JSON format: ```json #{prs}```.
  PROMPT
  send(prompt)
end

#risks(all) ⇒ Object

rubocop:disable Metrics/MethodLength



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/newsman/assistant.rb', line 89

def risks(all)
  example = "repository-name:\n
    - The server is weak, we may fail the delivery\n
    of the dataset, report milestone will be missed [#487].\n
    - The code in repository is suboptimal, we might have some problems for the future maintainability [#44].\n"
  prompt = <<~PROMPT
    Please compile a summary of the risks identified in the repository from the list of pull requests provided.
    If no risks are identified in a pull request, just answer 'No risks identified' for that PR.
    Each risk should be summarized in a concise and fluent single sentence.
    Developers usually mention some risks in pull request descriptions, either as 'risk' or 'issue'.#{' '}
    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].
    Please strictly adhere to the example template provided: "#{example}".
    List of Pull Requests: ```json #{all}```.
  PROMPT
  send(prompt)
end

#say_helloObject



40
41
42
43
44
45
46
# File 'lib/newsman/assistant.rb', line 40

def say_hello
  <<~HELLO
    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.
  HELLO
end

#send(request) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/newsman/assistant.rb', line 120

def send(request)
  @client.chat(
    parameters: {
      model: @model,
      messages: [
        { role: 'system', content: CONTEXT },
        { role: 'user', content: request.to_s }
      ],
      temperature: @temperature
    }
  ).dig('choices', 0, 'message', 'content')
end