Skip to content

Commit

Permalink
move reasoning steps of new thorough decision strategy into separate …
Browse files Browse the repository at this point in the history
…object to keep the same two decision/reasoning result fields as in the default strategy
  • Loading branch information
Benjoyo committed Oct 16, 2023
1 parent e8ded50 commit 0da0284
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
50 changes: 29 additions & 21 deletions python/src/gpt/chains/decide_chain/openai_functions/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,36 @@ def get_cot_decision_output_schema(
possible_values: Optional[List] = None
):
return {
"relevantFacts": {
"type": "array",
"items": {
"type": "string",
"description": "A discrete fact"
"reasoning": {
"type": "object",
"properties": {
"relevantFacts": {
"type": "array",
"items": {
"type": "string",
"description": "A discrete fact"
}
},
"deducedInformation": {
"type": "array",
"items": {
"type": "string",
"description": "Additional information that can be deduced from the relevantFacts"
}
},
"reasoningSteps": {
"type": "array",
"items": {
"type": "string",
"description": "A discrete reasoning step. Do not perform multiple steps in one. Be very fine-grained and use discrete steps/items."
}
},
"finalReasoning": {
"type": "string",
"description": "concise description of the final reasoning behind the decision"
}
}
},
"deducedInformation": {
"type": "array",
"items": {
"type": "string",
"description": "Additional information that can be deduced from the relevantFacts"
}
},
"reasoningSteps": {
"type": "array",
"items": {
"type": "string",
"description": "A discrete reasoning step. Do not perform multiple steps in one. Be very fine-grained and use discrete steps/items."
}
},
"finalReasoning": "concise description of the final reasoning behind the decision",
"decision": {
"description": "the final decision value, may be null if no decision was possible",
"type": output_type,
Expand Down Expand Up @@ -89,7 +97,7 @@ def create_openai_functions_decide_chain(
template="Decision stored, continue with next task.",
)] if strategy == 'cot' else [])
+ [HumanMessagePromptTemplate.from_template(
USER_MESSAGE_TEMPLATE.format(task=instructions)
USER_MESSAGE_TEMPLATE.format(task=instructions, output_type=output_type)
)]
)

Expand Down
5 changes: 3 additions & 2 deletions python/src/gpt/chains/decide_chain/openai_functions/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Remember to respect the enum of possible decision values, if given!"""

ONE_SHOT_FUNCTION_CALL_ARG = '{"relevantFacts": ["The season is Fall", "The number of guests is 26", "The occasion is a House Party", "The budget is low"], "deducedInformation": ["Fall season usually calls for warm, hearty meals", "A low budget means we need to choose a dish that is cost-effective", "The number of guests suggests we need a dish that can be easily prepared in large quantities", "The occasion of a house party does not call for a special or extravagant dish."], "reasoningSteps": ["1. Given the Fall season, a warm, hearty meal like Spareribs, Roastbeef, Dry Aged Gourmet Steak or Stew would be appropriate", "2. Considering the low budget, Stew would be more cost-effective than Spareribs, Roastbeef or Dry Aged Gourmet Steak.", "3. Given the number of guests, a dish that can be easily prepared in large quantities like a Stew would be suitable", "4. Considering all factors (warm and hearty for Fall, cost-effective for a low budget, and easily prepared in large quantities for a house party) Stew seems to be the best choice"], "finalReasoning": "Stew is the best choice as it meets all the requirements: it\'s a warm, hearty meal suitable for Fall, it\'s cost-effective, and it can be easily prepared in large quantities for a house party.", "decision": "Stew"}'
ONE_SHOT_FUNCTION_CALL_ARG = '{"reasoning": {"relevantFacts": ["The season is Fall", "The number of guests is 26", "The occasion is a House Party", "The budget is low"], "deducedInformation": ["Fall season usually calls for warm, hearty meals", "A low budget means we need to choose a dish that is cost-effective", "The number of guests suggests we need a dish that can be easily prepared in large quantities", "The occasion of a house party does not call for a special or extravagant dish."], "reasoningSteps": ["1. Given the Fall season, a warm, hearty meal like Spareribs, Roastbeef, Dry Aged Gourmet Steak or Stew would be appropriate", "2. Considering the low budget, Stew would be more cost-effective than Spareribs, Roastbeef or Dry Aged Gourmet Steak.", "3. Given the number of guests, a dish that can be easily prepared in large quantities like a Stew would be suitable", "4. Considering all factors (warm and hearty for Fall, cost-effective for a low budget, and easily prepared in large quantities for a house party) Stew seems to be the best choice"], "finalReasoning": "Stew is the best choice as it meets all the requirements: it\'s a warm, hearty meal suitable for Fall, it\'s cost-effective, and it can be easily prepared in large quantities for a house party."}, "decision": "Stew"}'

USER_MESSAGE_TEMPLATE = """\
# CONTEXT
Expand All @@ -43,4 +43,5 @@
# DECISION TASK DESCRIPTION
{task}
Remember to respect the enum of possible decision values, if given!"""
Remember to respect the enum of possible decision values, if given!
Remember that the type of the final decision value must be `{output_type}`."""

0 comments on commit 0da0284

Please sign in to comment.