Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New sentiment #1839

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion backend/.env.dist.composed
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ CROWD_OPENSEARCH_NODE=http://open-search:9200
# Temporal
CROWD_TEMPORAL_SERVER_URL=temporal:7233

# HuggingFace
CROWD_HUGGINGFACE_API_KEY=

# Seach sync api
CROWD_SEARCH_SYNC_API_URL=http://search-sync-api:8083
CROWD_SEARCH_SYNC_API_URL=http://search-sync-api:8083
5 changes: 4 additions & 1 deletion backend/.env.dist.local
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,8 @@ CROWD_ANALYTICS_API_TOKEN=
CROWD_TEMPORAL_SERVER_URL=localhost:7233
CROWD_TEMPORAL_NAMESPACE=default

# HuggingFace
CROWD_HUGGINGFACE_API_KEY=

# Seach sync api
CROWD_SEARCH_SYNC_API_URL=http://search-sync-api:8083
CROWD_SEARCH_SYNC_API_URL=http://search-sync-api:8083
2 changes: 2 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions backend/src/bin/scripts/unleash-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ const constaintConfiguration = {
],
],

// New sentiment
[FeatureFlag.NEW_SENTIMENT]: [],

[FeatureFlag.SYNCHRONOUS_OPENSEARCH_UPDATES]: [
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<el-tooltip
v-if="sentiment && sentiment > 0"
effect="dark"
:content="`Sentiment score: ${sentiment}`"
:content="`${label} sentiment`"
placement="top"
>
<i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"sentiment": {
"region": "CROWD_COMPREHEND_AWS_REGION",
"accessKeyId": "CROWD_COMPREHEND_AWS_ACCESS_KEY_ID",
"secretAccessKey": "CROWD_COMPREHEND_AWS_SECRET_ACCESS_KEY"
"secretAccessKey": "CROWD_COMPREHEND_AWS_SECRET_ACCESS_KEY",
"huggingfaceApiKey": "CROWD_HUGGINGFACE_API_KEY"
},
"slackAlerting": {
"url": "CROWD_SLACK_ALERTING_URL"
Expand Down
39 changes: 35 additions & 4 deletions services/apps/data_sink_worker/src/service/activity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,24 @@ export default class ActivityService extends LoggerBase {
): Promise<string> {
try {
this.log.debug('Creating an activity.')

const sentiment = await getSentiment(`${activity.body || ''} ${activity.title || ''}`.trim())
// TODO: isNewSentimentEnabled FF
const isNewSentimentEnabled = await isFeatureEnabled(
FeatureFlag.NEW_SENTIMENT,
async () => {
return {
tenantId,
}
},
this.unleash,
this.redisClient,
60,
tenantId,
)

const sentiment = await getSentiment(
`${activity.body || ''} ${activity.title || ''}`.trim(),
isNewSentimentEnabled,
)

const id = await this.store.transactionally(async (txStore) => {
const txRepo = new ActivityRepository(txStore, this.log)
Expand Down Expand Up @@ -160,7 +176,7 @@ export default class ActivityService extends LoggerBase {
const txRepo = new ActivityRepository(txStore, this.log)
const txSettingsRepo = new SettingsRepository(txStore, this.log)

const toUpdate = await this.mergeActivityData(activity, original)
const toUpdate = await this.mergeActivityData(activity, original, tenantId)

if (toUpdate.type) {
await txSettingsRepo.createActivityType(
Expand Down Expand Up @@ -222,9 +238,24 @@ export default class ActivityService extends LoggerBase {
private async mergeActivityData(
data: IActivityUpdateData,
original: IDbActivity,
tenantId: string,
): Promise<IDbActivityUpdateData> {
let calcSentiment = false

// TODO: isNewSentimentEnabled FF
const isNewSentimentEnabled = await isFeatureEnabled(
FeatureFlag.NEW_SENTIMENT,
async () => {
return {
tenantId,
}
},
this.unleash,
this.redisClient,
60,
tenantId,
)

let body: string | undefined
if (!arePrimitivesDbEqual(original.body, data.body)) {
body = data.body
Expand All @@ -239,7 +270,7 @@ export default class ActivityService extends LoggerBase {

let sentiment: Promise<ISentimentAnalysisResult | undefined>
if (calcSentiment) {
sentiment = getSentiment(`${body || ''} ${title || ''}`.trim())
sentiment = getSentiment(`${body || ''} ${title || ''}`.trim(), isNewSentimentEnabled)
} else {
sentiment = Promise.resolve(undefined)
}
Expand Down
154 changes: 153 additions & 1 deletion services/libs/sentiment/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion services/libs/sentiment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dependencies": {
"@aws-sdk/client-comprehend": "^3.335.0",
"@crowd/common": "file:../common",
"@crowd/logging": "file:../logging"
"@crowd/logging": "file:../logging",
"axios": "^1.6.1"
}
}
Loading
Loading