Skip to content

Commit

Permalink
fix: remove debug print
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu007 committed Sep 7, 2024
1 parent b99b5a0 commit ad69b29
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/show_bitcoin_chart.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime

from codeinterpreterapi import CodeInterpreterSession
from codeinterpreterapi.session import CodeInterpreterSession


def main() -> None:
Expand Down
3 changes: 0 additions & 3 deletions src/codeinterpreterapi/brain/brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def run(
if isinstance(last_input, Dict):
input = self.prepare_input(last_input)
print("Brain run self.current_agent=", self.current_agent)
print("Brain run input=", input)
try:
ca = self.current_agent
if ca == AgentName.AGENT_EXECUTOR:
Expand Down Expand Up @@ -251,9 +250,7 @@ def llm_convert_to_CodeInterpreterIntermediateResult(

last_input = {}
last_input["output_str"] = output_str
print("llm_convert_to_CodeInterpreterIntermediateResult(brain) last_input=", last_input)
output = runnable.invoke(input=last_input)
print("llm_convert_to_CodeInterpreterIntermediateResult(brain) output=", output)
return output


Expand Down
2 changes: 1 addition & 1 deletion src/codeinterpreterapi/callbacks/markdown/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def on_llm_start(self, serialized: Dict[str, Any], prompts: List[str], **kwargs:
def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None:
self._write_header("LLM End")
if response.llm_output:
self._write_to_file(response.llm_output)
self._write_to_file(str(response.llm_output))
for generation in response.generations[0]:
self._write_to_file(f"```\n{generation.text}\n```\n\n")
self._write_to_file("---\n\n")
Expand Down
3 changes: 0 additions & 3 deletions src/codeinterpreterapi/crew/crew_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def run(self, inputs: BaseMessageContent, plan_list: CodeInterpreterPlanList) ->

tasks = self.create_tasks(final_goal=final_goal, plan_list=plan_list)
my_crew = Crew(agents=self.agents, tasks=tasks)
print("CodeInterpreterCrew.kickoff() crew_inputs=", last_input)
crew_output: CrewOutput = my_crew.kickoff(inputs=last_input)
result = self.llm_convert_to_CodeInterpreterIntermediateResult(crew_output, last_input, final_goal)
return result
Expand Down Expand Up @@ -124,9 +123,7 @@ def llm_convert_to_CodeInterpreterIntermediateResult(
last_input["final_goal"] = final_goal
last_input["agent_scratchpad"] = crew_output.raw
last_input["crew_output"] = crew_output.tasks_output
print("llm_convert_to_CodeInterpreterIntermediateResult last_input=", last_input)
output = runnable.invoke(input=last_input)
print("llm_convert_to_CodeInterpreterIntermediateResult output=", output)
return output


Expand Down
3 changes: 0 additions & 3 deletions src/codeinterpreterapi/crew/custom_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ def execute_task(self, task: CrewTask, context: Optional[str] = None, tools: Opt
input_dict = self.create_input_dict(task)
result = self.agent_executor.invoke(input=input_dict, config=self.ci_params.runnable_config)
result_str = MultiConverter.to_str(result)
print("execute_task result(type)=", type(result_str))
print("execute_task result=", result_str)

# TODO: return full dict when crewai is updated
return result_str

def create_input_dict(self, task: CrewTask) -> None:
# This is interface crewai <=> langchain
# Tools will be set by langchain layer.
print("task=", task)
task_description = task.description
if task.context:
task_description += f"\n\n### コンテキスト\n{task.context}"
Expand Down
18 changes: 7 additions & 11 deletions src/codeinterpreterapi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def __init__(self, agent_callback_func: callable):

def on_chain_start(self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) -> Any:
"""Run when chain starts running."""
print("AgentCallbackHandler on_chain_start")
# print("AgentCallbackHandler on_chain_start")

def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> Any:
"""Run when chain ends running."""
print("AgentCallbackHandler on_chain_end type(outputs)=", type(outputs))
print("AgentCallbackHandler on_chain_end type(outputs)=", outputs)
# print("AgentCallbackHandler on_chain_end type(outputs)=", type(outputs))
# print("AgentCallbackHandler on_chain_end type(outputs)=", outputs)
self.agent_callback_func(outputs)

def on_chat_model_start(
Expand All @@ -66,19 +66,19 @@ def on_chat_model_start(
**kwargs: Any,
) -> Any:
"""Run when chain starts running."""
print("AgentCallbackHandler on_chat_model_start")
# print("AgentCallbackHandler on_chat_model_start")

def on_chain_error(self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any) -> Any:
"""Run when chain errors."""
print("AgentCallbackHandler on_chain_error")
# print("AgentCallbackHandler on_chain_error")

def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any:
"""Run on agent action."""
print("AgentCallbackHandler on_agent_action")
# print("AgentCallbackHandler on_agent_action")

def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> Any:
"""Run on agent end."""
print("AgentCallbackHandler on_agent_finish")
# print("AgentCallbackHandler on_agent_finish")


class CodeInterpreterSession:
Expand Down Expand Up @@ -258,7 +258,6 @@ async def _ainput_handler(self, request: UserRequest) -> None:
return self._input_handler_common(request, add_content_str)

def _output_handler_pre(self, response: Any) -> str:
print("_output_handler_pre response(type)=", type(response))
output_str = MultiConverter.to_str(response)

# TODO: MultiConverterに共通化
Expand All @@ -278,7 +277,6 @@ def _output_handler_pre(self, response: Any) -> str:

def _output_handler_post(self, final_response: str) -> CodeInterpreterResponse:
"""Embed images in the response"""
print("_output_handler_post final_response(type)=", type(final_response))
for file in self.output_files:
if str(file.name) in final_response:
# rm ![Any](file.name) from the response
Expand All @@ -301,7 +299,6 @@ def _output_handler_post(self, final_response: str) -> CodeInterpreterResponse:
self.output_files = []
self.output_code_log_list = []

print("_output_handler self.brain.current_agent=", self.brain.current_agent)
response = CodeInterpreterResponse(
content=final_response,
files=output_files,
Expand Down Expand Up @@ -363,7 +360,6 @@ def generate_response(
user_request = UserRequest(content=user_msg, files=files)
try:
input_message = self._input_handler(user_request)
print("generate_response type(user_request.content)=", type(user_request.content))
# ======= ↓↓↓↓ LLM invoke ↓↓↓↓ #=======
response = self.brain.invoke(input=input_message)
# ======= ↑↑↑↑ LLM invoke ↑↑↑↑ #=======
Expand Down
1 change: 0 additions & 1 deletion src/codeinterpreterapi/thoughts/thoughts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class CodeInterpreterToT(RunnableSerializable):
tot_chain: MyToTChain = None

def __init__(self, llm=None, is_ja=True, is_simple=False):
print("XXX llm=", llm)
super().__init__()
self.tot_chain = create_tot_chain_from_llm(llm=llm, is_ja=is_ja, is_simple=is_simple)

Expand Down
4 changes: 1 addition & 3 deletions src/codeinterpreterapi/utils/multi_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,17 @@ def to_str(input_obj: Any) -> str:
elif isinstance(input_obj, CrewOutput):
input_obj = MultiConverter._process_crew_output(input_obj)
else:
print("MultiConverter to_str type(input_obj)=", type(input_obj))
print("MultiConverter to_str unknown type(input_obj)=", type(input_obj))
return str(input_obj)

# 確実にstr以外は念のため再帰
return MultiConverter.to_str(input_obj)

@staticmethod
def _process_ai_message_chunk(chunk: AIMessageChunk) -> str:
print(f"MultiConverter.to_str AIMessageChunk input_obj= {chunk}")
if chunk.content:
return chunk.content
tool_call_chunks = chunk.tool_call_chunks
print(f"MultiConverter.to_str AIMessageChunk len= {len(tool_call_chunks)}")
if tool_call_chunks:
last_chunk = tool_call_chunks[-1]
return last_chunk.get("text", str(last_chunk))
Expand Down
1 change: 0 additions & 1 deletion src/codeinterpreterapi/utils/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def complement_input(input_dict: Dict[str, Any]) -> Dict[str, Any]:

# ステップ1: キーのリマップ
for key, value in remap.items():
print("key, value =", key, value)
if key in complemented_dict:
complemented_dict[value] = complemented_dict[key]

Expand Down

0 comments on commit ad69b29

Please sign in to comment.