clean up of v

pull/39/head
Kye 2 years ago
parent 493b061e38
commit a6b8773c59

@ -343,10 +343,10 @@ The `temperature`, `top_p`, `top_k`, and `n` parameters control the randomness a
## `CodeInterpreterTool`: ## `CodeInterpreter`:
```python ```python
tool = CodeInterpreterTool("Code Interpreter", "A tool to interpret code and generate useful outputs.") tool = CodeInterpreter("Code Interpreter", "A tool to interpret code and generate useful outputs.")
tool.run("Plot the bitcoin chart of 2023 YTD") tool.run("Plot the bitcoin chart of 2023 YTD")
# Or with file inputs # Or with file inputs
@ -358,11 +358,11 @@ To use the asynchronous version, simply replace `run` with `arun` and ensure you
```python ```python
import asyncio import asyncio
tool = CodeInterpreterTool("Code Interpreter", "A tool to interpret code and generate useful outputs.") tool = CodeInterpreter("Code Interpreter", "A tool to interpret code and generate useful outputs.")
asyncio.run(tool.arun("Plot the bitcoin chart of 2023 YTD")) asyncio.run(tool.arun("Plot the bitcoin chart of 2023 YTD"))
# Or with file inputs # Or with file inputs
asyncio.run(tool.arun("Analyze this dataset and plot something interesting about it.", ["examples/assets/iris.csv"])) asyncio.run(tool.arun("Analyze this dataset and plot something interesting about it.", ["examples/assets/iris.csv"]))
``` ```
The `CodeInterpreterTool` class is a flexible tool that uses the `CodeInterpreterSession` from the `codeinterpreterapi` package to run the code interpretation and return the result. It provides both synchronous and asynchronous methods for convenience, and ensures that exceptions are handled gracefully. The `CodeInterpreter` class is a flexible tool that uses the `CodeInterpreterSession` from the `codeinterpreterapi` package to run the code interpretation and return the result. It provides both synchronous and asynchronous methods for convenience, and ensures that exceptions are handled gracefully.

@ -3,7 +3,7 @@ from swarms.agents.tools.base import Tool, ToolException
from typing import Callable, Any, List from typing import Callable, Any, List
from codeinterpreterapi import CodeInterpreterSession, File, ToolException from codeinterpreterapi import CodeInterpreterSession, File, ToolException
class CodeInterpreterTool(Tool): class CodeInterpreter(Tool):
def __init__(self, name: str, description: str): def __init__(self, name: str, description: str):
super().__init__(name, description, self.run) super().__init__(name, description, self.run)
@ -24,7 +24,7 @@ class CodeInterpreterTool(Tool):
for file in response.files: for file in response.files:
file.show_image() file.show_image()
except Exception as e: except Exception as e:
raise ToolException(f"Error running CodeInterpreterTool: {e}") raise ToolException(f"Error running CodeInterpreter: {e}")
finally: finally:
# terminate the session # terminate the session
session.stop() session.stop()
@ -46,14 +46,14 @@ class CodeInterpreterTool(Tool):
for file in response.files: for file in response.files:
file.show_image() file.show_image()
except Exception as e: except Exception as e:
raise ToolException(f"Error running CodeInterpreterTool: {e}") raise ToolException(f"Error running CodeInterpreter: {e}")
finally: finally:
# terminate the session # terminate the session
await session.astop() await session.astop()
""" """
tool = CodeInterpreterTool("Code Interpreter", "A tool to interpret code and generate useful outputs.") tool = CodeInterpreter("Code Interpreter", "A tool to interpret code and generate useful outputs.")
tool.run("Plot the bitcoin chart of 2023 YTD") tool.run("Plot the bitcoin chart of 2023 YTD")
# Or with file inputs # Or with file inputs
@ -63,7 +63,7 @@ tool.run("Analyze this dataset and plot something interesting about it.", ["exam
import asyncio import asyncio
tool = CodeInterpreterTool("Code Interpreter", "A tool to interpret code and generate useful outputs.") tool = CodeInterpreter("Code Interpreter", "A tool to interpret code and generate useful outputs.")
asyncio.run(tool.arun("Plot the bitcoin chart of 2023 YTD")) asyncio.run(tool.arun("Plot the bitcoin chart of 2023 YTD"))
# Or with file inputs # Or with file inputs

Loading…
Cancel
Save