Skip to content

Commit 44ee6bb

Browse files
tedasdfGaoDaliealckasoc
authored
FEVER for ReAct (#39)
* First version , * Update second version * third version * four version * first version of alfworld * uploaded * done Alfworld * Final * helo helo halo * helo helo halo * helo helo halo * halo * halo * helo helo halo * hello * hello * final * asdf * asdf * halo 2 * halo final * halo halo * halo halo * asf * doctor string multiagent-of-madness * doctor string multiagent of madness * doctor string multiagent of madness * refactor * refactor * Fix Bug react function * the default should be '\n' * delete ops * string * asdf * fixed the list issues * adf * reverse coding technique * reverse coding technique * reverse coding technique * reverse coding technique * reverse coding technique * Alfword prompt * Alfword prompt + * fix bugs * Fix the error * store the fixtures in data * fixed fixtures and assets * removed code in test_environment.py * renamed notebooks * deleted tmp nb * fixed fixtures * renamed prompt * renamed prompts * removed print * small change * removed alfworld in test * small change * fixed test case * small change * remove alfworld * small change * removed tmp * auto linted * readme * readme * removed all alfworld * removed tmp --------- Co-authored-by: Gaodalie <[email protected]> Co-authored-by: alckasoc <[email protected]>
1 parent 6a1f40c commit 44ee6bb

File tree

13 files changed

+127
-84
lines changed

13 files changed

+127
-84
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
Our primary goal is to provide easy-to-use and clean functions for natural language processing tasks, enabling developers to build robust and efficient applications with ease.
99

10-
11-
1210
- Easy-to-Use Interface: Provides intuitive and user-friendly functions for rapid prototyping and development.
1311

1412
- Clean Functions: Offers clean and well-structured functions, promoting readability and maintainability of code.
@@ -40,7 +38,7 @@ Thought: Ramon Dekkers has been involved in controversies and crimes. I need to
4038
```
4139

4240

43-
Project Organization
41+
## Project Organization
4442

4543
------------
4644

@@ -78,7 +76,7 @@ Project Organization
7876
│ or model summaries.
7977
8078
├── notebooks <- Jupyter notebooks. Naming convention is a number
81-
│ (for ordering), the creator's initials, and a short `-` delimited │ description, e.g. `1.0-jqp-initial-data-exploration`.
79+
│ (for ordering), the creator's initials, and a short `-` delimited │ description, e.g. `1.0-jqp-initial-data-exploration`.
8280
8381
8482
├── references <- Data dictionaries, manuals, and all other explanatory materials.
@@ -91,6 +89,6 @@ Project Organization
9189
---------
9290

9391

94-
## Contribution
92+
## Contributing
9593

9694
If you want to contribute, please check the [contributing.md](https://github.com/alckasoc/discussion-agents/blob/main/CONTRIBUTING.md) for guidelines!

discussion_agents/cog/agent/expel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
EXPEL_REFLEXION_REACT_INSTRUCTION,
2727
RULE_PREFIX,
2828
)
29-
from discussion_agents.cog.prompts.react import REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES
29+
from discussion_agents.cog.prompts.react import HOTPOTQA_FEWSHOT_EXAMPLES
3030
from discussion_agents.cog.prompts.reflexion import (
3131
REFLEXION_REACT_INSTRUCTION,
3232
REFLEXION_REACT_REFLECT_FEWSHOT_EXAMPLES,
@@ -152,7 +152,7 @@ def generate(
152152
reranker_strategy=reranker_strategy,
153153
)["fewshots"]
154154
examples = (
155-
examples if examples else [REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES] # type: ignore
155+
examples if examples else [HOTPOTQA_FEWSHOT_EXAMPLES] # type: ignore
156156
)
157157
examples = "\n\n".join(examples + [END_OF_EXAMPLES_DELIMITER]) + "\n" # type: ignore
158158

@@ -195,7 +195,7 @@ def gather_experience(
195195
keys: List[str],
196196
strategy: str = "reflexion",
197197
prompt: str = REFLEXION_REACT_INSTRUCTION,
198-
examples: str = REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES,
198+
examples: str = HOTPOTQA_FEWSHOT_EXAMPLES,
199199
reflect_examples: str = REFLEXION_REACT_REFLECT_FEWSHOT_EXAMPLES,
200200
reflect_prompt: str = REFLEXION_REACT_REFLECT_INSTRUCTION,
201201
) -> Dict[str, Any]:
@@ -214,7 +214,7 @@ def gather_experience(
214214
- "last_attempt_and_reflexion": This strategy combines the 'last_attempt' and 'reflexion' strategies.
215215
prompt (str, optional): Prompt template string. Defaults to REFLEXION_REACT_INSTRUCTION.
216216
Must include examples, reflections, question, scratchpad, and max_steps.
217-
examples (str, optional): Fewshot examples. Defaults to REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES.
217+
examples (str, optional): Fewshot examples. Defaults to HOTPOTQA_FEWSHOT_EXAMPLES.
218218
reflect_examples (str, optional): Reflection fewshot examples. Defaults to REFLEXION_REACT_REFLECT_FEWSHOT_EXAMPLES.
219219
reflect_prompt (str, optional): Reflect prompt template string. Defaults to REFLEXION_REACT_REFLECT_INSTRUCTION.
220220
Must include examples, question, and scratchpad.

discussion_agents/cog/agent/react.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from discussion_agents.cog.functional.react import _is_halted, _prompt_agent
2525
from discussion_agents.cog.modules.memory.react import ReActMemory
2626
from discussion_agents.cog.prompts.react import (
27-
REACT_INSTRUCTION,
28-
REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES,
27+
HOTPOTQA_FEWSHOT_EXAMPLES,
28+
REACT_INSTRUCTION_HOTPOTQA,
2929
)
3030
from discussion_agents.utils.parse import parse_action, remove_newline
3131

@@ -79,8 +79,8 @@ def generate(
7979
self,
8080
question: str,
8181
reset: bool = True,
82-
examples: str = REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES,
83-
prompt: str = REACT_INSTRUCTION,
82+
examples: str = HOTPOTQA_FEWSHOT_EXAMPLES,
83+
prompt: str = REACT_INSTRUCTION_HOTPOTQA,
8484
) -> List[Tuple[str, str, str]]:
8585
"""Processes a given question through ReAct.
8686
@@ -90,8 +90,8 @@ def generate(
9090
Args:
9191
question (str): The question to be processed.
9292
reset (bool, optional): Whether to reset the internal state before processing. Defaults to True.
93-
examples (str, optional): Fewshot examples. Defaults to REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES.
94-
prompt (str, optional): Prompt template string. Defaults to REACT_INSTRUCTION. Must include question,
93+
examples (str, optional): Fewshot examples. Defaults to HOTPOTQA_FEWSHOT_EXAMPLES.
94+
prompt (str, optional): Prompt template string. Defaults to REACT_INSTRUCTION_HOTPOTQA. Must include question,
9595
scratchpad, examples, and max_steps.
9696
9797
Returns:

discussion_agents/cog/agent/reflexion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
ReflexionCoTReflector,
2828
ReflexionReActReflector,
2929
)
30-
from discussion_agents.cog.prompts.react import REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES
30+
from discussion_agents.cog.prompts.react import HOTPOTQA_FEWSHOT_EXAMPLES
3131
from discussion_agents.cog.prompts.reflexion import (
3232
REFLEXION_COT_FEWSHOT_EXAMPLES,
3333
REFLEXION_COT_FEWSHOT_EXAMPLES_NO_CONTEXT,
@@ -371,7 +371,7 @@ def generate(
371371
self,
372372
question: str,
373373
key: str,
374-
examples: str = REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES,
374+
examples: str = HOTPOTQA_FEWSHOT_EXAMPLES,
375375
strategy: Optional[str] = None,
376376
reset: bool = True,
377377
prompt: str = REFLEXION_REACT_INSTRUCTION,
@@ -386,7 +386,7 @@ def generate(
386386
Args:
387387
question (str): The question to be processed.
388388
key (str): The answer to the question.
389-
examples (str, optional): Fewshot examples. Defaults to REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES.
389+
examples (str, optional): Fewshot examples. Defaults to HOTPOTQA_FEWSHOT_EXAMPLES.
390390
strategy (Optional[str]): The reflection strategy. Can be of 3 types. Defaults to None.
391391
- "last_attempt": This strategy uses only 'question' and 'scratchpad'. The 'reflections' list is updated with the current scratchpad.
392392
- "reflexion": This strategy uses all the parameters. It adds a new reflexion generated by the language model to the 'reflections' list.

discussion_agents/cog/functional/expel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
SYSTEM_CRITIQUE_EXISTING_INSIGHTS_INSTRUCTION,
2222
SYSTEM_TEMPLATE,
2323
)
24-
from discussion_agents.cog.prompts.react import REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES
24+
from discussion_agents.cog.prompts.react import HOTPOTQA_FEWSHOT_EXAMPLES
2525
from discussion_agents.cog.prompts.reflexion import (
2626
REFLEXION_REACT_INSTRUCTION,
2727
REFLEXION_REACT_REFLECT_FEWSHOT_EXAMPLES,
@@ -37,7 +37,7 @@ def gather_experience(
3737
keys: List[str],
3838
strategy: str = "reflexion",
3939
prompt: str = REFLEXION_REACT_INSTRUCTION,
40-
examples: str = REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES,
40+
examples: str = HOTPOTQA_FEWSHOT_EXAMPLES,
4141
reflect_examples: str = REFLEXION_REACT_REFLECT_FEWSHOT_EXAMPLES,
4242
reflect_prompt: str = REFLEXION_REACT_REFLECT_INSTRUCTION,
4343
) -> Dict[str, List]:
@@ -52,7 +52,7 @@ def gather_experience(
5252
strategy (str, optional): The strategy used to generate experiences. Defaults to "reflexion" if not specified.
5353
prompt (str, optional): Prompt template string. Defaults to REFLEXION_REACT_INSTRUCTION.
5454
Must include examples, reflections, question, scratchpad, and max_steps.
55-
examples (str, optional): Fewshot examples. Defaults to REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES.
55+
examples (str, optional): Fewshot examples. Defaults to HOTPOTQA_FEWSHOT_EXAMPLES.
5656
reflect_examples (str, optional): Reflection fewshot examples. Defaults to REFLEXION_REACT_REFLECT_FEWSHOT_EXAMPLES.
5757
reflect_prompt (str, optional): Reflect prompt template string. Defaults to REFLEXION_REACT_REFLECT_INSTRUCTION.
5858
Must include examples, question, and scratchpad.

discussion_agents/cog/functional/generative_agents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from langchain.embeddings import HuggingFaceEmbeddings
1313
from langchain.prompts import PromptTemplate
1414
from langchain.retrievers import TimeWeightedVectorStoreRetriever
15-
from langchain.vectorstores import FAISS
15+
from langchain_community.vectorstores.faiss import FAISS
1616
from langchain_core.retrievers import BaseRetriever
1717

1818
from discussion_agents.utils.fetch import fetch_memories

discussion_agents/cog/functional/react.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from tiktoken import Encoding
66

77
from discussion_agents.cog.prompts.react import (
8-
REACT_INSTRUCTION,
8+
REACT_INSTRUCTION_HOTPOTQA,
99
)
1010
from discussion_agents.utils.parse import remove_newline
1111

@@ -15,7 +15,7 @@ def _build_agent_prompt(
1515
scratchpad: str,
1616
examples: str,
1717
max_steps: int,
18-
prompt: str = REACT_INSTRUCTION,
18+
prompt: str = REACT_INSTRUCTION_HOTPOTQA,
1919
) -> str:
2020
"""Constructs a prompt template for the agent.
2121
@@ -27,7 +27,7 @@ def _build_agent_prompt(
2727
scratchpad (str): Additional scratchpad information to be included.
2828
examples (str): Fewshot examples.
2929
max_steps (int): Max number of steps.
30-
prompt (str, optional): Prompt template string. Defaults to REACT_INSTRUCTION. Must include question,
30+
prompt (str, optional): Prompt template string. Defaults to REACT_INSTRUCTION_HOTPOTQA. Must include question,
3131
scratchpad, examples, and max_steps.
3232
3333
Returns:
@@ -48,7 +48,7 @@ def _prompt_agent(
4848
scratchpad: str,
4949
examples: str,
5050
max_steps: int,
51-
prompt: str = REACT_INSTRUCTION,
51+
prompt: str = REACT_INSTRUCTION_HOTPOTQA,
5252
) -> str:
5353
"""Generates a response from the LLM based on a given question and scratchpad.
5454
@@ -61,7 +61,7 @@ def _prompt_agent(
6161
scratchpad (str): Additional context or information for the language model.
6262
examples (str): Fewshot examples.
6363
max_steps (int): Maximum number of steps.
64-
prompt (str, optional): Prompt template string. Defaults to REACT_INSTRUCTION. Must include question,
64+
prompt (str, optional): Prompt template string. Defaults to REACT_INSTRUCTION_HOTPOTQA. Must include question,
6565
scratchpad, examples, and max_steps.
6666
6767
Returns:
@@ -94,7 +94,7 @@ def _is_halted(
9494
max_steps: int,
9595
max_tokens: int,
9696
enc: Encoding,
97-
prompt: str = REACT_INSTRUCTION,
97+
prompt: str = REACT_INSTRUCTION_HOTPOTQA,
9898
) -> bool:
9999
"""Determines whether the agent's operation should be halted.
100100
@@ -111,7 +111,7 @@ def _is_halted(
111111
max_steps (int): Maximum allowed steps.
112112
max_tokens (int): Maximum allowed token count.
113113
enc (Encoding): The encoder to calculate token length.
114-
prompt (str, optional): Prompt template string. Defaults to REACT_INSTRUCTION. Must include question,
114+
prompt (str, optional): Prompt template string. Defaults to REACT_INSTRUCTION_HOTPOTQA. Must include question,
115115
scratchpad, examples, and max_steps.
116116
117117
Returns:

discussion_agents/cog/prompts/react.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""ReAct prompts and fewshot examples."""
22

33

4-
REACT_INSTRUCTION = """Solve a question answering task with interleaving Thought, Action, Observation steps. Thought can reason about the current situation, and Action can be three types:
4+
# ======================================================================== HOTPOTQA ======================================================================== #
5+
6+
7+
REACT_INSTRUCTION_HOTPOTQA = """Solve a question answering task with interleaving Thought, Action, Observation steps. Thought can reason about the current situation, and Action can be three types:
58
(1) Search[entity], which searches the exact entity on Wikipedia and returns the first paragraph if it exists. If not, it will return some similar entities to search.
69
(2) Lookup[keyword], which returns the next sentence containing keyword in the last passage successfully found by Search.
710
(3) Finish[answer], which returns the answer and finishes the task.
@@ -13,7 +16,7 @@
1316
1417
Question: {question}{scratchpad}"""
1518

16-
REACT_WEBTHINK_SIMPLE6_FEWSHOT_EXAMPLES = """Question: What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?
19+
HOTPOTQA_FEWSHOT_EXAMPLES = """Question: What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?
1720
Thought 1: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado orogeny extends into, then find the elevation range of the area.
1821
Action 1: Search[Colorado orogeny]
1922
Observation 1: The Colorado orogeny was an episode of mountain building (an orogeny) in Colorado and surrounding areas.
@@ -74,3 +77,45 @@
7477
Observation 2: Leonid Anatolievich Levin is a Soviet-American mathematician and computer scientist.
7578
Thought 3: Leonid Levin is a mathematician and computer scientist. So Pavel Urysohn and Leonid Levin have the same type of work.
7679
Action 3: Finish[yes]"""
80+
81+
82+
# ======================================================================== FEVER ======================================================================== #
83+
84+
85+
REACT_INSTRUCTION_FEVER = """Determine if there is Observation that SUPPORTS or REFUTES a Claim, or if there is NOT ENOUGH INFORMATION. and Action can be two types:
86+
(1) Search[entity], which searches the exact entity on Wikipedia and returns the first paragraph if it exists. If not, it will return some similar entities to search.
87+
(3) Finish[answer], which returns the answer and finishes the task.
88+
You have a maximum of {max_steps} steps.
89+
90+
Here are some examples:
91+
{examples}
92+
(END OF EXAMPLES)
93+
94+
Question: {question}{scratchpad}"""
95+
96+
FEVER_FEWSHOT_EXAMPLES = """Claim: Nikolaj Coster-Waldau worked with the Fox Broadcasting Company.
97+
Thought 1: I need to search Nikolaj Coster-Waldau and find if he has worked with the Fox Broadcasting Company.
98+
Action 1: Search[Nikolaj Coster-Waldau]
99+
Observation 1: Nikolaj William Coster-Waldau (born 27 July 1970) is a Danish actor and producer. He graduated from the Danish National School of Performing Arts in Copenhagen in 1993,[1] and had his breakthrough role in Denmark with the film Nightwatch (1994). He played Jaime Lannister in the HBO fantasy drama series Game of Thrones, for which he received two Primetime Emmy Award nominations for Outstanding Supporting Actor in a Drama Series.. Coster-Waldau has appeared in numerous films in his native Denmark and Scandinavia, including Headhunters (2011) and A Thousand Times Good Night (2013). In the U.S, his debut film role was in the war film Black Hawk Down (2001), playing Medal of Honor recipient Gary Gordon.[2] He then played a detective in the short-lived Fox television series New Amsterdam (2008), and appeared in the 2009 Fox television film Virtuality, originally intended as a pilot.
100+
Thought 2: Because he "appeared in the 2009 Fox television film Virtuality", he should have worked with the Fox Broadcasting Company.
101+
Action 2: Finish[SUPPORTS]
102+
103+
Claim: Stranger Things is set in Bloomington, Indiana.
104+
Thought 1: I should search for Stranger Things, and see if it is set in Bloomington, Indiana.
105+
Action 1: Search[Stranger Things]
106+
Observation 1: Stranger Things is an American science fiction horror drama television series created by the Duffer Brothers. Set in the 1980s, primarily in the fictional town of Hawkins, Indiana, the series centers on a number of mysteries and supernatural events occurring around the town and their impact on an ensemble of child and adult characters.
107+
Thought 2: The observation says that it is set in a "fictional town of Hawkins, Indiana", so it is not set in Bloomington.
108+
Action 2: Finish[REFUTES]
109+
110+
Claim: Beautiful reached number two on the Billboard Hot 100 in 2003.?
111+
Thought 1: I need to search the song Beautiful and find if it reached number two on the Billboard Hot 100 in 2003.
112+
Action 1: Search[Beautiful]
113+
Observation 1: Could not find [Beautiful]. Similar: ['Beautiful', 'Beautiful, Beautiful', 'A Beautiful Mind (film)', 'Beautiful (Christina Aguilera song)', 'Life Is Beautiful'].
114+
Thought 2: From suggestions, I should search "Beautiful (Christina Aguilera song)" to find the song.
115+
Action 2: Search[Beautiful (Christina Aguilera song)]
116+
Observation 2: "Beautiful" is a song recorded by American singer Christina Aguilera for her fourth studio album, Stripped (2002).
117+
Thought 3: It does not mention Billboard, so I need to look up "Billboard Hot 100" to find if it reached number two on it in 2003.
118+
Action 3: Lookup[Billboard Hot 100]
119+
Observation 3: (Result 1 / 3) The song peaked at number two on the Billboard Hot 100 in the United States, where it was certified Gold for 500,000 units shipped.
120+
Thought 4: It only says the song peaked at number two on the Billboard Hot 100, but not if it was in 2003. I am not sure if this claim is true or not.
121+
Action 4: Finish[NOT ENOUGH INFO]"""

test_environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ def main():
2222

2323

2424
if __name__ == '__main__':
25-
main()
25+
main()

0 commit comments

Comments
 (0)