Skip to content

Commit

Permalink
✨ add iris example
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Jul 16, 2023
1 parent 8ae5da0 commit f8634b0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
59 changes: 48 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You can run everything local except the LLM using your own OpenAI API Key.
- Internet access and auto Python package installation
- Input `text + files` -> Receive `text + files`
- Conversation Memory: respond based on previous inputs
- Run everything local except the OpenAI API (OpenOrca or others coming soon)
- Run everything local except the OpenAI API (OpenOrca or others maybe soon)
- Use CodeBox API for easy scaling in production (coming soon)

## Installation
Expand All @@ -24,42 +24,79 @@ pip install codeinterpreterapi

## Usage

Make sure to set the `OPENAI_API_KEY` environment variable (or use a `.env` file)

```python
from codeinterpreterapi import CodeInterpreterSession


async def main():
# start a session
# create a session
session = CodeInterpreterSession()
await session.astart()

# generate a response based on user input
output = await session.generate_response(
"Plot the bitcoin chart of 2023 YTD"
)
# show output image in default image viewer
file = output.files[0]
file.show_image()

# show output text
print("AI: ", output.content)
# ouput the response (text + image)
print("AI: ", response.content)
for file in response.files:
file.show_image()

# terminate the session
await session.astop()


if __name__ == "__main__":
import asyncio, os
os.environ["OPENAI_API_KEY"] = "sk-*********" # or .env file

import asyncio
# run the async function
asyncio.run(main())

```

## Output
### Chart Output

![Bitcoin YTD](https://github.com/shroominic/codeinterpreter-api/blob/main/examples/assets/bitcoin_chart.png?raw=true)

## Dataset Analysis

```python
from codeinterpreterapi import CodeInterpreterSession
from codeinterpreterapi.schema import File


async def main():
# context manager for auto start/stop of the session
async with CodeInterpreterSession() as session:
# define the user request
user_request = "Analyze this dataset and plot something interesting about it."
files = [
File.from_path("examples/assets/iris.csv"),
]

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

# output to the user
print("AI: ", response.content)
for file in response.files:
file.show_image()


if __name__ == "__main__":
import asyncio

asyncio.run(main())
```

### Iris Output

![Iris Dataset Analysis](https://github.com/shroominic/codeinterpreter-api/blob/main/examples/assets/iris_analysis.png?raw=true)

## Production

In case you want to deploy to production you can use the CodeBox API for easy scaling.
Expand Down
Binary file added examples/assets/iris_analysis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f8634b0

Please sign in to comment.