Skip to content

Conversation

@hafizrahman
Copy link
Contributor

@hafizrahman hafizrahman commented Jun 15, 2023

Please do not merge before #9224 is merged.

Part of: #9216
Ref: pe5sF9-1AH-p2

Sorry if the PR is a bit large; a good chunk of it is just the Prompts text, and trackings.

Description

This PR continues from #9224 by adding the actual functionalities to the UI.

The added features are:

  1. "Share" button now works, with or without sharing message.
  2. Generating share message with AI now works,
  3. Information button now opens to Automattic's AI guidelines page.
  4. Error handling is now added in case AI completion fetching fails.
  5. Analytics:
Event Trigger Properties
*_product_sharing_ai_displayed When the sheet for AI-generated share content is displayed.  
*_product_sharing_ai_generate_tapped When the “Write with AI” button is tapped on the AI product share sheet. is_retry: true | false
*_product_sharing_ai_share_tapped When the “Share” button is tapped on the AI product share sheet. with_message: true | false
*_product_sharing_ai_dismissed When the AI product share sheet is dismissed.  
*_product_sharing_ai_message_generated When a message is generated on the AI product share sheet.  
*_product_sharing_ai_message_generation_failed When message generation fails on the AI product share sheet. error_context: classname error_type: errorType error_description: errorDescription

Testing instructions

  1. Start app, go to Products, select a published Product,
  2. tap Share on option on top right, then the sharing dialog will show up,
  3. Test sharing without a message,
  4. Go back, test the Write with AI button and make sure a message is generated,
  5. Test the "Regenerate" button,
  6. Test sharing with your own manually written message,
  7. Test the (i) icon and make sure it opens the webview to Automattic's AI Guidelines page.
  8. Open share dialog, turn off internet, and check the error case.
  9. Lastly, check logcat and find matching tracking events as outlined above.

Check video below for testing example:

Video

share-with-ai-android.webm
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jun 15, 2023

You can test the changes on this Pull Request by downloading an installable build, or scanning this QR code:

@codecov-commenter
Copy link

codecov-commenter commented Jun 15, 2023

Codecov Report

Patch coverage: 4.66% and project coverage change: -0.06 ⚠️

Comparison is base (7241db3) 44.05% compared to head (f59f569) 43.99%.

❗ Current head f59f569 differs from pull request most recent head 501a406. Consider uploading reports for the commit 501a406 to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk    #9236      +/-   ##
============================================
- Coverage     44.05%   43.99%   -0.06%     
+ Complexity     4268     4251      -17     
============================================
  Files           859      859              
  Lines         45459    45454       -5     
  Branches       5965     5958       -7     
============================================
- Hits          20026    19997      -29     
- Misses        23676    23707      +31     
+ Partials       1757     1750       -7     
Impacted Files Coverage Δ
...src/main/kotlin/com/woocommerce/android/AppUrls.kt 0.00% <ø> (ø)
...ain/kotlin/com/woocommerce/android/ai/AIPrompts.kt 0.00% <0.00%> (ø)
.../kotlin/com/woocommerce/android/ai/AIRepository.kt 0.00% <0.00%> (ø)
.../woocommerce/android/analytics/AnalyticsTracker.kt 20.76% <ø> (ø)
...rce/android/ui/products/ProductNavigationTarget.kt 16.37% <0.00%> (-0.59%) ⬇️
...oocommerce/android/ui/products/ProductNavigator.kt 0.00% <0.00%> (ø)
...e/android/ui/products/ProductSharingBottomSheet.kt 0.00% <0.00%> (ø)
...rce/android/ui/products/ProductSharingViewModel.kt 0.00% <0.00%> (ø)
...kotlin/com/woocommerce/android/util/FeatureFlag.kt 72.54% <0.00%> (ø)
...om/woocommerce/android/analytics/AnalyticsEvent.kt 100.00% <100.00%> (ø)

... and 11 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@hafizrahman hafizrahman added this to the 14.1 milestone Jun 16, 2023
The note itself is generated by ChatGPT.
Comment on lines +4 to +14
private const val PRODUCT_DESCRIPTION_PROMPT = "Write a description for a product with title \"%1\$s\"%2\$s.\n" +
"Identify the language used in the product title and use the same language in your response.\n" +
"Make the description 50-60 words or less.\n" +
"Use a 9th grade reading level.\n" +
"Perform in-depth keyword research relating to the product in the same language of the product title, " +
"and use them in your sentences without listing them out."

fun generateProductDescriptionPrompt(name: String, features: String = ""): String {
val featuresPart = if (features.isNotEmpty()) " and features: \"$features\"" else ""
return String.format(PRODUCT_DESCRIPTION_PROMPT, name, featuresPart)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused yet, but will be very soon, so I thought to add it right away.

@hafizrahman hafizrahman marked this pull request as ready for review June 16, 2023 11:11
@peril-woocommerce
Copy link

peril-woocommerce bot commented Jun 16, 2023

Warnings
⚠️ This PR is assigned to a milestone which is closing in less than 2 days Please, make sure to get it merged by then or assign it to a later expiring milestone
⚠️ PR has more than 300 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS

@hafizrahman hafizrahman changed the title Feature/ai share description functionality AI: Generate product sharing message part 2: Functionality Jun 16, 2023
@hafizrahman hafizrahman added the feature: product details Related to adding or editing products, includes product settings. label Jun 16, 2023

fun onShareButtonClicked() {
val writtenMessage = _viewState.value.shareMessage
val messageToShare = writtenMessage.ifEmpty { navArgs.productName } + "\n" + navArgs.permalink
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If user doesn't enter any share message, we default to "[product_name] [URL]" as the sharing text, otherwise it's "[written_message] [URL]"

@JorgeMucientes
Copy link
Contributor

Hey @hafizrahman 👋🏼

I'm still reviewing the PR but, while testing, I couldn't generate the test with AI. I always get an error. I tested with a couple different products, with and without description:

GenerateDescription.mp4

Any idea what might be wrong?

val messageToShare = writtenMessage.ifEmpty { navArgs.productName } + "\n" + navArgs.permalink

tracker.track(
AnalyticsEvent.PRODUCT_SHARING_AI_GENERATE_TAPPED,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Np, I think this tracking should be PRODUCT_SHARING_AI_SHARE_TAPPED ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Great eye.

Base automatically changed from feature/ai-share-description-ui to trunk June 16, 2023 14:36
hafizrahman and others added 3 commits June 16, 2023 21:52
…ites for now.

Otherwise it opens the old sharing feature as usual.
# Conflicts:
#	WooCommerce/src/main/kotlin/com/woocommerce/android/analytics/AnalyticsEvent.kt
#	WooCommerce/src/main/kotlin/com/woocommerce/android/analytics/AnalyticsTracker.kt
#	WooCommerce/src/main/kotlin/com/woocommerce/android/util/FeatureFlag.kt
@JorgeMucientes
Copy link
Contributor

Just finished reviewing @hafizrahman

Thanks for quick fixing the tracking issue. About this:

I'm still reviewing the PR but, while testing, I couldn't generate the test with AI. I always get an error. I tested with a couple different products, with and without description:

As discussed over Slack, it didn't work because I wasn't testing with a WP.com site and, as you well noticed this feature only applies to WP.com accounts. Now that the check is added to only display AI sharing UI for WP.com sites, we are good to go!

Excellent job!! Ready to ship :shipit:

@JorgeMucientes JorgeMucientes enabled auto-merge June 16, 2023 15:12
@JorgeMucientes JorgeMucientes merged commit 36a7817 into trunk Jun 16, 2023
@JorgeMucientes JorgeMucientes deleted the feature/ai-share-description-functionality branch June 16, 2023 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: product details Related to adding or editing products, includes product settings.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants