Spaces:
Runtime error
Runtime error
russkiyximik
Overhauled Code Interpreter tool by wrapping it in a new class to make it robust to agent output
138bf3e Download mycoder/src/inner/crew.py from russkiyximik/query2plot: direct link, hf CLI and curl.
- Browser
- Download file 1.9 kB
-
https://huggingface.co/spaces/russkiyximik/query2plot/resolve/main/mycoder/src/inner/crew.py
- Command line
-
hf download hf://spaces/russkiyximik/query2plot/mycoder/src/inner/crew.py
-
curl -L -o crew.py https://huggingface.co/spaces/russkiyximik/query2plot/resolve/main/mycoder/src/inner/crew.py
1.9 kB
| from crewai import Agent, Crew, Process, Task | |
| from crewai.project import CrewBase, agent, crew, task | |
| from .paths import MARKDOWN_OUTPUT_FILE, PLOT_OUTPUT_FILE | |
| class Coder(): | |
| """Coder crew""" | |
| agents_config = 'config/agents.yaml' | |
| tasks_config = 'config/tasks.yaml' | |
| # One click install for Docker Desktop: | |
| #https://docs.docker.com/desktop/ | |
| def coder(self) -> Agent: | |
| from src.inner.tools.custom_tool import ( | |
| ExtractSchema, | |
| ResultAwareCodeInterpreterTool, | |
| ) | |
| code_interpreter = ResultAwareCodeInterpreterTool(unsafe_mode=True) | |
| return Agent( | |
| config=self.agents_config['coder'], | |
| verbose=True, | |
| #allow_code_execution=True, | |
| #code_execution_mode="unsafe", # Currently doesn't use Docker for safety | |
| max_execution_time=300, | |
| max_retry_limit=5 , | |
| tools=[ExtractSchema(), code_interpreter], | |
| ) | |
| def coding_task(self) -> Task: | |
| task_config = dict(self.tasks_config['coding_task']) | |
| task_config['description'] = ( | |
| f"{task_config['description']}\n\n" | |
| f"Save plots to '{PLOT_OUTPUT_FILE}'. " | |
| f"Write the markdown output to '{MARKDOWN_OUTPUT_FILE}'." | |
| ) | |
| task_config['output_file'] = str(MARKDOWN_OUTPUT_FILE) | |
| return Task( | |
| config=task_config, | |
| ) | |
| # @task | |
| # def image_task(self) -> Task: | |
| # return Task( | |
| # config=self.tasks_config['image_task'], | |
| # ) | |
| def crew(self) -> Crew: | |
| """Creates the Coder crew""" | |
| return Crew( | |
| agents=self.agents, | |
| tasks=self.tasks, | |
| process=Process.sequential, | |
| verbose=True, | |
| memory=True, | |
| ) | |
| # TO DO: Change memory to ollama from default (OpenAI) | |