-
-
Notifications
You must be signed in to change notification settings - Fork 391
Expand file tree
/
Copy pathuse_additional_tools.py
More file actions
49 lines (36 loc) · 1.3 KB
/
use_additional_tools.py
File metadata and controls
49 lines (36 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
The exciting part about this example is
that the code interpreter has internet access
so it can download the bitcoin chart from yahoo finance
and plot it for you
"""
import csv
import io
from typing import Any
from langchain_core.tools import BaseTool
from codeinterpreterapi import CodeInterpreterSession
class ExampleKnowledgeBaseTool(BaseTool):
name: str = "salary_database"
description: str = "Use to get salary data of company employees"
def _run(self, *args: Any, **kwargs: Any) -> Any:
raise NotImplementedError()
async def _arun(self, *args: Any, **kwargs: Any) -> Any:
f = io.StringIO()
writer = csv.writer(f)
writer.writerow(["month", "employee", "salary"])
writer.writerow(["march 2022", "Jan", "1200"])
writer.writerow(["march 2022", "Ola", "1500"])
writer.writerow(["april 2022", "Jan", "1800"])
writer.writerow(["april 2022", "Ola", "2000"])
return f.getvalue()
async def main() -> None:
async with CodeInterpreterSession(
additional_tools=[ExampleKnowledgeBaseTool()]
) as session:
response = await session.agenerate_response(
"Plot chart of company employee salaries"
)
response.show()
if __name__ == "__main__":
import asyncio
asyncio.run(main())