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

Support pass prompt to CreateAlertTool #452

Merged
merged 9 commits into from
Nov 22, 2024

Conversation

qianheng-aws
Copy link
Contributor

@qianheng-aws qianheng-aws commented Oct 23, 2024

Description

This PR enhance the CreateAlertTool with 2 features:

  • support pass prompt as parameter to override the default prompt.
  • use CLAUDE as its default model type if model_type in parameters is empty or unsupported.

Related Issues

Resolves #447

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Heng Qian <qianheng@amazon.com>
Signed-off-by: Heng Qian <qianheng@amazon.com>
Copy link
Member

@yuye-aws yuye-aws left a comment

Choose a reason for hiding this comment

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

Approved. Can @zane-neo review?

Comment on lines +76 to +91
public enum ModelType {
CLAUDE,
OPENAI;

public static ModelType from(String value) {
if (value.isEmpty()) {
return ModelType.CLAUDE;
}
try {
return ModelType.valueOf(value.toUpperCase(Locale.ROOT));
} catch (Exception e) {
log.error("Wrong Model type, should be CLAUDE or OPENAI");
return ModelType.CLAUDE;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Wait a bit. The code is the same as the ModelType in PPL tool. Can you extract it outside the function for code reusage?

Copy link
Contributor Author

@qianheng-aws qianheng-aws Nov 12, 2024

Choose a reason for hiding this comment

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

They are not exactly the same, this tool doesn't support FINETUNE model. If we want to reuse this method, we'd better refactor it as well and I think it should also applies to other tools like CreateAnomalyDetectorTool.

So I don't think it's a blocker for this PR, we can do such refactor work in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Then the code is good.

);
modelType = String.valueOf(ModelType.from(modelType));
if (prompt.isEmpty()) {
if (!promptDict.containsKey(modelType)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The model type is enumerated, do we need to judge whether promptDict contains the model type?

Copy link
Contributor Author

@qianheng-aws qianheng-aws Nov 12, 2024

Choose a reason for hiding this comment

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

This is the right line for identify whether promptDict contains that model. It will throw exception if not having.

Copy link
Member

@yuye-aws yuye-aws left a comment

Choose a reason for hiding this comment

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

This PR looks good to me. Pinging @xinyual to review again.

@yuye-aws
Copy link
Member

#457 @qianheng-aws This PR gets merged. Please update accordingly.

@qianheng-aws
Copy link
Contributor Author

qianheng-aws commented Nov 14, 2024

#457 @qianheng-aws This PR gets merged. Please update accordingly.

Should this PR be the same as that change? I think there is no difference functionally. We already support empty model_type and return a default one.

@yuye-aws
Copy link
Member

#457 @qianheng-aws This PR gets merged. Please update accordingly.

Should this PR be the same as that change? I think there is no difference functionally. We already support empty model_type and return a default one.

Well. I mean you can make the following code snippet public. Then, both CreateAlertTool and CreateAnomalyDetectorTool can import it.

    public enum ModelType {
        CLAUDE,
        OPENAI;

        public static ModelType from(String value) {
            if (value.isEmpty()) {
                return ModelType.CLAUDE;
            }
            try {
                return ModelType.valueOf(value.toUpperCase(Locale.ROOT));
            } catch (Exception e) {
                log.error("Wrong Model type, should be CLAUDE or OPENAI");
                return ModelType.CLAUDE;
            }
        }
    }

@qianheng-aws
Copy link
Contributor Author

#457 @qianheng-aws This PR gets merged. Please update accordingly.

Should this PR be the same as that change? I think there is no difference functionally. We already support empty model_type and return a default one.

Well. I mean you can make the following code snippet public. Then, both CreateAlertTool and CreateAnomalyDetectorTool can import it.

    public enum ModelType {
        CLAUDE,
        OPENAI;

        public static ModelType from(String value) {
            if (value.isEmpty()) {
                return ModelType.CLAUDE;
            }
            try {
                return ModelType.valueOf(value.toUpperCase(Locale.ROOT));
            } catch (Exception e) {
                log.error("Wrong Model type, should be CLAUDE or OPENAI");
                return ModelType.CLAUDE;
            }
        }
    }

I think that change should be made in the PR for refactoring code reuse. There is no help make it public for now.

@xinyual
Copy link
Collaborator

xinyual commented Nov 19, 2024

@qianheng-aws Seems CI/CD fails. Can you fix this?

@yuye-aws
Copy link
Member

@qianheng-aws Spotless apply plz.

Signed-off-by: Heng Qian <qianheng@amazon.com>
Signed-off-by: Heng Qian <qianheng@amazon.com>
@qianheng-aws
Copy link
Contributor Author

Only 1 flakey test failure, which is unrelated as well:

71 tests completed, 1 failed
Tests with failures:

  • org.opensearch.integTest.NeuralSparseSearchToolIT.testNeuralSparseSearchToolInFlowAgent_withNestedIndex

@yuye-aws
Copy link
Member

Pinging @xinyual to review this PR.

@yuye-aws
Copy link
Member

@xinyual Plz attach backport-2.x label to this PR.

@xinyual xinyual merged commit a95cfae into opensearch-project:main Nov 22, 2024
8 of 9 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Nov 22, 2024
* Support pass prompt to CreateAlertTool

Signed-off-by: Heng Qian <qianheng@amazon.com>

* Use Claude as ModelType if passed-in modelType is empty

Signed-off-by: Heng Qian <qianheng@amazon.com>

* Fix UT

Signed-off-by: Heng Qian <qianheng@amazon.com>

* Fix spotlessApply

Signed-off-by: Heng Qian <qianheng@amazon.com>

* Fix spotlessApply

Signed-off-by: Heng Qian <qianheng@amazon.com>

---------

Signed-off-by: Heng Qian <qianheng@amazon.com>
Co-authored-by: zane-neo <zaniu@amazon.com>
(cherry picked from commit a95cfae)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
xinyual pushed a commit that referenced this pull request Nov 22, 2024
* Support pass prompt to CreateAlertTool



* Use Claude as ModelType if passed-in modelType is empty



* Fix UT



* Fix spotlessApply



* Fix spotlessApply



---------



(cherry picked from commit a95cfae)

Signed-off-by: Heng Qian <qianheng@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: zane-neo <zaniu@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Support other model types in CreateAlertTool and CreateAnomalyDetectorTool
4 participants