-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e1e3bb
commit f4facf6
Showing
22 changed files
with
246 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
EMAIL_FROM=local@local.local | ||
GITHUB_APP_SECRET=1cbaa8d7eaa9897204615ae07383791bf3c6113d | ||
GITHUB_APP_ID=4bf7b244da515541298a | ||
OPENAI_ACCESS_TOKEN=1cbdfyggfhhrtfvddjfj024lfh37fgen65fjgb | ||
|
||
RECAPTCHA_SITE_KEY=1111key2222 | ||
RECAPTCHA_SECRET_KEY='$eCr3T' | ||
|
||
HOST=localhost | ||
|
||
OPENAI_ACCESS_TOKEN = 1235fff12345 | ||
PASSWORD_SPECIAL_USER= | ||
EMAIL_SPECIAL_USER= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
HOST=www.example.com | ||
EMAIL_SPECIAL_USER=info@hexlet.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class OpenAiJob < ApplicationJob | ||
queue_as :default | ||
|
||
retry_on StandardError, wait: 5.seconds, attempts: 3 | ||
|
||
def perform(resume_id) | ||
resume = Resume.find(resume_id) | ||
ResumeAutoAnswerService.evaluate_resume(resume) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationContainer | ||
extend Dry::Container::Mixin | ||
|
||
if Rails.env.test? | ||
register(:open_ai_helper, memoize: true) { OpenAiHelperStub.new } | ||
else | ||
register(:open_ai_helper, memoize: true) { OpenAiHelper.new } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class OpenAiHelper | ||
attr_reader :client | ||
|
||
MODEL = 'gpt-3.5-turbo' | ||
TEMPERATURE = 0.7 | ||
|
||
def initialize | ||
@client = OpenAI::Client.new | ||
end | ||
|
||
def send_content(prompt, resume_content) | ||
response = chat([{ role: 'user', content: prompt }, { role: 'user', content: resume_content }]) | ||
|
||
raise StandardError, response['error']['message'] if response['error'] | ||
|
||
response | ||
end | ||
|
||
private | ||
|
||
def chat(messages = []) | ||
client.chat( | ||
parameters: { | ||
model: MODEL, | ||
messages:, | ||
temperature: TEMPERATURE | ||
} | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class OpenAiHelperStub | ||
def initialize(*); end | ||
|
||
def send_content(*) | ||
chat | ||
end | ||
|
||
private | ||
|
||
def chat(*) | ||
{ 'choices' => | ||
[{ 'message' => | ||
{ 'role' => 'assistant', | ||
'content' => | ||
'Резюме выглядит хорошо структурированным и содержит подробное описание проектов и навыков, которые соответствуют требованиям junior backend-разработчика (Ruby on Rails). Важно, что автор указывает желание профессионального развития, ревью кода и наска, что свидетельствует о его готовности к обучению и улучшению своих навыков. Единственное, что можно улучшить - добавить информацию о своих личных качествах и достижениях в области программирования.' }, | ||
'finish_reason' => 'stop', | ||
'index' => 0 }] } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
class ResumeAutoAnswerService | ||
class << self | ||
def evaluate_resume(resume) | ||
client = ApplicationContainer[:open_ai_helper] | ||
resume_summary = prepare_resume(resume) | ||
response_recommendation = client.send_content(I18n.t('open_ai_command.evaluate_resume'), resume_summary) | ||
response_covering_letter = client.send_content(I18n.t('open_ai_command.write_cover_letter'), resume_summary) | ||
response_edited_text = client.send_content(I18n.t('open_ai_command.edit_text'), resume_summary) | ||
|
||
content_recommendation = response_recommendation.dig('choices', 0, 'message', 'content') | ||
content_covering_letter = response_covering_letter.dig('choices', 0, 'message', 'content') | ||
content_edited_text = response_edited_text.dig('choices', 0, 'message', 'content') | ||
|
||
content = I18n.t('recommendation_open_ai', recommendation: content_recommendation, letter: content_covering_letter, edit_text: content_edited_text, scope: 'web.answers') | ||
|
||
ActiveRecord::Base.transaction do | ||
user = User.find_by(email: ENV.fetch('EMAIL_SPECIAL_USER')) | ||
attrs = { content: } | ||
Resume::AnswerMutator.create(resume, attrs, user) | ||
resume.evaluated_ai = true | ||
resume.save! | ||
end | ||
end | ||
|
||
def prepare_resume(resume) | ||
resume | ||
.serializable_hash | ||
.deep_symbolize_keys | ||
.slice(:name, :summary, :skills_description, :awards_description, :contact_phone, :contact_email) | ||
.values | ||
.join('\n') | ||
end | ||
end | ||
private_class_method :prepare_resume | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20230416145907_add_evaluated_open_ai_to_resumes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddEvaluatedOpenAiToResumes < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :resumes, :evaluated_ai, :boolean | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.