(athena: Athena)
| 7 | |
| 8 | export default class Python extends PluginBase { |
| 9 | async load(athena: Athena) { |
| 10 | athena.registerTool( |
| 11 | { |
| 12 | name: "python/exec", |
| 13 | desc: "Executes Python code. Whenever you need to run Python code or do *any* kind of math calculations, or the user's request requires running Python code or doing math calculations, use this tool. You must print the final result to get it. Otherwise the stdout will be empty. Only use Python when it's necessary. If you already have all the information you need for some simple task, don't use Python. Whenever you need to get stock data, use Python with the yfinance package. If you need to plot something, use Python with the matplotlib package; use seaborn-v0_8-darkgrid or fivethirtyeight style and configurations of your choice (like font size, DPI=300, etc.) to get a high quality plot.", |
| 14 | args: { |
| 15 | code: { |
| 16 | type: "string", |
| 17 | desc: "Python code", |
| 18 | required: true, |
| 19 | }, |
| 20 | }, |
| 21 | retvals: { |
| 22 | stdout: { |
| 23 | type: "string", |
| 24 | desc: "Standard output of the code", |
| 25 | required: true, |
| 26 | }, |
| 27 | }, |
| 28 | }, |
| 29 | { |
| 30 | fn: async (args: Dict<any>) => { |
| 31 | return { |
| 32 | stdout: (await PythonShell.runString(args.code)).join("\n"), |
| 33 | }; |
| 34 | }, |
| 35 | explain_args: (args: Dict<any>) => ({ |
| 36 | summary: `Executing Python code...`, |
| 37 | details: args.code, |
| 38 | }), |
| 39 | explain_retvals: (args: Dict<any>, retvals: Dict<any>) => ({ |
| 40 | summary: `The Python code has finished.`, |
| 41 | details: retvals.stdout, |
| 42 | }), |
| 43 | }, |
| 44 | ); |
| 45 | athena.registerTool( |
| 46 | { |
| 47 | name: "python/exec-file", |
| 48 | desc: "Executes Python code from a file. Whenever you need to run a Python file, or the user's request requires running Python file, use this tool.", |
| 49 | args: { |
| 50 | path: { |
| 51 | type: "string", |
| 52 | desc: "Path to the Python file", |
| 53 | required: true, |
| 54 | }, |
| 55 | args: { |
| 56 | type: "array", |
| 57 | desc: "Arguments to pass to the Python file", |
| 58 | required: false, |
| 59 | of: { |
| 60 | type: "string", |
| 61 | desc: "Argument to pass", |
| 62 | required: true, |
| 63 | }, |
| 64 | }, |
| 65 | }, |
| 66 | retvals: { |
nothing calls this directly
no test coverage detected