-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixing a name typo * better prompt fetch from db * Fixing the Trix UI * Few gem updates; * Upgrading to Rails 7.0.5.1 * Fixing an association issue in between organization and users * fixing a typo organiation.members * fixing the prompt table * Upgradig a few gems * Upgrading to Rails 7.0.6 * Upgrading ActionText to version 7.0.6 * fixing the prompt table * Aligning Gemfile.loc * Upgrading to Rails 7.0.6 * Upgrading groupdate, faraday, rails-dom-testig and few other gems * Upgrading honeybadger to version 6.1.3 * Minor gem upgrades * Renamed and improved the prompt import function * Adding octokit * schema.rb now reflects the correct database structure * Middle of the gate * Upgrading to Flowbite 1.7.0 * Extracting Topic from question --------- Signed-off-by: spaquet <176050+spaquet@users.noreply.github.com>
- Loading branch information
Showing
24 changed files
with
349 additions
and
195 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
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
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,16 @@ | ||
class EventTopicsExtractionJob | ||
include Sidekiq::Job | ||
|
||
require "openai" | ||
|
||
def perform(event) | ||
# Initialize an openAI client | ||
client = OpenAI::Client.new | ||
|
||
# Fetch all the questions from an event | ||
|
||
# Aggregate the questions in one document | ||
|
||
# Extract the topics from the questions with openAI | ||
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 |
---|---|---|
@@ -1,14 +1,21 @@ | ||
# app/sidekiq/question_processing_job.rb | ||
class QuestionProcessingJob | ||
include Sidekiq::Job | ||
|
||
def perform(question) | ||
# Extract key elements from the question such as Tone, Keywords | ||
# Topics are extracted via a cron job | ||
|
||
# Extract Tone from the quesstion | ||
# Extract Tone from the question | ||
QuestionToneJob.perform_async(question) | ||
|
||
# Extract Keywords from the question | ||
QuestionKeywordsExtractionJob.perform_async(question) | ||
|
||
# Extract the status from the question JSON | ||
question_status = JSON.parse(question)['status'] | ||
|
||
# Check if the question status is not "rejected" | ||
if question_status != "rejected" | ||
# Extract Keywords from the question | ||
QuestionKeywordsExtractionJob.perform_async(question) | ||
|
||
# Extract Topic from the question | ||
QuestionTopicExtractionJob.perform_async(question) | ||
end | ||
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,71 @@ | ||
# app/sidekiq/question_topic_extraction_job.rb | ||
|
||
# Description: used to extract the topic covered by a question. | ||
|
||
class QuestionTopicExtractionJob | ||
include Sidekiq::Job | ||
|
||
require "openai" | ||
|
||
def perform(question) | ||
# Initialize an openAI client | ||
client = OpenAI::Client.new | ||
|
||
# Parse the question | ||
qh = JSON.parse(question) | ||
# puts "## Question ##" | ||
# puts qh | ||
|
||
# Extracting key values from the question | ||
room_id = qh.dig("room_id") | ||
question_id = qh.dig("id") | ||
question_title = qh.dig("title") | ||
user_id = qh.dig("user_id") | ||
|
||
# Find the event id | ||
event_id = Room.select(:event_id).find(room_id).event_id | ||
puts "## Event id: #{event_id}" | ||
|
||
# Extracting the topic from the question using openAI | ||
pr = PromptRetrieverService.retrieve("question-topic-extraction", nil, {title: question_title}) | ||
# puts "## PROMPT ##" | ||
# puts pr.inspect | ||
|
||
messages = JSON.parse(pr[:messages]) | ||
|
||
params = { | ||
model: pr[:model], | ||
messages: messages, | ||
temperature: 0.7, | ||
user: qh.dig("user_id") | ||
} | ||
|
||
# puts params | ||
|
||
response = client.chat( | ||
parameters: params | ||
) | ||
|
||
# puts response | ||
|
||
topics = response.dig("choices", 0, "message","content") | ||
topics = topics.split(", ") | ||
topics.map{ |word| word.strip.chomp(".") } | ||
puts "TOPICS IS ARRAY? #{topics.kind_of?(Array)}" | ||
puts "QUESTION: #{question_title}" | ||
puts "TOPICS AS ARRAY: #{topics}" | ||
if topics.kind_of?(Array) | ||
topics.each do |topic| | ||
param = { | ||
event_id: event_id, | ||
question_id: question_id, | ||
room_id: room_id, | ||
user_id: user_id, | ||
description: "Question: #{question_title}", | ||
name: topic | ||
} | ||
Topic.upsert(param , unique_by: [:question_id, :room_id, :user_id]) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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.