bioguider 0.2.20__py3-none-any.whl → 0.2.21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bioguider might be problematic. Click here for more details.
- bioguider/agents/agent_utils.py +16 -10
- bioguider/agents/collection_observe_step.py +7 -2
- bioguider/agents/collection_task_utils.py +1 -0
- bioguider/agents/consistency_collection_step.py +100 -0
- bioguider/agents/consistency_evaluation_task.py +56 -0
- bioguider/agents/consistency_evaluation_task_utils.py +13 -0
- bioguider/agents/consistency_observe_step.py +107 -0
- bioguider/agents/consistency_query_step.py +74 -0
- bioguider/agents/evaluation_userguide_task.py +10 -43
- bioguider/agents/prompt_utils.py +6 -2
- bioguider/managers/evaluation_manager.py +2 -2
- bioguider/utils/code_structure_builder.py +9 -4
- bioguider/utils/constants.py +12 -12
- bioguider/utils/{file_handler.py → python_file_handler.py} +1 -1
- bioguider/utils/r_file_handler.py +368 -0
- bioguider/utils/utils.py +34 -1
- {bioguider-0.2.20.dist-info → bioguider-0.2.21.dist-info}/METADATA +1 -1
- {bioguider-0.2.20.dist-info → bioguider-0.2.21.dist-info}/RECORD +20 -19
- bioguider/agents/consistency_collection_execute_step.py +0 -152
- bioguider/agents/consistency_collection_observe_step.py +0 -128
- bioguider/agents/consistency_collection_plan_step.py +0 -128
- bioguider/agents/consistency_collection_task.py +0 -109
- bioguider/agents/consistency_collection_task_utils.py +0 -137
- {bioguider-0.2.20.dist-info → bioguider-0.2.21.dist-info}/LICENSE +0 -0
- {bioguider-0.2.20.dist-info → bioguider-0.2.21.dist-info}/WHEEL +0 -0
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
from typing import Callable
|
|
2
|
-
|
|
3
|
-
from langchain_openai.chat_models.base import BaseChatOpenAI
|
|
4
|
-
from langchain_core.prompts import ChatPromptTemplate
|
|
5
|
-
from bioguider.agents.agent_utils import ObservationResult
|
|
6
|
-
from bioguider.agents.common_agent_2step import CommonAgentTwoSteps
|
|
7
|
-
from bioguider.agents.consistency_collection_task_utils import ConsistencyCollectionWorkflowState
|
|
8
|
-
from bioguider.agents.peo_common_step import PEOCommonStep
|
|
9
|
-
|
|
10
|
-
CONSISTENCY_EVAL_OBSERVE_SYSTEM_PROMPT = """You are an expert developer specializing in the biomedical domain.
|
|
11
|
-
|
|
12
|
-
### **Goal**
|
|
13
|
-
Your task is to collect the function, class, and method definitions and docstrings for a given user guide/API documentation.
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
### **Intermediate Steps**
|
|
18
|
-
Here are the results from previous steps:
|
|
19
|
-
{intermediate_steps}
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
### **Instructions**
|
|
24
|
-
1. Your goal is if you have enough information to evaluate the consistency of the user guide/API documentation.
|
|
25
|
-
2. Carefully review the **Goal**, **User Guide/API Documentation**, and **Intermediate Output**.
|
|
26
|
-
3. If you believe you have enough information to evaluate the consistency of the user guide/API documentation:
|
|
27
|
-
|
|
28
|
-
* Proceed with the following format:
|
|
29
|
-
|
|
30
|
-
* Provide your reasoning under **Analysis**
|
|
31
|
-
* Then give your final answer under **FinalAnswer**
|
|
32
|
-
* **FinalAnswer** format must exactly match this format:
|
|
33
|
-
**FinalAnswer**: {{"final_answer": "yes" or "no"}}
|
|
34
|
-
* Your answer **must exactly match the follwing format** (note: no JSON code block, no additional comments), **do not** make up anything:
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-
**Analysis**: your analysis here
|
|
38
|
-
**FinalAnswer**: {{"final_answer": "yes" or "no"}}
|
|
39
|
-
```
|
|
40
|
-
4. If you believe you do not have enough information to evaluate the consistency of the user guide/API documentation:
|
|
41
|
-
|
|
42
|
-
* Provide your reasoning under **Thoughts**:
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
**Thoughts**: your thoughts here
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
Be precise and support your reasoning with evidence from the input.
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
### **Notes**
|
|
53
|
-
We are collecting information over multiple rounds, your thoughts and the output of this step will be persisted, so please **do not rush to provide a Final Answer**.
|
|
54
|
-
If you find the current information insufficient, share your reasoning or thoughts instead—we’ll continue with the next round accordingly.
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
### **Input User Guide/API Documentation**
|
|
59
|
-
{user_guide_api_documentation}
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
"""
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
class ConsistencyCollectionObserveStep(PEOCommonStep):
|
|
67
|
-
def __init__(
|
|
68
|
-
self,
|
|
69
|
-
llm: BaseChatOpenAI,
|
|
70
|
-
):
|
|
71
|
-
super().__init__(llm=llm)
|
|
72
|
-
self.step_name = "Consistency Collection Observe Step"
|
|
73
|
-
|
|
74
|
-
def _build_prompt(self, state):
|
|
75
|
-
user_guide_api_documentation = state["user_guide_api_documentation"]
|
|
76
|
-
intermediate_steps = self._build_intermediate_steps(state)
|
|
77
|
-
prompt = ChatPromptTemplate.from_template(CONSISTENCY_EVAL_OBSERVE_SYSTEM_PROMPT)
|
|
78
|
-
return prompt.format(
|
|
79
|
-
user_guide_api_documentation=user_guide_api_documentation,
|
|
80
|
-
intermediate_steps=intermediate_steps,
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
def _collect_final_answer(self, state: ConsistencyCollectionWorkflowState):
|
|
84
|
-
if not ("final_answer" in state and state["final_answer"] is not None and
|
|
85
|
-
state["final_answer"].strip().lower() == "yes"):
|
|
86
|
-
return None
|
|
87
|
-
|
|
88
|
-
final_result = ""
|
|
89
|
-
if "intermediate_steps" in state and state["intermediate_steps"] is not None:
|
|
90
|
-
for i in range(len(state["intermediate_steps"])):
|
|
91
|
-
final_result += state["intermediate_steps"][i]
|
|
92
|
-
final_result += "\n\n"
|
|
93
|
-
if "step_output" in state and state["step_output"] is not None:
|
|
94
|
-
final_result += state["step_output"]
|
|
95
|
-
final_result += "\n\n"
|
|
96
|
-
|
|
97
|
-
return final_result
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def _execute_directly(self, state: ConsistencyCollectionWorkflowState):
|
|
101
|
-
system_prompt = self._build_prompt(state)
|
|
102
|
-
agent = CommonAgentTwoSteps(llm=self.llm)
|
|
103
|
-
res, _, token_usage, reasoning_process = agent.go(
|
|
104
|
-
system_prompt=system_prompt,
|
|
105
|
-
instruction_prompt="Now, let's begin the consistency collection observe step.",
|
|
106
|
-
schema=ObservationResult,
|
|
107
|
-
)
|
|
108
|
-
state["final_answer"] = res.FinalAnswer
|
|
109
|
-
analysis = res.Analysis
|
|
110
|
-
thoughts = res.Thoughts
|
|
111
|
-
state["step_analysis"] = analysis
|
|
112
|
-
state["step_thoughts"] = thoughts
|
|
113
|
-
state["step_count"] += 1
|
|
114
|
-
state["final_assembly_result"] = self._collect_final_answer(state)
|
|
115
|
-
self._print_step(
|
|
116
|
-
state,
|
|
117
|
-
step_output=f"**Observation Reasoning Process {state['step_count']}**\n{reasoning_process}"
|
|
118
|
-
)
|
|
119
|
-
self._print_step(
|
|
120
|
-
state,
|
|
121
|
-
step_output=f"Final Answer: {res.FinalAnswer if res.FinalAnswer else None}\nAnalysis: {analysis}\nThoughts: {thoughts}",
|
|
122
|
-
)
|
|
123
|
-
if state["final_assembly_result"] is not None:
|
|
124
|
-
self._print_step(
|
|
125
|
-
state,
|
|
126
|
-
step_output=f"Final Assembly Result: {state['final_assembly_result']}",
|
|
127
|
-
)
|
|
128
|
-
return state, token_usage
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
from langchain_openai.chat_models.base import BaseChatOpenAI
|
|
2
|
-
|
|
3
|
-
from langchain.tools import BaseTool
|
|
4
|
-
from langchain_core.prompts import ChatPromptTemplate, StringPromptTemplate
|
|
5
|
-
from bioguider.agents.agent_utils import (
|
|
6
|
-
convert_plan_to_string,
|
|
7
|
-
get_tool_names_and_descriptions,
|
|
8
|
-
PlanAgentResultJsonSchema,
|
|
9
|
-
PlanAgentResult,
|
|
10
|
-
)
|
|
11
|
-
from bioguider.agents.common_agent_2step import CommonAgentTwoChainSteps, CommonAgentTwoSteps
|
|
12
|
-
from bioguider.agents.consistency_collection_task_utils import ConsistencyCollectionWorkflowState
|
|
13
|
-
from bioguider.agents.peo_common_step import PEOCommonStep
|
|
14
|
-
|
|
15
|
-
CONSISTANCE_EVAL_PLAN_SYSTEM_PROMPT = ChatPromptTemplate.from_template("""### **Goal**
|
|
16
|
-
You are an expert developer specializing in the biomedical domain.
|
|
17
|
-
Your task is to collect the function, class, and method definitions and docstrings for a given user guide/API documentation.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
### **Function Tools**
|
|
22
|
-
You have access to the following function tools:
|
|
23
|
-
{tools}
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
### **Intermediate Steps**
|
|
28
|
-
Here are the results from previous steps:
|
|
29
|
-
{intermediate_steps}
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
### **Intermediate Thoughts**
|
|
34
|
-
- **Analysis**: {intermediate_analysis}
|
|
35
|
-
- **Thoughts**: {intermediate_thoughts}
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
### **Instructions**
|
|
40
|
-
1. We will iterate through multiple **Plan -> Execution -> Observation** loops as needed.
|
|
41
|
-
- All variables and tool outputs are **persisted across rounds**, so you can build on prior results.
|
|
42
|
-
- Develop your plan **incrementally**, and reflect on intermediate observations before proceeding.
|
|
43
|
-
- Limit each step to **one or two actions** — avoid trying to complete everything in a single step.
|
|
44
|
-
|
|
45
|
-
2. Your task is to evaluate the consistency of the user guide/API documentation.
|
|
46
|
-
|
|
47
|
-
3. You may use
|
|
48
|
-
- the `retrieve_function_definition_and_docstring` tool to get the function definition and docstring or,
|
|
49
|
-
- the `retrieve_class_definition_and_docstring` to get the class definition and docstring or,
|
|
50
|
-
- the `retrieve_class_and_method_definition_and_docstring` to get the class and method definition and docstring.
|
|
51
|
-
|
|
52
|
-
4. Your plan can only use the above tools, **do not** make up any tools not in the above tools list.
|
|
53
|
-
|
|
54
|
-
5. If no function, class, or method is found in the given user guide/API documentation, you should return "N/A" as an empty plan.
|
|
55
|
-
Our tools can only retrieve the **function**, **class**, **method** definition and docstring, **do not** make up any function, class, or method name.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### **Input User Guide/API Documentation**
|
|
59
|
-
{user_guide_api_documentation}
|
|
60
|
-
|
|
61
|
-
### **Output Format**
|
|
62
|
-
Your plan **must exactly match** a sequence of steps in the following format, **do not** make up anything:
|
|
63
|
-
|
|
64
|
-
Step: <tool name> # Tool name **must be one** of {tool_names}
|
|
65
|
-
Step Input: <function/class/method name>
|
|
66
|
-
Step Input: <file path, if not sure, just put "N/A">
|
|
67
|
-
|
|
68
|
-
Step: <tool name> # Tool name **must be one** of {tool_names}
|
|
69
|
-
Step Input: <function/class/method name>
|
|
70
|
-
Step Input: <file path, if not sure, just put "N/A">
|
|
71
|
-
...
|
|
72
|
-
|
|
73
|
-
...
|
|
74
|
-
""")
|
|
75
|
-
|
|
76
|
-
class ConsistencyCollectionPlanStep(PEOCommonStep):
|
|
77
|
-
"""
|
|
78
|
-
ConsistencyCollectionPlanStep is a step in the consistency collection plan process.
|
|
79
|
-
It is responsible for initializing the tools and compiling the step.
|
|
80
|
-
"""
|
|
81
|
-
|
|
82
|
-
def __init__(
|
|
83
|
-
self,
|
|
84
|
-
llm: BaseChatOpenAI,
|
|
85
|
-
custom_tools: list[BaseTool] | None = None,
|
|
86
|
-
):
|
|
87
|
-
super().__init__(llm)
|
|
88
|
-
self.step_name = "Consistency Collection Plan Step"
|
|
89
|
-
self.custom_tools = custom_tools if custom_tools is not None else []
|
|
90
|
-
|
|
91
|
-
def _prepare_system_prompt(self, state: ConsistencyCollectionWorkflowState) -> str:
|
|
92
|
-
user_guide_api_documentation = state["user_guide_api_documentation"]
|
|
93
|
-
intermediate_steps = self._build_intermediate_steps(state)
|
|
94
|
-
step_analysis, step_thoughts = self._build_intermediate_analysis_and_thoughts(state)
|
|
95
|
-
tool_names, tools_desc = get_tool_names_and_descriptions(self.custom_tools)
|
|
96
|
-
system_prompt = CONSISTANCE_EVAL_PLAN_SYSTEM_PROMPT.format(
|
|
97
|
-
tools=tools_desc,
|
|
98
|
-
intermediate_steps=intermediate_steps,
|
|
99
|
-
intermediate_analysis=step_analysis,
|
|
100
|
-
intermediate_thoughts=step_thoughts,
|
|
101
|
-
tool_names=tool_names,
|
|
102
|
-
user_guide_api_documentation=user_guide_api_documentation,
|
|
103
|
-
)
|
|
104
|
-
self._print_step(
|
|
105
|
-
state,
|
|
106
|
-
step_output="**Intermediate Step Output**\n" + intermediate_steps
|
|
107
|
-
)
|
|
108
|
-
self._print_step(
|
|
109
|
-
state,
|
|
110
|
-
step_output="**Intermediate Step Analysis**\n{step_analysis}\n**Intermediate Step Thoughts**\n{step_thoughts}",
|
|
111
|
-
)
|
|
112
|
-
return system_prompt
|
|
113
|
-
|
|
114
|
-
def _execute_directly(self, state: ConsistencyCollectionWorkflowState):
|
|
115
|
-
system_prompt = self._prepare_system_prompt(state)
|
|
116
|
-
agent = CommonAgentTwoSteps(llm=self.llm)
|
|
117
|
-
res, _, token_usage, reasoning_process = agent.go(
|
|
118
|
-
system_prompt=system_prompt,
|
|
119
|
-
instruction_prompt="Now, let's begin the consistency collection plan step.",
|
|
120
|
-
schema=PlanAgentResultJsonSchema,
|
|
121
|
-
)
|
|
122
|
-
PEOCommonStep._reset_step_state(state)
|
|
123
|
-
res = PlanAgentResult(**res)
|
|
124
|
-
self._print_step(state, step_output=f"**Reasoning Process**\n{reasoning_process}")
|
|
125
|
-
self._print_step(state, step_output=f"**Plan**\n{str(res.actions)}")
|
|
126
|
-
state["plan_actions"] = convert_plan_to_string(res)
|
|
127
|
-
|
|
128
|
-
return state, token_usage
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from typing import Callable, Optional, TypedDict
|
|
3
|
-
from langchain.prompts import ChatPromptTemplate
|
|
4
|
-
from langchain_openai.chat_models.base import BaseChatOpenAI
|
|
5
|
-
from langchain_core.messages import AIMessage
|
|
6
|
-
from langchain.tools import StructuredTool
|
|
7
|
-
from pydantic import BaseModel, Field
|
|
8
|
-
import logging
|
|
9
|
-
from langgraph.graph import StateGraph, START, END
|
|
10
|
-
|
|
11
|
-
from bioguider.agents.agent_task import AgentTask
|
|
12
|
-
from bioguider.agents.agent_tools import agent_tool
|
|
13
|
-
from bioguider.agents.agent_utils import read_file, summarize_file
|
|
14
|
-
from bioguider.agents.peo_common_step import PEOWorkflowState
|
|
15
|
-
from bioguider.agents.common_agent import CommonAgent
|
|
16
|
-
from bioguider.agents.common_agent_2step import CommonAgentTwoSteps
|
|
17
|
-
from bioguider.agents.consistency_collection_task_utils import (
|
|
18
|
-
ConsistencyCollectionWorkflowState,
|
|
19
|
-
retrieve_function_definition_and_docstring_tool,
|
|
20
|
-
retrieve_class_definition_and_docstring_tool,
|
|
21
|
-
retrieve_class_and_method_definition_and_docstring_tool,
|
|
22
|
-
retrieve_method_definition_and_docstring_tool,
|
|
23
|
-
)
|
|
24
|
-
from bioguider.agents.consistency_collection_plan_step import ConsistencyCollectionPlanStep
|
|
25
|
-
from bioguider.agents.consistency_collection_observe_step import ConsistencyCollectionObserveStep
|
|
26
|
-
from bioguider.agents.consistency_collection_execute_step import ConsistencyCollectionExecuteStep
|
|
27
|
-
from bioguider.database.code_structure_db import CodeStructureDb
|
|
28
|
-
|
|
29
|
-
logger = logging.getLogger(__name__)
|
|
30
|
-
|
|
31
|
-
class ConsistencyCollectionTask(AgentTask):
|
|
32
|
-
def __init__(
|
|
33
|
-
self,
|
|
34
|
-
llm: BaseChatOpenAI,
|
|
35
|
-
code_structure_db: CodeStructureDb,
|
|
36
|
-
step_callback: Callable | None = None,
|
|
37
|
-
):
|
|
38
|
-
super().__init__(llm=llm, step_callback=step_callback)
|
|
39
|
-
self.llm = llm
|
|
40
|
-
self.code_structure_db = code_structure_db
|
|
41
|
-
|
|
42
|
-
func_tool = retrieve_function_definition_and_docstring_tool(llm=llm, code_structure_db=code_structure_db)
|
|
43
|
-
class_tool = retrieve_class_definition_and_docstring_tool(llm=llm, code_structure_db=code_structure_db)
|
|
44
|
-
class_and_method_tool = retrieve_class_and_method_definition_and_docstring_tool(llm=llm, code_structure_db=code_structure_db)
|
|
45
|
-
method_tool = retrieve_method_definition_and_docstring_tool(llm=llm, code_structure_db=code_structure_db)
|
|
46
|
-
self.tools = [func_tool, class_tool, class_and_method_tool, method_tool]
|
|
47
|
-
self.custom_tools = [
|
|
48
|
-
StructuredTool.from_function(
|
|
49
|
-
func_tool.run,
|
|
50
|
-
description=func_tool.__class__.__doc__,
|
|
51
|
-
name=func_tool.__class__.__name__,
|
|
52
|
-
),
|
|
53
|
-
StructuredTool.from_function(
|
|
54
|
-
class_tool.run,
|
|
55
|
-
description=class_tool.__class__.__doc__,
|
|
56
|
-
name=class_tool.__class__.__name__,
|
|
57
|
-
),
|
|
58
|
-
StructuredTool.from_function(
|
|
59
|
-
class_and_method_tool.run,
|
|
60
|
-
description=class_and_method_tool.__class__.__doc__,
|
|
61
|
-
name=class_and_method_tool.__class__.__name__,
|
|
62
|
-
),
|
|
63
|
-
StructuredTool.from_function(
|
|
64
|
-
method_tool.run,
|
|
65
|
-
description=method_tool.__class__.__doc__,
|
|
66
|
-
name=method_tool.__class__.__name__,
|
|
67
|
-
),
|
|
68
|
-
]
|
|
69
|
-
|
|
70
|
-
self.steps = [
|
|
71
|
-
ConsistencyCollectionPlanStep(llm=llm, custom_tools=self.custom_tools),
|
|
72
|
-
ConsistencyCollectionExecuteStep(llm=llm, code_structure_db=code_structure_db, custom_tools=self.custom_tools),
|
|
73
|
-
ConsistencyCollectionObserveStep(llm=llm)
|
|
74
|
-
]
|
|
75
|
-
|
|
76
|
-
def _compile(self, repo_path: str, gitignore_path: str):
|
|
77
|
-
def check_observe_step(state: ConsistencyCollectionWorkflowState):
|
|
78
|
-
if "final_answer" in state and state["final_answer"] is not None:
|
|
79
|
-
return END
|
|
80
|
-
return "plan_step"
|
|
81
|
-
def check_plan_step(state: ConsistencyCollectionWorkflowState):
|
|
82
|
-
if "plan_actions" in state and state["plan_actions"] is not None and len(state["plan_actions"]) > 0:
|
|
83
|
-
return "execute_step"
|
|
84
|
-
return END
|
|
85
|
-
|
|
86
|
-
graph = StateGraph(ConsistencyCollectionWorkflowState)
|
|
87
|
-
graph.add_node("plan_step", self.steps[0].execute)
|
|
88
|
-
graph.add_node("execute_step", self.steps[1].execute)
|
|
89
|
-
graph.add_node("observe_step", self.steps[2].execute)
|
|
90
|
-
graph.add_edge(START, "plan_step")
|
|
91
|
-
graph.add_conditional_edges("plan_step", check_plan_step, {"execute_step", END})
|
|
92
|
-
graph.add_edge("execute_step", "observe_step")
|
|
93
|
-
graph.add_conditional_edges("observe_step", check_observe_step, {"plan_step", END})
|
|
94
|
-
|
|
95
|
-
self.graph = graph.compile()
|
|
96
|
-
|
|
97
|
-
def collect(self, user_guide_api_documentation: str) -> tuple[bool, str | None]:
|
|
98
|
-
s = self._go_graph({
|
|
99
|
-
"user_guide_api_documentation": user_guide_api_documentation,
|
|
100
|
-
"step_count": 0,
|
|
101
|
-
})
|
|
102
|
-
# analyze the final assembly result
|
|
103
|
-
if "final_assembly_result" in s and s["final_assembly_result"] is not None:
|
|
104
|
-
self._print_step(step_name="Final Assembly Result")
|
|
105
|
-
self._print_step(step_output=s["final_assembly_result"])
|
|
106
|
-
return True, s["final_assembly_result"]
|
|
107
|
-
else:
|
|
108
|
-
return False, s["thoughts"] if "thoughts" in s else None
|
|
109
|
-
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
from typing import Callable, Optional, TypedDict
|
|
4
|
-
from langchain_core.prompts import ChatPromptTemplate
|
|
5
|
-
from langchain_openai.chat_models.base import BaseChatOpenAI
|
|
6
|
-
from langchain_core.messages import AIMessage
|
|
7
|
-
from pydantic import BaseModel, Field
|
|
8
|
-
import logging
|
|
9
|
-
|
|
10
|
-
from bioguider.agents.agent_tools import agent_tool
|
|
11
|
-
from bioguider.database.code_structure_db import CodeStructureDb
|
|
12
|
-
|
|
13
|
-
logger = logging.getLogger(__name__)
|
|
14
|
-
|
|
15
|
-
class ConsistencyCollectionWorkflowState(TypedDict):
|
|
16
|
-
user_guide_api_documentation: str
|
|
17
|
-
step_output_callback: Optional[Callable]
|
|
18
|
-
intermediate_steps: Optional[str]
|
|
19
|
-
step_output: Optional[str]
|
|
20
|
-
step_analysis: Optional[str]
|
|
21
|
-
step_thoughts: Optional[str]
|
|
22
|
-
plan_actions: Optional[list[dict]]
|
|
23
|
-
|
|
24
|
-
final_answer: Optional[str]
|
|
25
|
-
final_assembly_result: Optional[str]
|
|
26
|
-
step_count: Optional[int]
|
|
27
|
-
|
|
28
|
-
class retrieve_method_definition_and_docstring_tool:
|
|
29
|
-
""" Retrieve the method definition and docstring.
|
|
30
|
-
If the method is a method of a class, you **must** put the class name as the parent name and better to put the file path as the file path of the class.
|
|
31
|
-
Args:
|
|
32
|
-
method_name str: the name of the method
|
|
33
|
-
class_name str: the name of the class that the method is in.
|
|
34
|
-
file_path str: the path of the file that the method is in. If not sure, just put "N/A"
|
|
35
|
-
Returns:
|
|
36
|
-
str: the method definition and docstring
|
|
37
|
-
"""
|
|
38
|
-
def __init__(self, llm: BaseChatOpenAI, code_structure_db: CodeStructureDb):
|
|
39
|
-
self.llm = llm
|
|
40
|
-
self.code_structure_db = code_structure_db
|
|
41
|
-
|
|
42
|
-
def run(self, method_name: str, class_name: str, file_path: str) -> str:
|
|
43
|
-
if file_path != "N/A":
|
|
44
|
-
row = self.code_structure_db.select_by_name_and_parent_and_path(method_name, class_name, file_path)
|
|
45
|
-
if row is None:
|
|
46
|
-
return "Can't retrieve method definition and docstring"
|
|
47
|
-
return f"Method: {row['name']}\nDocstring: {row['doc_string']}\nParams: {row['params']}"
|
|
48
|
-
else:
|
|
49
|
-
rows = self.code_structure_db.select_by_name_and_parent(method_name, class_name)
|
|
50
|
-
if rows is None or len(rows) == 0:
|
|
51
|
-
return "Can't retrieve method definition and docstring"
|
|
52
|
-
return f"Method: {rows[0]['name']}\nDocstring: {rows[0]['doc_string']}\nParams: {rows[0]['params']}"
|
|
53
|
-
|
|
54
|
-
class retrieve_function_definition_and_docstring_tool:
|
|
55
|
-
""" Retrieve the function definition and docstring
|
|
56
|
-
Args:
|
|
57
|
-
function_name str: the name of the function
|
|
58
|
-
file_path str: the path of the file that the function is in. If not sure, just put "N/A"
|
|
59
|
-
Returns:
|
|
60
|
-
str: the function definition and docstring
|
|
61
|
-
"""
|
|
62
|
-
def __init__(
|
|
63
|
-
self,
|
|
64
|
-
llm: BaseChatOpenAI,
|
|
65
|
-
code_structure_db: CodeStructureDb,
|
|
66
|
-
):
|
|
67
|
-
self.llm = llm
|
|
68
|
-
self.code_structure_db = code_structure_db
|
|
69
|
-
|
|
70
|
-
def run(self, function_name: str, file_path: str) -> str:
|
|
71
|
-
if file_path != "N/A":
|
|
72
|
-
row = self.code_structure_db.select_by_name_and_path(function_name, file_path)
|
|
73
|
-
if row is None:
|
|
74
|
-
return f"No such function {function_name}"
|
|
75
|
-
return f"Function: {row['name']}\nDocstring: {row['doc_string']}\nParams: {row['params']}"
|
|
76
|
-
else:
|
|
77
|
-
rows = self.code_structure_db.select_by_name(function_name)
|
|
78
|
-
if rows is None or len(rows) == 0:
|
|
79
|
-
return f"No such function {function_name}"
|
|
80
|
-
return f"Function: {rows[0]['name']}\nDocstring: {rows[0]['doc_string']}\nParams: {rows[0]['params']}"
|
|
81
|
-
|
|
82
|
-
class retrieve_class_definition_and_docstring_tool:
|
|
83
|
-
""" Retrieve the class definition and docstring
|
|
84
|
-
Args:
|
|
85
|
-
class_name str: the name of the class
|
|
86
|
-
file_path str: the path of the file that the class is in. If not sure, just put "N/A"
|
|
87
|
-
Returns:
|
|
88
|
-
str: the class definition and docstring
|
|
89
|
-
"""
|
|
90
|
-
def __init__(self, llm: BaseChatOpenAI, code_structure_db: CodeStructureDb):
|
|
91
|
-
self.llm = llm
|
|
92
|
-
self.code_structure_db = code_structure_db
|
|
93
|
-
|
|
94
|
-
def run(self, class_name: str, file_path: str) -> str:
|
|
95
|
-
if file_path != "N/A":
|
|
96
|
-
row = self.code_structure_db.select_by_name_and_path(class_name, file_path)
|
|
97
|
-
if row is None:
|
|
98
|
-
return f"No such class {class_name}"
|
|
99
|
-
return f"Class: {row['name']}\nDocstring: {row['doc_string']}\nParams: {row['params']}"
|
|
100
|
-
else:
|
|
101
|
-
rows = self.code_structure_db.select_by_name(class_name)
|
|
102
|
-
if rows is None or len(rows) == 0:
|
|
103
|
-
return f"No such class {class_name}"
|
|
104
|
-
return f"Class: {rows[0]['name']}\nDocstring: {rows[0]['doc_string']}\nParams: {rows[0]['params']}"
|
|
105
|
-
|
|
106
|
-
class retrieve_class_and_method_definition_and_docstring_tool:
|
|
107
|
-
""" Retrieve the class and all methods definition and docstring
|
|
108
|
-
Args:
|
|
109
|
-
class_name str: the name of the class
|
|
110
|
-
file_path str: the path of the file that the class is in. If not sure, just put "N/A"
|
|
111
|
-
Returns:
|
|
112
|
-
str: the class and method definition and docstring
|
|
113
|
-
"""
|
|
114
|
-
def __init__(self, llm: BaseChatOpenAI, code_structure_db: CodeStructureDb):
|
|
115
|
-
self.llm = llm
|
|
116
|
-
self.code_structure_db = code_structure_db
|
|
117
|
-
|
|
118
|
-
def run(self, class_name: str, file_path: str) -> str:
|
|
119
|
-
if file_path != "N/A":
|
|
120
|
-
row = self.code_structure_db.select_by_name_and_path(class_name, file_path)
|
|
121
|
-
if row is None:
|
|
122
|
-
return f"No such class {class_name}"
|
|
123
|
-
else:
|
|
124
|
-
rows = self.code_structure_db.select_by_name(class_name)
|
|
125
|
-
if rows is None or len(rows) == 0:
|
|
126
|
-
return f"No such class {class_name}"
|
|
127
|
-
row = rows[0]
|
|
128
|
-
|
|
129
|
-
parent_path = file_path if file_path is not None and file_path.lower() != "n/a" else row["path"]
|
|
130
|
-
methods = self.code_structure_db.select_by_parent(
|
|
131
|
-
class_name,
|
|
132
|
-
parent_path
|
|
133
|
-
)
|
|
134
|
-
method_definitions = []
|
|
135
|
-
for method in methods:
|
|
136
|
-
method_definitions.append(f"Method: {method['name']}\nDocstring: {method['doc_string']}\nParams: {method['params']}\n\n")
|
|
137
|
-
return f"Class: {row['name']}\nDocstring: {row['doc_string']}\nParams: {row['params']}\nMethods: {method_definitions}"
|
|
File without changes
|
|
File without changes
|