-
Notifications
You must be signed in to change notification settings - Fork 3
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
fa55f57
commit 6e75874
Showing
1 changed file
with
30 additions
and
29 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,39 +1,40 @@ | ||
class DeriveThemes | ||
module Services | ||
class DeriveThemes | ||
|
||
attr_accessor :text | ||
attr_accessor :text | ||
|
||
# This is the prompt sent to the selected AI agent to provide instructions on category derivision. | ||
PROMPT = %{ | ||
You are a social researcher doing data analysis. Please generate a list of the 20 most relevant themes from the following list of codes. The themes should be all lowercase and contain no punctuation. Codes should be stripped of quotation marks. Return each code with an array of its categories in JSON format. Use this JSON as the format: | ||
# This is the prompt sent to the selected AI agent to provide instructions on category derivision. | ||
PROMPT = %{ | ||
You are a social researcher doing data analysis. Please generate a list of the 20 most relevant themes from the following list of codes. The themes should be all lowercase and contain no punctuation. Codes should be stripped of quotation marks. Return each code with an array of its categories in JSON format. Use this JSON as the format: | ||
{ | ||
"themes" : [ | ||
{ | ||
"theme": "foo", | ||
"codes": [ "bar", "bat", "baz"] | ||
} | ||
] | ||
} | ||
The codes are as follows: | ||
} | ||
{ | ||
"themes" : [ | ||
{ | ||
"theme": "foo", | ||
"codes": [ "bar", "bat", "baz"] | ||
} | ||
] | ||
} | ||
def self.perform(text) | ||
new(text).perform | ||
end | ||
The codes are as follows: | ||
} | ||
|
||
def initialize(text) | ||
@text = text | ||
end | ||
def self.perform(text) | ||
new(text).perform | ||
end | ||
|
||
# Uses the OpenAI client to pass the prompt and text through the API for sentiment analysis. | ||
def perform | ||
return false unless text.present? | ||
def initialize(text) | ||
@text = text | ||
end | ||
|
||
response = Clients::OpenAi.request("#{PROMPT} #{self.text}") | ||
return false unless response['themes'].present? | ||
return response['themes'] | ||
end | ||
# Uses the OpenAI client to pass the prompt and text through the API for sentiment analysis. | ||
def perform | ||
return false unless text.present? | ||
|
||
response = Clients::OpenAi.request("#{PROMPT} #{self.text}") | ||
return false unless response['themes'].present? | ||
return response['themes'] | ||
end | ||
|
||
end | ||
end |