Skip to content

Commit

Permalink
support communicate method for agent (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: Haofei Yu <[email protected]>
  • Loading branch information
timsanders256 and lwaekfjlk authored May 11, 2024
1 parent b314f7e commit 41d15e7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
3 changes: 2 additions & 1 deletion research_town/agents/agent_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..utils.author_relation import bfs
from ..utils.paper_collection import get_bert_embedding
from .agent_prompting import (
communicate_with_multiple_researchers,
generate_ideas,
summarize_research_direction,
summarize_research_field,
Expand Down Expand Up @@ -128,7 +129,7 @@ def get_profile(self, author_name: str) -> Dict[str, Any]:
return {"info": "fail!"}

def communicate(self, message: Dict[str, str]) -> str:
return "hello"
return communicate_with_multiple_researchers(message)[0]

def read_paper(
self, external_data: Dict[str, Dict[str, List[str]]], domain: str
Expand Down
33 changes: 33 additions & 0 deletions research_town/agents/agent_prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,36 @@ def summarize_research_direction(personal_info: str) -> List[str]:
)
content = completion.choices[0].message["content"]
return [content]

def communicate_with_multiple_researchers(input: Dict[str, str]):
"""
This is a single-round chat method. One that contains a chat history can better enable
"""
single_round_chat_serialize = [f"Message from researcher named {name}: {message}" for name, message in input.items()]
single_round_chat_serialize_all = "\n".join(single_round_chat_serialize)
prompt_qa = (
"Please continue in a conversation with other fellow researchers for me, where you will address their concerns in a scholarly way. "
"Here are the messages from other researchers: {single_round_chat_serialize_all}"
)
openai.api_key = KEY
input = {"single_round_chat_serialize_all": single_round_chat_serialize_all}
prompt = prompt_qa.format_map(input)
try:
completion = openai.ChatCompletion.create(
model=llm_model,
messages=[{"role": "user", "content": prompt}],
temperature=0,
seed=42,
top_p=0,
)
except Exception:
time.sleep(20)
completion = openai.ChatCompletion.create(
model=llm_model,
messages=[{"role": "user", "content": prompt}],
temperature=0,
seed=42,
top_p=0,
)
content = completion.choices[0].message["content"]
return [content]
5 changes: 4 additions & 1 deletion tests/test_agent_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ def test_get_profile():


def test_communicate():
pass
research_agent = BaseResearchAgent("Jiaxuan You")
response = research_agent.communicate({"Alice": "I believe in the potential of using automous agents to simulate the current research pipeline."})
assert isinstance(response, str)
assert response != ""

'''
def test_read_paper():
Expand Down

0 comments on commit 41d15e7

Please sign in to comment.