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

Temp draft PR for easier diffing #256

Draft
wants to merge 9 commits into
base: ai-expression
Choose a base branch
from
Draft

Conversation

bobular
Copy link
Member

@bobular bobular commented Feb 19, 2025

No description provided.

@@ -28,13 +26,6 @@ public AiExpressionCache() throws IOException {
super(DEFAULT_CACHE_DIR, DEFAULT_TIMEOUT_MILLIS, DEFAULT_POLL_FREQUENCY_MILLIS);
}

// Compute SHA-256 hash digest of input
private static String computeDigest(String input) throws NoSuchAlgorithmException {
Copy link
Member Author

Choose a reason for hiding this comment

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

We might need to get this back?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, we're not using this any more - I should have deleted it.

Copy link
Member Author

@bobular bobular left a comment

Choose a reason for hiding this comment

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

Here are my comments. I am about to push a change but I notice there are some recent pushes from you. I hope they don't clash.

EDIT - oh maybe there aren't any new changes from you, yay!

public static List<JSONObject> processExpressionData(RecordInstance geneRecord, int maxExperiments) throws WdkModelException, WdkUserException {
// return value:
List<JSONObject> experiments = new ArrayList<>();
public static GeneSummaryInputs getSummaryInputsFromRecord(RecordInstance record, Function<JSONObject, String> experimentDigester) throws WdkModelException {
Copy link
Member Author

Choose a reason for hiding this comment

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

Could we call this getExperimentPrompt to be consistent and not confuse with md5 digesting?

* @param summaryInputs inputs
* @return response JSON (indicating cache hit or not with data or miss reason respectively)
* @throws Exception lookup or other exception if unable to find or validate cached data
*/
Copy link
Member Author

Choose a reason for hiding this comment

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

We only use this function as a visitor function passed to _cache.populateAndProcessContent() which is good because getValidStoredData() accesses the cache directory directly (via digestsMatch() and readCachedData(), so we need the lock in place.

Is there some way to stop us accidentally calling these methods/functions outside of the lock mechanism? Or is this not really necessary if they are private methods? Maybe we just need an extra line in the documentation to explain this?

List<ExperimentInputs> getExperimentsWithData();

default String getDigest() {
// TODO Does it make more sense to md5 the concatenation of the experiment hashes?
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it'll save a bit of compute too!

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally this needs to digest the second level (final summary) prompt as well as the inputs to that prompt. Then when we tweak the prompting on the live site, cache entries will be invalidated automatically. I am about to push the fix for this.

List<JSONObject> experiments = new ArrayList<>();
// start with serial generation; move back to parallel later
for (ExperimentInputs input : experimentData) {
experiments.add(_cache.populateAndProcessContent(input.getCacheKey(),
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this nested populateAndProcessContent() is going to fail to get a lock?

private static final String CACHE_DIR_PROP_NAME = "AI_EXPRESSION_CACHE_DIR";
private static final String DEFAULT_TMP_CACHE_SUBDIR = "expressionCache";

// catch characteristics
private static final long DEFAULT_TIMEOUT_MILLIS = 5000;
Copy link
Member Author

Choose a reason for hiding this comment

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

I know this is just a detail, but let's say the AI summarisation takes up to 3 minutes and is performed within OnDiskCache.populateAndProcessContent(). Does that mean the timeout should be at least 3 × 60 × 1000?

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