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

Add default prompt to ppl tool #125

Merged
merged 12 commits into from
Jan 16, 2024

Conversation

xinyual
Copy link
Collaborator

@xinyual xinyual commented Jan 12, 2024

Description

add default prompt to ppl tool

Issues Resolved

add default prompt to ppl tool. So customer don't need to add very low context prompt in their request body.

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

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: xinyual <[email protected]>
@@ -373,4 +405,20 @@ private String parseOutput(String llmOutput, String indexName) {
return ppl;
}

private String loadDefaultPrompt(PPLModelType pplModelType) {
Copy link
Member

@zhichao-aws zhichao-aws Jan 12, 2024

Choose a reason for hiding this comment

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

Now we read the resource every time when invoke creating PPLTool. It would be more efficient if we only read them once and store the prompts at static fields

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Already move it to static.

Signed-off-by: xinyual <[email protected]>
Copy link

codecov bot commented Jan 12, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (c81746e) 80.82% compared to head (60f0c10) 80.83%.
Report is 1 commits behind head on main.

Files Patch % Lines
.../main/java/org/opensearch/agent/tools/PPLTool.java 83.33% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #125      +/-   ##
============================================
+ Coverage     80.82%   80.83%   +0.01%     
- Complexity      193      195       +2     
============================================
  Files            13       13              
  Lines           975     1002      +27     
  Branches        130      133       +3     
============================================
+ Hits            788      810      +22     
- Misses          137      141       +4     
- Partials         50       51       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: xinyual <[email protected]>
Signed-off-by: xinyual <[email protected]>
try {
defaultPromptDict = loadDefaultPromptDict();
} catch (IOException e) {
throw new RuntimeException("fail to load default prompt dict" + e.getMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible that this would break the plugin initialization process with this error thrown?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. Already change the logic to init the dict to an empty dict and log an error here.

this.contextPrompt = contextPrompt;
this.pplModelType = PPLModelType.from(pplModelType);
if (contextPrompt.isEmpty()) {
this.contextPrompt = this.defaultPromptDict.getOrDefault(this.pplModelType.toString(), "");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible this pplModelType.toString() produce NPE?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since we init the modeltype with the default value, the model type should be an object or throw an error. So it shouldn't be a NPE.

@xinyual xinyual force-pushed the addDefaultPromptToPPLTool branch from cd2717b to a8c673a Compare January 15, 2024 06:56
Signed-off-by: xinyual <[email protected]>
@xinyual
Copy link
Collaborator Author

xinyual commented Jan 15, 2024

Force push since we decide not to add abstract prompt class this time.

FINETUNE;

public static PPLModelType from(String value) {
if (value.isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is value possibly be null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, when create ppltool object, we use (String) map.getOrDefault("model_type", "") So model type string will have default value.

@zane-neo zane-neo merged commit 7e4c8d5 into opensearch-project:main Jan 16, 2024
13 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 16, 2024
* add default prompt for ppl tool

Signed-off-by: xinyual <[email protected]>

* fix Upper problem

Signed-off-by: xinyual <[email protected]>

* change wrong information

Signed-off-by: xinyual <[email protected]>

* remove uesless log

Signed-off-by: xinyual <[email protected]>

* add corresponding UTs

Signed-off-by: xinyual <[email protected]>

* apply spotless

Signed-off-by: xinyual <[email protected]>

* use locale instead

Signed-off-by: xinyual <[email protected]>

* move dict to static

Signed-off-by: xinyual <[email protected]>

* move dict to static

Signed-off-by: xinyual <[email protected]>

* replace throw error with error log

Signed-off-by: xinyual <[email protected]>

* add default value for PPL model type

Signed-off-by: xinyual <[email protected]>

* apply spotless

Signed-off-by: xinyual <[email protected]>

---------

Signed-off-by: xinyual <[email protected]>
(cherry picked from commit 7e4c8d5)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
xinyual pushed a commit that referenced this pull request Jan 16, 2024
* add default prompt for ppl tool



* fix Upper problem



* change wrong information



* remove uesless log



* add corresponding UTs



* apply spotless



* use locale instead



* move dict to static



* move dict to static



* replace throw error with error log



* add default value for PPL model type



* apply spotless



---------


(cherry picked from commit 7e4c8d5)

Signed-off-by: xinyual <[email protected]>
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>
@zhichao-aws zhichao-aws mentioned this pull request Jan 17, 2024
5 tasks
yuye-aws pushed a commit to yuye-aws/skills that referenced this pull request Apr 26, 2024
…roject#129)

* add default prompt for ppl tool

* fix Upper problem

* change wrong information

* remove uesless log

* add corresponding UTs

* apply spotless

* use locale instead

* move dict to static

* move dict to static

* replace throw error with error log

* add default value for PPL model type

* apply spotless

---------

(cherry picked from commit 7e4c8d5)

Signed-off-by: xinyual <[email protected]>
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>
Signed-off-by: yuye-aws <[email protected]>
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.

3 participants