-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
536 additions
and
23 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
48 changes: 48 additions & 0 deletions
48
...de-build/roborazzi-core/src/commonMain/kotlin/com/github/takahirom/roborazzi/AiOptions.kt
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,48 @@ | ||
package com.github.takahirom.roborazzi | ||
|
||
/** | ||
* If you want to use AI to compare images, you can specify the model and prompt. | ||
*/ | ||
data class AiOptions( | ||
val aiModel: AiModel, | ||
val aiAssertions: List<AiAssertion> = emptyList(), | ||
val inputPrompt: (AiOptions) -> String = { aiOptions -> | ||
buildString { | ||
aiOptions.aiAssertions.forEachIndexed { index, aiAssertion -> | ||
appendLine("Assertion ${index + 1}: ${aiAssertion.assertPrompt}\n") | ||
} | ||
} | ||
}, | ||
val template: String = """ | ||
Evaluate the following assertion for fulfillment in the new image. | ||
The evaluation should be based on the comparison between the original image on the left and the new image on the right, with differences highlighted in red in the center. Focus on whether the new image fulfills the requirement specified in the user input. | ||
Output: | ||
For each assertion: | ||
A fulfillment percentage from 0 to 100. | ||
A brief explanation of how this percentage was determined. | ||
Assertions: | ||
INPUT_PROMPT | ||
""" | ||
) { | ||
interface AiModel { | ||
data class Gemini( | ||
val apiKey: String, | ||
val modelName: String = "gemini-1.5-pro" | ||
) : AiModel | ||
|
||
/** | ||
* You can use this model if you want to use other models. | ||
*/ | ||
interface Manual : AiModel, AiCompareResultFactory | ||
} | ||
|
||
data class AiAssertion( | ||
val assertPrompt: String, | ||
/** | ||
* If null, the AI result is not validated. But they are still included in the report. | ||
*/ | ||
val requiredFulfillmentPercent: Int | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
...ld/roborazzi-core/src/commonMain/kotlin/com/github/takahirom/roborazzi/AiResultFactory.kt
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,13 @@ | ||
package com.github.takahirom.roborazzi | ||
|
||
fun interface AiCompareResultFactory { | ||
operator fun invoke( | ||
comparisonImageFilePath: String, | ||
aiOptions: AiOptions | ||
): AiResult | ||
} | ||
|
||
var aiCompareResultFactory: AiCompareResultFactory? = | ||
AiCompareResultFactory { comparisonImageFilePath, aiOptions -> | ||
throw NotImplementedError("aiCompareCanvasFactory is not implemented") | ||
} |
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 @@ | ||
build/ |
Oops, something went wrong.