-
Notifications
You must be signed in to change notification settings - Fork 47
Add contrib. prompt library #927
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
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,56 @@ | ||
| description: CoT pattern introduced by Wei et al. (2022) | ||
| defs: | ||
| # Chain of Thought | ||
| cot_block: | ||
| function: | ||
| question: str | ||
| reasoning: str | ||
| answer: str | ||
| return: |- | ||
| Question: ${ question } | ||
| Answer: Let's think step by step. ${ reasoning } | ||
| The answer is ${ answer } | ||
|
|
||
| fewshot_cot: | ||
| function: | ||
| examples: | ||
| { list: { obj: { question: str, reasoning: str, answer: str } } } | ||
| return: | ||
| text: | ||
| - for: | ||
| example: ${ examples } | ||
| repeat: | ||
| text: | ||
| - call: ${ cot_block } | ||
| args: | ||
| question: ${ example.question } | ||
| reasoning: ${ example.reasoning } | ||
| answer: ${ example.answer } | ||
| - "\n\n" | ||
| join: | ||
| with: "" | ||
|
|
||
| chain_of_thought: | ||
| function: | ||
| question: str | ||
| model: str | ||
| examples: | ||
| { list: { obj: { question: str, reasoning: str, answer: str } } } | ||
| return: | ||
| lastOf: | ||
| - call: ${ fewshot_cot } | ||
| args: | ||
| examples: ${ examples } | ||
| - "Question: ${ question }\n" | ||
| - "Answer: Let's think step by step. " | ||
| - model: ${ model } | ||
| def: answer | ||
| parameters: | ||
| max_tokens: 1024 | ||
| temperature: 0 | ||
| stop: | ||
| - "<|endoftext|>" | ||
| - "Question:" | ||
| include_stop_sequence: false | ||
| - data: | ||
| answer: ${ answer|trim } |
This file contains hidden or 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,120 @@ | ||
| description: ReAct pattern from Yao et al., [ICLR 2023](https://openreview.net/forum?id=WE_vluYUL-X) | ||
| # See alternative implementation here: https://smith.langchain.com/hub/hwchase17/react-chat | ||
| defs: | ||
| react_block: | ||
| function: | ||
| trajectory: { list: obj } | ||
| return: | ||
| text: | ||
| - for: | ||
| trajectory: ${ trajectory } | ||
| repeat: | ||
| text: | ||
| - def: type | ||
| text: ${ trajectory.keys()|first } | ||
| contribute: [] | ||
| - if: ${ type == 'question'} | ||
| then: | | ||
| Question: ${ trajectory[type]|trim } | ||
| - if: ${ type == 'task'} | ||
| then: | | ||
| Task: ${ trajectory[type]|trim } | ||
| - if: ${ type == 'thought'} | ||
| then: | | ||
| Tho: ${ trajectory[type]|trim } | ||
| - if: ${ type == 'action'} | ||
| then: | | ||
| Act: ${ trajectory[type]|trim } | ||
| - if: ${ type == 'observation'} | ||
| then: | | ||
| Obs: ${ trajectory[type]|trim } | ||
| - if: ${ type not in ['question', 'task', 'thought', 'action', 'observation'] } | ||
| then: "${ type }: ${ trajectory[type]|trim }" | ||
| - "\n" | ||
|
|
||
| react: | ||
| function: | ||
| task: str | ||
| model: str | ||
| tool_schema: { list: obj } | ||
| tools: obj | ||
| trajectories: { list: list } | ||
| return: | ||
| lastOf: | ||
| - role: system | ||
| text: | ||
| - "Today's Date: " | ||
| - lang: python | ||
| code: | | ||
| from datetime import datetime | ||
| result = datetime.today().strftime('%B %d, %Y.\n') | ||
| - | | ||
| You are a helpful assistant with access to the following function calls. Your task is to produce a sequence of function calls necessary to generate response to the user utterance. Use the following function calls as required. | ||
|
|
||
| Respond in the format {"name": function name, "arguments": dictionary of argument name and its value}. Do not use variables. | ||
|
|
||
| ${ tool_schema } | ||
| contribute: [context] | ||
| - "\n" | ||
| - for: | ||
| traj: ${ trajectories } | ||
| repeat: | ||
| text: | ||
| call: ${ react_block } | ||
| args: | ||
| trajectory: ${ traj } | ||
| - ${ task } | ||
| - def: prev_action | ||
| contribute: [] | ||
| data: none | ||
| - def: exit | ||
| contribute: [] | ||
| data: False | ||
| - def: tool_names | ||
| contribute: [] | ||
| text: ${ tool_schema|map(attribute='function.name')|list } | ||
| - repeat: | ||
| text: | ||
| - "\nTho: " | ||
| - def: thought | ||
| model: "${ model }" | ||
| contribute: [] | ||
| parameters: | ||
| stop: | ||
| - "Act:" | ||
| max_tokens: 256 | ||
| include_stop_sequence: false | ||
| - "${ thought|trim }" | ||
| - "\nAct: " | ||
| - def: action | ||
| model: "${ model }" | ||
| parser: json | ||
| parameters: | ||
| temperature: 0 | ||
| stop: ["\n", "Obs:", "<|eom_id|>"] | ||
| include_stop_sequence: false | ||
| spec: { name: str, arguments: obj } | ||
| - if: ${ action != prev_action } | ||
| then: | ||
| def: observation | ||
| if: ${ action.name.lower() != "finish" } | ||
| then: | ||
| text: | ||
| - "\nObs: " | ||
| - if: ${ action.name in tools } | ||
| then: | ||
| call: ${ tools[action.name] } | ||
| args: | ||
| arguments: ${ action.arguments } | ||
| else: "Invalid action. Valid actions are ${ tool_names[:-1]|join(', ') }, and ${ tool_names[-1] }." | ||
| # - "\n" | ||
| else: | ||
| def: exit | ||
| contribute: [] | ||
| data: True | ||
| - def: prev_action | ||
| contribute: [] | ||
| data: ${ action } | ||
| until: ${ action.name.lower() == "finish" or exit } | ||
| - data: | ||
| answer: ${ (action.arguments.answer|default("No answer found."))|trim } |
This file contains hidden or 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,162 @@ | ||
| description: ReWOO (Reasoning without observation) pattern from Xu et al., (http://arxiv.org/abs/2305.18323) | ||
| # Compared to ReAct, reduced token consumption (and thus execution time), | ||
| # by generating full chain of tools in a single pass | ||
| # see: https://github.com/langchain-ai/langgraph/blob/main/examples/rewoo/rewoo.ipynb | ||
| defs: | ||
| rewoo_block: | ||
| function: | ||
| trajectory: { list: obj } | ||
| return: | ||
| text: | ||
| - defs: | ||
| i: | ||
| data: 1 | ||
| - for: | ||
| trajectory: ${ trajectory } | ||
| repeat: | ||
| text: | ||
| - defs: | ||
| type: | ||
| text: ${ trajectory.keys()|first } | ||
| content: | ||
| text: ${ trajectory.values()|first } | ||
| - if: ${ type in ['task', 'question'] } | ||
| then: |- | ||
| Task: ${ content|trim } | ||
| - if: ${ type == 'thought'} | ||
| then: |- | ||
|
|
||
| Plan: ${ content|trim } | ||
| - if: ${ type == 'action'} | ||
| then: | ||
| text: | ||
| - " #E${ i } = ${ content|trim }" | ||
| - defs: | ||
| i: | ||
| data: ${ i+1 } | ||
| - if: ${ type == 'observation'} | ||
| then: "" | ||
| - if: ${ type not in ['question', 'task', 'thought', 'action', 'observation'] } | ||
| then: "${ type }: ${ content|trim }\n" | ||
| - "\n" | ||
|
|
||
| rewoo: | ||
| function: | ||
| task: str | ||
| model: str | ||
| tool_schema: { list: obj } | ||
| tools: obj | ||
| trajectories: { list: list } | ||
| show_plans: bool | ||
| return: | ||
| lastOf: | ||
| - | | ||
| For the following task, make plans that can solve the problem step by step. For each plan, indicate which external tool together with tool input to retrieve evidence. You can store the evidence into a variable #E that can be called by later tools. (Plan, #E1, Plan, #E2, Plan, ...) | ||
|
|
||
| Tools can be one of the following: | ||
| ${ tool_schema } | ||
| - "\n" | ||
| - for: | ||
| traj: ${ trajectories } | ||
| repeat: | ||
| text: | ||
| - call: ${ rewoo_block } | ||
| args: | ||
| trajectory: ${ traj } | ||
| - "\n" | ||
| - | | ||
| Begin! | ||
| Describe your plans with rich details. Each Plan should be followed by only one #E. | ||
|
|
||
| ${ task } | ||
| - def: PLANS | ||
| model: ${ model } | ||
| contribute: [] | ||
| parser: # plan, step_name, tool, tool_input | ||
| regex: 'Plan:\s*(?P<plan>(?:.|\n)*?)\s*(?P<step_name>#E\d+)\s*=\s*(?P<act>\{.+\})' | ||
| mode: findall | ||
| parameters: | ||
| temperature: 0 | ||
| stop: | ||
| - "<|endoftext|>" | ||
| - "\n\n" | ||
| - "Task:" | ||
| include_stop_sequence: false | ||
| max_tokens: 1024 | ||
| - if: ${ show_plans } | ||
| contribute: [result, context] | ||
| then: | ||
| text: | ||
| - "\n\n--- Raw plans ---\n" | ||
| - ${ PLANS } | ||
| - "\n\n--- Extracted Blueprint ---\n" | ||
| - for: | ||
| plan: ${ PLANS } | ||
| repeat: | ||
| text: | ||
| - "Plan: ${ plan[0] }\n" | ||
| - "${ plan[1] } = ${ plan[2] }\n" | ||
| - "----------------------------\n\n" | ||
| - defs: | ||
| SOLUTION: | ||
| text: "No plans found." | ||
| output: | ||
| data: {} | ||
| plans: | ||
| for: | ||
| plan: ${ PLANS } | ||
| repeat: | ||
| lastOf: | ||
| - defs: | ||
| PLAN: ${ plan[0] } | ||
| ID: ${ plan[1] } | ||
| ACTION_RAW: ${ plan[2] } | ||
| ACTION: | ||
| parser: json | ||
| lang: python | ||
| code: |- | ||
| for k,v in output.items(): | ||
| if k in ACTION_RAW: | ||
| ACTION_RAW = ACTION_RAW.replace(k, v) | ||
| result = ACTION_RAW | ||
| tool_output: | ||
| if: ${ ACTION.name in tools } | ||
| then: | ||
| call: ${ tools[ACTION.name] } | ||
| args: | ||
| arguments: ${ ACTION.arguments } | ||
| else: "Invalid action. Valid actions are ${ tools.keys() }" | ||
| - def: output | ||
| lang: python | ||
| contribute: [] | ||
| code: | | ||
| output[ID] = str(tool_output) | ||
| result = output | ||
| - | | ||
| Plan: ${ PLAN } | ||
| Evidence: ${ tool_output } | ||
| - if: ${ plans is not none and plans|length > 0 } | ||
| then: | ||
| text: | ||
| - "\n\n" | ||
| - def: solution_input | ||
| text: |- | ||
| Solve the following task or problem. To solve the problem, we have made step-by-step Plan and retrieved corresponding Evidence to each Plan. Use them with caution since long evidence might contain irrelevant information. | ||
|
|
||
| ${ plans|join } | ||
| Now solve the question or task according to provided Evidence above. Respond with the answer directly with no extra words. | ||
|
|
||
| ${ task } | ||
| Response: | ||
| - def: SOLUTION | ||
| model: ${ model } | ||
| parameters: | ||
| temperature: 0 | ||
| stop: | ||
| - "<|endoftext|>" | ||
| include_stop_sequence: false | ||
| max_tokens: 1024 | ||
| input: | ||
| text: ${ solution_input } | ||
| - data: | ||
| answer: ${ SOLUTION|trim } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: line 31, you could write
with: \n\nand remove those newlines from line 29. Also remove text from line 23 (the body is simply a call).