Skip to content

Commit

Permalink
🧼 cleanup example usage
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Sep 4, 2023
1 parent 2e99626 commit 955c06d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 43 deletions.
2 changes: 1 addition & 1 deletion examples/analyze_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async def main():
]

# generate the response
response = await session.generate_response(user_request, files=files)
response = await session.agenerate_response(user_request, files=files)

# output the response (text + image)
response.show()
Expand Down
18 changes: 5 additions & 13 deletions examples/anthropic_claude.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import asyncio

from codeinterpreterapi import CodeInterpreterSession


async def run_with_claude():
async with CodeInterpreterSession(model="claude-2") as session:
result = await session.generate_response(
"Plot the nvidea stock vs microsoft stock over the last 6 months."
)
result.show()


if __name__ == "__main__":
asyncio.run(run_with_claude())
with CodeInterpreterSession(model="claude-2") as session:
result = session.generate_response(
"Plot the nvidea stock vs microsoft stock over the last 6 months."
)
result.show()
4 changes: 2 additions & 2 deletions examples/chat_history_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def main():
print("Session ID:", session.session_id)
session_id = session.session_id

response = session.generate_response_sync("Plot the bitcoin chart of 2023 YTD")
response = session.generate_response("Plot the bitcoin chart of 2023 YTD")
response.show()

del session

assert session_id is not None
session = CodeInterpreterSession.from_id(session_id)

response = session.generate_response_sync("Now for the last 5 years")
response = session.generate_response("Now for the last 5 years")
response.show()

session.stop()
Expand Down
32 changes: 12 additions & 20 deletions examples/convert_file.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
from codeinterpreterapi import CodeInterpreterSession, File


async def main():
async with CodeInterpreterSession() as session:
user_request = "Convert this dataset to excel."
files = [
File.from_path("examples/assets/iris.csv"),
]

response = await session.generate_response(user_request, files)

print("AI: ", response.content)
for file in response.files:
if file.name == "iris.xlsx":
file.save("examples/assets/iris.xlsx")


if __name__ == "__main__":
import asyncio

asyncio.run(main())
with CodeInterpreterSession() as session:
user_request = "Convert this dataset to excel."
files = [
File.from_path("examples/assets/iris.csv"),
]

response = session.generate_response(user_request, files)

print("AI: ", response.content)
for file in response.files:
if file.name == "iris.xlsx":
file.save("examples/assets/iris.xlsx")
5 changes: 3 additions & 2 deletions examples/plot_sin_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

async def main():
async with CodeInterpreterSession() as session:
response = await session.generate_response("Plot a sin wave and show it to me.")

response = await session.agenerate_response(
"Plot a sin wave and show it to me."
)
response.show()


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 @@ -7,7 +7,7 @@ def main():
with CodeInterpreterSession(local=True) as session:
currentdate = datetime.now().strftime("%Y-%m-%d")

response = session.generate_response_sync(
response = session.generate_response(
f"Plot the bitcoin chart of 2023 YTD (today is {currentdate})"
)

Expand Down
10 changes: 6 additions & 4 deletions examples/use_additional_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@


class ExampleKnowledgeBaseTool(BaseTool):
name = "salary_database"
description = "Use to get salary data of company employees"
name: str = "salary_database"
description: str = "Use to get salary data of company employees"

def _run(self, *args, **kwargs):
raise NotImplementedError()
Expand All @@ -32,8 +32,10 @@ async def _arun(self, *args, **kwargs: Any) -> Any:


async def main():
async with CodeInterpreterSession(tools=[ExampleKnowledgeBaseTool()]) as session:
response = await session.generate_response(
async with CodeInterpreterSession(
additional_tools=[ExampleKnowledgeBaseTool()]
) as session:
response = await session.agenerate_response(
"Plot chart of company employee salaries"
)

Expand Down

0 comments on commit 955c06d

Please sign in to comment.