-
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.
Merge pull request #98 from identity-research-lab/fix-bad-relation
Fix an issue with categories creating invalid relations with codes
- Loading branch information
Showing
7 changed files
with
78 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class DeriveThemes | ||
|
||
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: | ||
{ | ||
"themes" : [ | ||
{ | ||
"theme": "foo", | ||
"codes": [ "bar", "bat", "baz"] | ||
} | ||
] | ||
} | ||
The codes are as follows: | ||
} | ||
|
||
def self.perform(text) | ||
new(text).perform | ||
end | ||
|
||
def initialize(text) | ||
@text = text | ||
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 |
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