Skip to content

Commit

Permalink
✨cleanup examples
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Dec 12, 2023
1 parent 1f62d1d commit 6525889
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/analyze_dataset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from codeinterpreterapi import CodeInterpreterSession, File


async def main():
async def main() -> None:
# context manager for start/stop of the session
async with CodeInterpreterSession() as session:
# define the user request
Expand Down
2 changes: 1 addition & 1 deletion examples/chat_history_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from codeinterpreterapi import CodeInterpreterSession # noqa: E402


def main():
def main() -> None:
session_id = None

session = CodeInterpreterSession()
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 9 additions & 7 deletions frontend/chainlitui.py → examples/frontend/chainlitui.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import chainlit as cl
import chainlit as cl # type: ignore
from codeinterpreterapi import CodeInterpreterSession
from codeinterpreterapi import File as CIFile

UPLOADED_FILES = []
UPLOADED_FILES: list[CIFile] = []


@cl.action_callback("upload_file")
async def on_action(action):
async def on_action(action: cl.Action) -> None:
files = None

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


@cl.on_chat_start
async def start_chat():
async def start_chat() -> None:
actions = [
cl.Action(name="upload_file", value="example_value", description="Upload file")
]
Expand All @@ -35,14 +37,14 @@ async def start_chat():
content="Hello, How can I assist you today", actions=actions
).send()


@cl.on_message
async def run_conversation(user_message: str):
async def run_conversation(user_message: str) -> None:
session = CodeInterpreterSession()
await session.astart()

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


response = await session.agenerate_response(user_message, files=files)
elements = [
cl.Image(
Expand All @@ -61,4 +63,4 @@ async def run_conversation(user_message: str):
actions=actions,
).send()

await session.astop()
await session.astop()
3 changes: 2 additions & 1 deletion frontend/utils.py → examples/frontend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create_temp_folder() -> str:
return temp_folder


async def get_images(prompt: str, files: Optional[list] = None):
async def get_images(prompt: str, files: Optional[list] = None) -> list:
if files is None:
files = []
with st.chat_message("user"): # type: ignore
Expand Down Expand Up @@ -53,3 +53,4 @@ async def get_images(prompt: str, files: Optional[list] = None):
f,
file_name="archive.zip",
)
return response.files
2 changes: 1 addition & 1 deletion examples/plot_sin_wave.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from codeinterpreterapi import CodeInterpreterSession


async def main():
async def main() -> None:
async with CodeInterpreterSession() as session:
response = await session.agenerate_response(
"Plot a sin wave and show it to me."
Expand Down
2 changes: 1 addition & 1 deletion examples/show_bitcoin_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from codeinterpreterapi import CodeInterpreterSession


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

Expand Down
6 changes: 3 additions & 3 deletions examples/use_additional_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class ExampleKnowledgeBaseTool(BaseTool):
name: str = "salary_database"
description: str = "Use to get salary data of company employees"

def _run(self, *args, **kwargs):
def _run(self, *args: Any, **kwargs: Any) -> Any:
raise NotImplementedError()

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


async def main():
async def main() -> None:
async with CodeInterpreterSession(
additional_tools=[ExampleKnowledgeBaseTool()]
) as session:
Expand Down

0 comments on commit 6525889

Please sign in to comment.