-
Notifications
You must be signed in to change notification settings - Fork 0
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 #17 from BlazingRockStorm/dev
version 0.1.0
- Loading branch information
Showing
15 changed files
with
187 additions
and
17 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
en: | ||
prompt: | ||
sentence: "Analyze the sentiment of the sentence given below.\n%{sentence}\nThe output should be in the format- value" | ||
sentence: "Analyze the sentiment of the sentence given below.\n%{sentence}\nThe output should be in the format- value" | ||
positive_check: "Is the sentence given below positive?\n%{sentence}\nThe output should be true or false" |
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,3 +1,4 @@ | ||
ja: | ||
prompt: | ||
sentence: "テキストを「中立」、「否定的」、または「肯定的」に分類してください。 テキスト:%{sentence}\n結果の形式- 値" | ||
sentence: "テキストを「中立」、「否定的」、または「肯定的」に分類してください。 テキスト:%{sentence}\n結果の形式- 値" | ||
positive_check: "テキストは肯定的ですか?\n%{sentence}\n「はい」はtrue、 「いいえ」は false" |
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,3 +1,4 @@ | ||
vi: | ||
prompt: | ||
sentence: "Phân tích sắc thái của câu dưới đây là tích cực, tiêu cực hay trung lập.\n%{sentence}\nKết quả trả về dưới dạng- Gía trị" | ||
sentence: "Phân tích sắc thái của câu dưới đây là tích cực, tiêu cực hay trung lập.\n%{sentence}\nKết quả trả về dưới dạng- Gía trị" | ||
positive_check: "Câu sau đây có tích cực hay không?\n%{sentence}\nkết quả trả về là true hoặc false" |
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,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'anthropic' | ||
|
||
module SentimentAI | ||
module Core | ||
class AnthropicDriver | ||
def initialize(api_key) | ||
@sentiment_ai = Anthropic::Client.new(access_token: api_key) | ||
end | ||
|
||
def analyze_sentence(sentence) | ||
text_request = I18n.t('prompt.sentence', sentence: sentence) | ||
|
||
@sentiment_ai.messages( | ||
parameters: { | ||
model: 'claude-3-haiku-20240307', | ||
messages: [ | ||
{ 'role': 'user', 'content': text_request } | ||
], | ||
max_tokens: 1000 | ||
} | ||
) | ||
end | ||
|
||
def positive_check(sentence) | ||
text_request = I18n.t('prompt.positive_check', sentence: sentence) | ||
|
||
@sentiment_ai.messages( | ||
parameters: { | ||
model: 'claude-3-haiku-20240307', | ||
messages: [ | ||
{ 'role': 'user', 'content': text_request } | ||
], | ||
max_tokens: 1000 | ||
} | ||
) | ||
end | ||
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
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,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module SentimentAI | ||
VERSION = '0.0.5' | ||
VERSION = '0.1.0' | ||
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,59 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'dotenv/load' | ||
|
||
RSpec.describe 'Using Anthropic provider' do | ||
let(:sentiment) { SentimentAI.new(:anthropic, ENV['ANTHROPIC_KEY']) } | ||
let(:japanese_sentiment) { SentimentAI.new(:anthropic, ENV['ANTHROPIC_KEY'], :ja) } | ||
|
||
describe 'new provider behaviours' do | ||
it 'provider being called correctly' do | ||
expect(sentiment).to be_truthy | ||
end | ||
end | ||
|
||
# describe 'analyze sentence in another language' do | ||
# describe '#analyze_sentence' do | ||
# it 'return the sentiment of the sentence' do | ||
# expect(japanese_sentiment.analyze_sentence('うまい!')).to eq({ sentence: 'うまい!', sentiment: '肯定的' }) | ||
# expect(japanese_sentiment.analyze_sentence('不愉快')).to eq({ sentence: '不愉快', sentiment: '否定的' }) | ||
# expect(japanese_sentiment.analyze_sentence('休暇はまずまずでした。')).to eq({ sentence: '休暇はまずまずでした。', sentiment: '中立' }) | ||
# end | ||
# end | ||
# end | ||
|
||
describe 'analyze feature' do | ||
describe '#analyze_sentence' do | ||
it 'return the sentiment of the sentence' do | ||
expect(sentiment.analyze_sentence('Delicious food')).to eq({ sentence: 'Delicious food', | ||
sentiment: 'positive' }) | ||
expect(sentiment.analyze_sentence('Too noisy!!!')).to eq({ sentence: 'Too noisy!!!', sentiment: 'negative' }) | ||
expect(sentiment.analyze_sentence("I really don't know how to feel about Pokemon")).to eq({ | ||
sentence: "I really don't know how to feel about Pokemon", sentiment: 'neutral' | ||
}) | ||
end | ||
end | ||
|
||
describe '#positive_check' do | ||
it 'return true or false' do | ||
expect(sentiment.positive_check('Delicious food')).to eq({ sentence: 'Delicious food', | ||
positive: true }) | ||
expect(sentiment.positive_check('Too noisy!!!')).to eq({ sentence: 'Too noisy!!!', positive: false }) | ||
end | ||
end | ||
|
||
describe '#analyze_array' do | ||
let(:array) { ['Delicious food', 'Too noisy!!!', "I really don't know how to feel about Pokemon"] } | ||
let(:result_array) do | ||
[{ sentence: 'Delicious food', sentiment: 'positive' }, | ||
{ sentence: 'Too noisy!!!', sentiment: 'negative' }, | ||
{ sentence: "I really don't know how to feel about Pokemon", sentiment: 'neutral' }] | ||
end | ||
|
||
it 'return the sentiments of all sentences in the array' do | ||
expect(sentiment.analyze_array(array)).to eq(result_array) | ||
end | ||
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
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