Skip to content

Commit

Permalink
remove double quotes from query
Browse files Browse the repository at this point in the history
  • Loading branch information
mskarlin committed Sep 10, 2024
2 parents c63181e + e7899c6 commit 878ab75
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
48 changes: 24 additions & 24 deletions paperqa/agents/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,16 @@ async def run_agent(
async def run_fake_agent(
query: QueryRequest,
docs: Docs,
on_reset_callback: Callable[[EnvironmentState], Awaitable] | None = None,
on_step_callback: (
on_env_reset_callback: Callable[[EnvironmentState], Awaitable] | None = None,
on_env_step_callback: (
Callable[[list[Message], float, bool, bool], Awaitable] | None
) = None,
**env_kwargs,
) -> tuple[Answer, AgentStatus]:
env = Environment(query, docs, **env_kwargs)
_, tools = await env.reset()
if on_reset_callback:
await on_reset_callback(env.state)
if on_env_reset_callback:
await on_env_reset_callback(env.state)

question = env.state.answer.question
search_tool = next(filter(lambda x: x.info.name == PaperSearch.TOOL_FN_NAME, tools))
Expand All @@ -252,8 +252,8 @@ async def step(tool: Tool, **call_kwargs) -> None:
tool_calls=[ToolCall.from_tool(tool, **call_kwargs)]
)
)
if on_step_callback:
await on_step_callback(obs, reward, done, truncated)
if on_env_step_callback:
await on_env_step_callback(obs, reward, done, truncated)

# Seed docs with a few keyword searches
for search in await litellm_get_search_query(
Expand Down Expand Up @@ -282,11 +282,11 @@ async def run_aviary_agent(
query: QueryRequest,
docs: Docs,
agent: ToolSelector,
on_reset_callback: Callable[[EnvironmentState], Awaitable] | None = None,
on_action_callback: (
on_env_reset_callback: Callable[[EnvironmentState], Awaitable] | None = None,
on_agent_action_callback: (
Callable[[ToolRequestMessage, BaseModel], Awaitable] | None
) = None,
on_step_callback: (
on_env_step_callback: (
Callable[[list[Message], float, bool, bool], Awaitable] | None
) = None,
**env_kwargs,
Expand All @@ -297,8 +297,8 @@ async def run_aviary_agent(
try:
async with asyncio.timeout(query.settings.agent.timeout):
obs, tools = await env.reset()
if on_reset_callback:
await on_reset_callback(env.state)
if on_env_reset_callback:
await on_env_reset_callback(env.state)

agent_state = ToolSelectorLedger(
messages=(
Expand All @@ -318,12 +318,12 @@ async def run_aviary_agent(
agent_state.messages += obs
action = await agent(agent_state.messages, tools)
agent_state.messages = [*agent_state.messages, action]
if on_action_callback:
await on_action_callback(action, agent_state)
if on_agent_action_callback:
await on_agent_action_callback(action, agent_state)

obs, reward, done, truncated = await env.step(action)
if on_step_callback:
await on_step_callback(obs, reward, done, truncated)
if on_env_step_callback:
await on_env_step_callback(obs, reward, done, truncated)
status = AgentStatus.SUCCESS # pylint: disable=redefined-outer-name
except TimeoutError:
logger.warning(
Expand All @@ -341,9 +341,9 @@ async def run_ldp_agent(
query: QueryRequest,
docs: Docs,
agent: "Agent[SimpleAgentState]",
on_reset_callback: Callable[[EnvironmentState], Awaitable] | None = None,
on_action_callback: "Callable[[OpResult[ToolRequestMessage], SimpleAgentState, float], Awaitable] | None" = None,
on_step_callback: (
on_env_reset_callback: Callable[[EnvironmentState], Awaitable] | None = None,
on_agent_action_callback: "Callable[[OpResult[ToolRequestMessage], SimpleAgentState, float], Awaitable] | None" = None, # noqa: E501
on_env_step_callback: (
Callable[[list[Message], float, bool, bool], Awaitable] | None
) = None,
**env_kwargs,
Expand All @@ -354,19 +354,19 @@ async def run_ldp_agent(
try:
async with asyncio.timeout(query.settings.agent.timeout):
obs, tools = await env.reset()
if on_reset_callback:
await on_reset_callback(env.state)
if on_env_reset_callback:
await on_env_reset_callback(env.state)

agent_state = await agent.init_state(tools=tools)

while not done:
action, agent_state, value = await agent.get_asv(agent_state, obs)
if on_action_callback:
await on_action_callback(action, agent_state, value)
if on_agent_action_callback:
await on_agent_action_callback(action, agent_state, value)

obs, reward, done, truncated = await env.step(action.value)
if on_step_callback:
await on_step_callback(obs, reward, done, truncated)
if on_env_step_callback:
await on_env_step_callback(obs, reward, done, truncated)
status = AgentStatus.SUCCESS # pylint: disable=redefined-outer-name
except TimeoutError:
logger.warning(
Expand Down
2 changes: 1 addition & 1 deletion paperqa/configs/contracrow.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"agent": {
"agent_llm": "gpt-4o-2024-08-06",
"agent_type": "OpenAIFunctionsAgent",
"agent_type": "ToolSelector",
"agent_system_prompt": "You are a helpful AI assistant.",
"agent_prompt": "Answer question: {question}\n\nSearch for papers, gather evidence, collect papers cited in evidence then re-gather evidence, and answer. Gathering evidence will do nothing if you have not done a new search or collected new papers. If you do not have enough evidence to generate a good answer, you can:\n- Search for more papers (preferred)\n- Collect papers cited by previous evidence (preferred)\n- Gather more evidence using a different phrase\nIf you search for more papers or collect new papers cited by previous evidence, remember to gather evidence again. Once you have five or more pieces of evidence from multiple sources, or you have tried a few times, call {gen_answer_tool_name} tool. The {gen_answer_tool_name} tool output is visible to the user, so you do not need to restate the answer and can simply terminate if the answer looks sufficient. The current status of evidence/papers/cost is {status}",
"search_count": 12,
Expand Down
2 changes: 1 addition & 1 deletion paperqa/configs/wikicrow.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"agent": {
"agent_llm": "gpt-4-turbo-2024-04-09",
"agent_type": "OpenAIFunctionsAgent",
"agent_type": "ToolSelector",
"agent_system_prompt": "You are a helpful AI assistant.",
"agent_prompt": "Answer question: {question}\n\nSearch for papers, gather evidence, collect papers cited in evidence then re-gather evidence, and answer. Gathering evidence will do nothing if you have not done a new search or collected new papers. If you do not have enough evidence to generate a good answer, you can:\n- Search for more papers (preferred)\n- Collect papers cited by previous evidence (preferred)\n- Gather more evidence using a different phrase\nIf you search for more papers or collect new papers cited by previous evidence, remember to gather evidence again. Once you have five or more pieces of evidence from multiple sources, or you have tried a few times, call {gen_answer_tool_name} tool. The {gen_answer_tool_name} tool output is visible to the user, so you do not need to restate the answer and can simply terminate if the answer looks sufficient. The current status of evidence/papers/cost is {status}",
"search_count": 12,
Expand Down

0 comments on commit 878ab75

Please sign in to comment.