Skip to content

Bug 2010707 - Created an LLMProvider class in Fenix#52

Open
fmasalha wants to merge 1 commit intomozilla-firefox:autolandfrom
fmasalha:LLMProvider
Open

Bug 2010707 - Created an LLMProvider class in Fenix#52
fmasalha wants to merge 1 commit intomozilla-firefox:autolandfrom
fmasalha:LLMProvider

Conversation

@fmasalha
Copy link
Contributor

@fmasalha fmasalha commented Feb 3, 2026

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

View this pull request in Lando to land it once approved.

Copy link
Contributor

@segunfamisa segunfamisa left a comment

Choose a reason for hiding this comment

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

Thanks for this patch!

Most of my comments are not blocking, but I do have two comments that I think we should address:

  1. About the creation of GeminiNanoLlm and
  2. The check about the content being readerable


internal class Summarizer(private val llm: Llm) {
suspend fun summarize(content: String): Flow<Llm.Response> {
val preparedStatement =
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 tip:

Do you know about this """my multiline text""".trimIndent()

I think it's pretty cool and can simplify long lines of text like this.

}

suspend fun checkSummarizability(content: String): Boolean {
return content.length <= MAX_CONTENT_LENGTH && llm.checkStatus() is Llm.Status.Available
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ important:

@MatthewTighe : Do we also need to check if the page is readerable? i.e if the reader mode is enabled for that page.

How do we plan to check that?

One idea is:

  1. Change the content parameter into a contentProperties of type data class ContentProperties(val length: Int, val isRreaderable: Boolean, .....)
  2. Then we can just use contentProperties.length, llm.checkStatus() and contentProperties.isReaderable

@@ -73,6 +73,13 @@ class GeminiNanoLlm(
}
}

override suspend fun checkStatus(): Llm.Status {
Copy link
Contributor

Choose a reason for hiding this comment

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

👌


internal class Summarizer(private val llm: Llm) {
suspend fun summarize(content: String): Flow<Llm.Response> {
val preparedStatement =
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 idea:

Do we want to consider passing down the prompt from outside the summarizer?

So we can have:

class Summarizer(val llm: Llm, val prompt: String) {  
  
  suspend fun summarize(content: String) ... {
    val statement = "$prompt $content"
    return llm.prompt(Prompt(statement))
  }
}

or

class Summarizer(val llm: Llm) {  
  
  suspend fun summarize(content: String, prompt: String) ... {
    val statement = "$prompt $content"
    return llm.prompt(Prompt(statement))
  }
}

I like the second one better, because I can imagine that we want to A/B test multiple prompts with the same LLM, so we just call summarizer.summarize(..., promptA), summarizer.summarize(....,promptB)

@fmasalha
Copy link
Contributor Author

fmasalha commented Feb 4, 2026

@fmasalha
Copy link
Contributor Author

fmasalha commented Feb 4, 2026

Copy link
Contributor

@segunfamisa segunfamisa left a comment

Choose a reason for hiding this comment

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

Thanks @fmasalha

There's one last thing I think we should fix before we land it. It's about how the test is written.

Let me know your thoughts.

Comment on lines +22 to +23
@get:Rule
val coroutineRule = MainCoroutineRule()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's a recent effort from @mcarare to remove usages of MainCoroutineRule and runTestOnMain.

I recommend taking a look at one of Mihai's patches like this one https://phabricator.services.mozilla.com/D281798

In some cases, this is as simple as using runTest() instead of runTestMain() but if we are doing some special things with dispatcher changes, or delay or syncrhonization, it will require creating a testDispatcher = StandardTestDispatcher() and using runTest(testDispatcher) and advanceTimeUntilIdle()

But I don't think we are doing that in this case, so your test can just remove the test rule, and use runTest.

If that does not work. Lemme know, and we can work through what I described together.

/**
* Abstraction for components that can summarize reader content.
*/
interface Summarizer {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why this can't live in our feature module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No reason, ill move it. thanks for the tip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants