Skip to content

Commit 6525889

Browse files
committed
✨cleanup examples
1 parent 1f62d1d commit 6525889

9 files changed

Lines changed: 18 additions & 15 deletions

File tree

examples/analyze_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from codeinterpreterapi import CodeInterpreterSession, File
22

33

4-
async def main():
4+
async def main() -> None:
55
# context manager for start/stop of the session
66
async with CodeInterpreterSession() as session:
77
# define the user request

examples/chat_history_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from codeinterpreterapi import CodeInterpreterSession # noqa: E402
77

88

9-
def main():
9+
def main() -> None:
1010
session_id = None
1111

1212
session = CodeInterpreterSession()
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import chainlit as cl
1+
import chainlit as cl # type: ignore
22
from codeinterpreterapi import CodeInterpreterSession
33
from codeinterpreterapi import File as CIFile
44

5-
UPLOADED_FILES = []
5+
UPLOADED_FILES: list[CIFile] = []
6+
67

78
@cl.action_callback("upload_file")
8-
async def on_action(action):
9+
async def on_action(action: cl.Action) -> None:
910
files = None
1011

1112
# Wait for the user to upload a file
@@ -25,8 +26,9 @@ async def on_action(action):
2526
).send()
2627
await action.remove()
2728

29+
2830
@cl.on_chat_start
29-
async def start_chat():
31+
async def start_chat() -> None:
3032
actions = [
3133
cl.Action(name="upload_file", value="example_value", description="Upload file")
3234
]
@@ -35,14 +37,14 @@ async def start_chat():
3537
content="Hello, How can I assist you today", actions=actions
3638
).send()
3739

40+
3841
@cl.on_message
39-
async def run_conversation(user_message: str):
42+
async def run_conversation(user_message: str) -> None:
4043
session = CodeInterpreterSession()
4144
await session.astart()
4245

4346
files = [CIFile(name=it.name, content=it.content) for it in UPLOADED_FILES]
4447

45-
4648
response = await session.agenerate_response(user_message, files=files)
4749
elements = [
4850
cl.Image(
@@ -61,4 +63,4 @@ async def run_conversation(user_message: str):
6163
actions=actions,
6264
).send()
6365

64-
await session.astop()
66+
await session.astop()
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def create_temp_folder() -> str:
1616
return temp_folder
1717

1818

19-
async def get_images(prompt: str, files: Optional[list] = None):
19+
async def get_images(prompt: str, files: Optional[list] = None) -> list:
2020
if files is None:
2121
files = []
2222
with st.chat_message("user"): # type: ignore
@@ -53,3 +53,4 @@ async def get_images(prompt: str, files: Optional[list] = None):
5353
f,
5454
file_name="archive.zip",
5555
)
56+
return response.files

examples/plot_sin_wave.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from codeinterpreterapi import CodeInterpreterSession
22

33

4-
async def main():
4+
async def main() -> None:
55
async with CodeInterpreterSession() as session:
66
response = await session.agenerate_response(
77
"Plot a sin wave and show it to me."

examples/show_bitcoin_chart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from codeinterpreterapi import CodeInterpreterSession
44

55

6-
def main():
6+
def main() -> None:
77
with CodeInterpreterSession(local=True) as session:
88
currentdate = datetime.now().strftime("%Y-%m-%d")
99

examples/use_additional_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class ExampleKnowledgeBaseTool(BaseTool):
1717
name: str = "salary_database"
1818
description: str = "Use to get salary data of company employees"
1919

20-
def _run(self, *args, **kwargs):
20+
def _run(self, *args: Any, **kwargs: Any) -> Any:
2121
raise NotImplementedError()
2222

23-
async def _arun(self, *args, **kwargs: Any) -> Any:
23+
async def _arun(self, *args: Any, **kwargs: Any) -> Any:
2424
f = io.StringIO()
2525
writer = csv.writer(f)
2626
writer.writerow(["month", "employee", "salary"])
@@ -31,7 +31,7 @@ async def _arun(self, *args, **kwargs: Any) -> Any:
3131
return f.getvalue()
3232

3333

34-
async def main():
34+
async def main() -> None:
3535
async with CodeInterpreterSession(
3636
additional_tools=[ExampleKnowledgeBaseTool()]
3737
) as session:

0 commit comments

Comments
 (0)