-
Notifications
You must be signed in to change notification settings - Fork 186
Improve semantic fact extraction prompt and add JSON enforcement #4282
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| import static org.opensearch.common.xcontent.json.JsonXContent.jsonXContent; | ||
| import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken; | ||
| import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.DEFAULT_UPDATE_MEMORY_PROMPT; | ||
| import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.JSON_ENFORCEMENT_MESSAGE; | ||
| import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.LLM_ID_FIELD; | ||
| import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.MEMORY_DECISION_FIELD; | ||
| import static org.opensearch.ml.common.memorycontainer.MemoryContainerConstants.SEMANTIC_FACTS_EXTRACTION_PROMPT; | ||
|
|
@@ -159,6 +160,11 @@ public void extractFactsFromConversation( | |
| MessageInput message = getMessageInput("Please extract information from our conversation so far"); | ||
| message.toXContent(messagesBuilder, ToXContent.EMPTY_PARAMS); | ||
| } | ||
|
|
||
| // Always add JSON enforcement message for fact extraction | ||
| MessageInput enforcementMessage = getMessageInput(JSON_ENFORCEMENT_MESSAGE); | ||
| enforcementMessage.toXContent(messagesBuilder, ToXContent.EMPTY_PARAMS); | ||
|
Comment on lines
+165
to
+166
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you find adding the enforcement message in the User prompt instead of the system prompt works better? Because in my experience they seem to adhere better in System prompt. The general guidance from OpenAI and others is to put output format instructions in System Prompt. If we do not see any significant improvements, I suggest adding it in the system prompt, to keep the code clean and readable.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 even in the user prompt when i ask LLM to not adhere to this format, it responds by saying it cannot and has been explicitly requested to follow a certain format. This must be because system prompt is given higher priority.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed significant improvements with adding this
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, I got this suggestion from LLMs like claude & openai :)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, that sounds good. But recommend to try system_prompt as an iteration in the future, it should perform better! I had some issues with PER responses when it was in user_prompt, moving to system_prompt significantly helped. As you have tested, I don't want to block you! Thanks! |
||
|
|
||
| messagesBuilder.endArray(); | ||
| String messagesJson = messagesBuilder.toString(); | ||
| stringParameters.put("messages", messagesJson); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.