Shroominic commited on
Commit
f8634b0
·
1 Parent(s): 8ae5da0

✨ add iris example

Browse files
Files changed (2) hide show
  1. README.md +48 -11
  2. examples/assets/iris_analysis.png +0 -0
README.md CHANGED
@@ -11,7 +11,7 @@ You can run everything local except the LLM using your own OpenAI API Key.
11
  - Internet access and auto Python package installation
12
  - Input `text + files` -> Receive `text + files`
13
  - Conversation Memory: respond based on previous inputs
14
- - Run everything local except the OpenAI API (OpenOrca or others coming soon)
15
  - Use CodeBox API for easy scaling in production (coming soon)
16
 
17
  ## Installation
@@ -24,12 +24,14 @@ pip install codeinterpreterapi
24
 
25
  ## Usage
26
 
 
 
27
  ```python
28
  from codeinterpreterapi import CodeInterpreterSession
29
 
30
 
31
  async def main():
32
- # start a session
33
  session = CodeInterpreterSession()
34
  await session.astart()
35
 
@@ -37,29 +39,64 @@ async def main():
37
  output = await session.generate_response(
38
  "Plot the bitcoin chart of 2023 YTD"
39
  )
40
- # show output image in default image viewer
41
- file = output.files[0]
42
- file.show_image()
43
 
44
- # show output text
45
- print("AI: ", output.content)
 
 
46
 
47
  # terminate the session
48
  await session.astop()
49
 
50
 
51
  if __name__ == "__main__":
52
- import asyncio, os
53
- os.environ["OPENAI_API_KEY"] = "sk-*********" # or .env file
54
-
55
  asyncio.run(main())
56
 
57
  ```
58
 
59
- ## Output
60
 
61
  ![Bitcoin YTD](https://github.com/shroominic/codeinterpreter-api/blob/main/examples/assets/bitcoin_chart.png?raw=true)
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  ## Production
64
 
65
  In case you want to deploy to production you can use the CodeBox API for easy scaling.
 
11
  - Internet access and auto Python package installation
12
  - Input `text + files` -> Receive `text + files`
13
  - Conversation Memory: respond based on previous inputs
14
+ - Run everything local except the OpenAI API (OpenOrca or others maybe soon)
15
  - Use CodeBox API for easy scaling in production (coming soon)
16
 
17
  ## Installation
 
24
 
25
  ## Usage
26
 
27
+ Make sure to set the `OPENAI_API_KEY` environment variable (or use a `.env` file)
28
+
29
  ```python
30
  from codeinterpreterapi import CodeInterpreterSession
31
 
32
 
33
  async def main():
34
+ # create a session
35
  session = CodeInterpreterSession()
36
  await session.astart()
37
 
 
39
  output = await session.generate_response(
40
  "Plot the bitcoin chart of 2023 YTD"
41
  )
 
 
 
42
 
43
+ # ouput the response (text + image)
44
+ print("AI: ", response.content)
45
+ for file in response.files:
46
+ file.show_image()
47
 
48
  # terminate the session
49
  await session.astop()
50
 
51
 
52
  if __name__ == "__main__":
53
+ import asyncio
54
+ # run the async function
 
55
  asyncio.run(main())
56
 
57
  ```
58
 
59
+ ### Chart Output
60
 
61
  ![Bitcoin YTD](https://github.com/shroominic/codeinterpreter-api/blob/main/examples/assets/bitcoin_chart.png?raw=true)
62
 
63
+ ## Dataset Analysis
64
+
65
+ ```python
66
+ from codeinterpreterapi import CodeInterpreterSession
67
+ from codeinterpreterapi.schema import File
68
+
69
+
70
+ async def main():
71
+ # context manager for auto start/stop of the session
72
+ async with CodeInterpreterSession() as session:
73
+ # define the user request
74
+ user_request = "Analyze this dataset and plot something interesting about it."
75
+ files = [
76
+ File.from_path("examples/assets/iris.csv"),
77
+ ]
78
+
79
+ # generate the response
80
+ response = await session.generate_response(
81
+ user_request, files=files
82
+ )
83
+
84
+ # output to the user
85
+ print("AI: ", response.content)
86
+ for file in response.files:
87
+ file.show_image()
88
+
89
+
90
+ if __name__ == "__main__":
91
+ import asyncio
92
+
93
+ asyncio.run(main())
94
+ ```
95
+
96
+ ### Iris Output
97
+
98
+ ![Iris Dataset Analysis](https://github.com/shroominic/codeinterpreter-api/blob/main/examples/assets/iris_analysis.png?raw=true)
99
+
100
  ## Production
101
 
102
  In case you want to deploy to production you can use the CodeBox API for easy scaling.
examples/assets/iris_analysis.png ADDED