Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Update docs
Vasek Mlejnsky78301e712298
diff --git a/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/interactive-charts/page.mdx b/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/interactive-charts/page.mdxindex 09fb42051..a8c9d1ad1 100644--- a/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/interactive-charts/page.mdx+++ b/apps/web/src/app/(docs)/docs/code-interpreting/create-charts-visualizations/interactive-charts/page.mdx@@ -139,7 +139,7 @@ Elements:```</CodeGroup>-You can then use this data to create an interactive chart with your favorite charting library on frontend.+You can send this data to your frontend to create an interactive chart with your favorite charting library.---diff --git a/apps/web/src/app/(docs)/docs/quickstart/connect-llms/page.mdx b/apps/web/src/app/(docs)/docs/quickstart/connect-llms/page.mdxindex 21db9c8e7..65dc60696 100644--- a/apps/web/src/app/(docs)/docs/quickstart/connect-llms/page.mdx+++ b/apps/web/src/app/(docs)/docs/quickstart/connect-llms/page.mdx@@ -7,61 +7,316 @@ If the LLM doesn't support tool use, you can, for example, prompt the LLM to out- [OpenAI](#openai)- [Anthropic](#anthropic)- [Mistral](#mistral)+- [Vercel AI SDK](#vercel-ai-sdk)+- [CrewAI](#crewai)+- [LangChain](#langchain)+- [LlamaIndex](#llamaindex)----# OpenAI-You can use E2B with all the OpenAI's langauge models.+## OpenAI+{/* You can use E2B with all the OpenAI's langauge models. */}-## o1 family-TODO+{/* ### o1 family+TODO */}-## GPT-4 family & GPT-3.5 family-TODO+{/* ### GPT-4 family & GPT-3.5 family */}+<CodeGroup>+```python+# pip install openai e2b-code-interpreter+from openai import OpenAI+from e2b_code_interpreter import Sandbox----+# Create OpenAI client+client = OpenAI()+prompt = "Calculate how many r's are in the word 'strawberry'"++# Define the tools+tools = [{+ "type": "function",+ "function": {+ "name": "execute_python",+ "description": "Execute python code in a Jupyter notebook cell and return result",+ "parameters": {+ "type": "object",+ "properties": {+ "code": {+ "type": "string",+ "description": "The python code to execute in a single cell"+ }+ },+ "required": ["code"]+ }+ }+}]++# Generate text with OpenAI+response = client.chat.completions.create(+ model="gpt-4o",+ messages=[{"role": "user", "content": prompt}],+ tools=tools,+)-# Anthropic-a+# Execute the tool if it's called by the model+if response.choices[0].message.tool_calls:+ tool_call = response.choices[0].message.tool_calls[0]+ if tool_call.function.name == "execute_python":+ # Create a sandbox and execute the code+ with Sandbox() as sandbox:+ code = tool_call.function.arguments+ execution = sandbox.run_code(code)+ result = execution.text-## Claude 3 family & 3.5 family-a+ # Send the result back to the model+ response = client.chat.completions.create(+ model="gpt-4o",+ messages=[+ {"role": "user", "content": prompt},+ {"role": "function", "name": "execute_python", "content": result}+ ]+ )++print(response.choices[0].message.content)+```+</CodeGroup>----# Mistral-a+## Anthropic+<CodeGroup>+```python+# pip install anthropic e2b-code-interpreter+from anthropic import Anthropic+from e2b_code_interpreter import Sandbox++# Create Anthropic client+anthropic = Anthropic()+system_prompt = "You are a helpful assistant that can execute python code in a Jupyter notebook. Only respond with the code to be executed and nothing else. Strip backticks in code blocks."+prompt = "Calculate how many r's are in the word 'strawberry'"-## Mistral Large & Mistral Small-a+# Send messages to Anthropic API+response = anthropic.messages.create(+ model="claude-3-5-sonnet-20240620",+ max_tokens=1024,+ messages=[+ {"role": "assistant", "content": system_prompt},+ {"role": "user", "content": prompt}+ ]+)-## Codestral-a+# Extract code from response+code = response.content[0].text++# Execute code in E2B Sandbox+with Sandbox() as sandbox:+ execution = sandbox.run_code(code)+ result = execution.logs.stdout++print(result)+```+</CodeGroup>----# Fireworks+## Mistral+<CodeGroup>+```python+# pip install mistralai e2b-code-interpreter+import os+from mistralai import Mistral+from e2b_code_interpreter import Sandbox++api_key = os.environ["MISTRAL_API_KEY"]++# Create Mistral client+client = Mistral(api_key=api_key)+system_prompt = "You are a helpful assistant that can execute python code in a Jupyter notebook. Only respond with the code to be executed and nothing else. Strip backticks in code blocks."+prompt = "Calculate how many r's are in the word 'strawberry'"+# Send the prompt to the model+response = client.chat.complete(+ model="codestral-latest",+ messages=[+ {"role": "system", "content": system_prompt},+ {"role": "user", "content": prompt}+ ]+)-## Llama 3.1 405B Instruct+# Extract the code from the response+code = response.choices[0].message.content++# Execute code in E2B Sandbox+with Sandbox() as sandbox:+ execution = sandbox.run_code(code)+ result = execution.text++print(result)+```+</CodeGroup>----# TogetherAI-a+## Vercel AI SDK+Vercel's [AI SDK](https://sdk.vercel.ai) offers support for multiple different LLM providers through a unified JavaScript interface that's easy to use.++<CodeGroup>+```js+// npm install ai @ai-sdk/openai zod @e2b/code-interpreter+import { openai } from '@ai-sdk/openai'+import { generateText } from 'ai'+import z from 'zod'+import { Sandbox } from '@e2b/code-interpreter'++// Create OpenAI client+const model = openai('gpt-4o')++const prompt = "Calculate how many r's are in the word 'strawberry'"++// Generate text with OpenAI+const { text } = await generateText({+ model,+ prompt,+ tools: {+ // Define a tool that runs code in a sandbox+ codeInterpreter: {+ description: 'Execute python code in a Jupyter notebook cell and return result',+ parameters: z.object({+ code: z.string().describe('The python code to execute in a single cell'),+ }),+ execute: async ({ code }) => {+ // Create a sandbox, execute LLM-generated code, and return the result+ const sandbox = await Sandbox.create()+ const { text, results, logs, error } = await sandbox.runCode(code)+ return results+ },+ },+ },+ // This is required to feed the tool call result back to the LLM+ maxSteps: 2+})++console.log(text)+```+</CodeGroup>----# Vercel AI SDK-Vercel's AI SDK offers support for multiple different LLM providers through a unified JavaScript interface that's easy to use.+## CrewAI+[CrewAI](https://crewai.com/) is a platform for building AI agents.++<CodeGroup>+```python+# pip install crewai crewai[tools] e2b-code-interpreter+from crewai_tools import tool+from crewai import Agent, Task, Crew, LLM+from e2b_code_interpreter import Sandbox+@tool("Python interpreter tool")+def execute_python(code: str):+ """+ Execute Python code and return the results.+ """+ with Sandbox() as sandbox:+ execution = sandbox.run_code(code)+ return execution.text++# Define the agent+python_executor = Agent(+ role='Python Executor',+ goal='Execute Python code and return the results',+ backstory='You are an expert Python programmer capable of executing code and returning results.',+ tools=[execute_python],+ llm=LLM(model="gpt-4o")+)++# Define the task+execute_task = Task(+ description="Calculate how many r's are in the word 'strawberry'",+ agent=python_executor,+ expected_output="The number of r's in the word 'strawberry'"+)++# Create the crew+code_execution_crew = Crew(+ agents=[python_executor],+ tasks=[execute_task],+ verbose=True,+)++# Run the crew+result = code_execution_crew.kickoff()+print(result)+```+</CodeGroup>----# LangChain-LangChain offers support multiple different LLM providers.+## LangChain+[LangChain](https://langchain.com/) offers support multiple different LLM providers.+<CodeGroup>+```python+# pip install langchain langchain-openai e2b-code-interpreter+from langchain_openai import ChatOpenAI+from langchain_core.prompts import ChatPromptTemplate+from langchain_core.output_parsers import StrOutputParser+from e2b_code_interpreter import Sandbox++system_prompt = "You are a helpful assistant that can execute python code in a Jupyter notebook. Only respond with the code to be executed and nothing else. Strip backticks in code blocks."+prompt = "Calculate how many r's are in the word 'strawberry'"++# Create LangChain components+llm = ChatOpenAI(model="gpt-4o")+prompt_template = ChatPromptTemplate.from_messages([+ ("system", system_prompt),+ ("human", "{input}")+])++output_parser = StrOutputParser()++# Create the chain+chain = prompt_template | llm | output_parser++# Run the chain+code = chain.invoke({"input": prompt})++# Execute code in E2B Sandbox+with Sandbox() as sandbox:+ execution = sandbox.run_code(code)+ result = execution.text++print(result)+```+</CodeGroup>----# LlamaIndex-LlamaIndex offers support multiple different LLM providers.+## LlamaIndex+[LlamaIndex](https://www.llamaindex.ai/) offers support multiple different LLM providers.+<CodeGroup>+```python+from llama_index.core.tools import FunctionTool+from llama_index.llms.openai import OpenAI+from llama_index.core.agent import ReActAgent+from e2b_code_interpreter import Sandbox++# Define the tool+def execute_python(code: str):+ with Sandbox() as sandbox:+ execution = sandbox.run_code(code)+ return execution.text++e2b_interpreter_tool = FunctionTool.from_defaults(+ name="execute_python",+ description="Execute python code in a Jupyter notebook cell and return result",+ fn=execute_python+)++# Initialize LLM+llm = OpenAI(model="gpt-4o")++# Initialize ReAct agent+agent = ReActAgent.from_tools([e2b_interpreter_tool], llm=llm, verbose=True)+agent.chat("Calculate how many r's are in the word 'strawberry'")+```+</CodeGroup>+diff --git a/apps/web/src/components/Navigation/routes.tsx b/apps/web/src/components/Navigation/routes.tsxindex 401ffd3c8..d26437b8b 100644--- a/apps/web/src/components/Navigation/routes.tsx+++ b/apps/web/src/components/Navigation/routes.tsx@@ -4,9 +4,6 @@ import {MessagesSquare,} from 'lucide-react'-import logoNode from '@/images/logos/node.svg'-import logoPython from '@/images/logos/python.svg'-import Image from 'next/image'// @ts-ignore; generated by prebuild.ts@@ -72,7 +69,7 @@ export const routes: NavGroup[] = [href: '/docs/quickstart',},{- title: '* Connect LLMs to E2B',+ title: 'Connect LLMs to E2B',href: '/docs/quickstart/connect-llms',},{@@ -224,58 +221,58 @@ export const routes: NavGroup[] = [// }// ]// },- {- title: '* AI Code Execution',- items: [- {- title: '* Python',- href: '/docs/code-execution/python',- icon: <Image src={logoPython} alt="Python" width={20} height={20} />,- },- {- title: '* JavaScript',- href: '/docs/code-execution/python',- icon: <Image src={logoNode} alt="JavaScript" width={20} height={20} />,- },- {- title: '* TypeScript',- href: '/docs/code-execution/python',- },- {- title: '* Custom language',- href: '/docs/code-execution/python',- },- {- title: '* Web frameworks',- links: [- {- title: '* Next.js',- href: '/docs/code-execution/python',- },- {- title: '* React',- href: '/docs/code-execution/python',- },- {- title: '* Svelte',- href: '/docs/code-execution/python',- },- {- title: '* Vue.js',- href: '/docs/code-execution/python',- },- {- title: '* Streamlit',- href: '/docs/code-execution/python',- },- {- title: '* Gradio',- href: '/docs/code-execution/python',- },- ],- },- ],- },+ // {+ // title: '* AI Code Execution',+ // items: [+ // {+ // title: '* Python',+ // href: '/docs/code-execution/python',+ // icon: <Image src={logoPython} alt="Python" width={20} height={20} />,+ // },+ // {+ // title: '* JavaScript',+ // href: '/docs/code-execution/python',+ // icon: <Image src={logoNode} alt="JavaScript" width={20} height={20} />,+ // },+ // {+ // title: '* TypeScript',+ // href: '/docs/code-execution/python',+ // },+ // {+ // title: '* Custom language',+ // href: '/docs/code-execution/python',+ // },+ // {+ // title: '* Web frameworks',+ // links: [+ // {+ // title: '* Next.js',+ // href: '/docs/code-execution/python',+ // },+ // {+ // title: '* React',+ // href: '/docs/code-execution/python',+ // },+ // {+ // title: '* Svelte',+ // href: '/docs/code-execution/python',+ // },+ // {+ // title: '* Vue.js',+ // href: '/docs/code-execution/python',+ // },+ // {+ // title: '* Streamlit',+ // href: '/docs/code-execution/python',+ // },+ // {+ // title: '* Gradio',+ // href: '/docs/code-execution/python',+ // },+ // ],+ // },+ // ],+ // },{title: '* Sandbox',items: [@@ -365,6 +362,23 @@ export const routes: NavGroup[] = [},]},+ {+ title: '* Limits',+ items: [+ {+ title: '* Sandbox',+ href: '/docs/limits/sandbox',+ },+ {+ title: '* Filesystem',+ href: '/docs/limits/overview',+ },+ {+ title: '* File upload & download',+ href: '/docs/limits/file-upload-download',+ },+ ]+ },{title: '* Latency',items: [diff --git a/apps/web/typography.ts b/apps/web/typography.tsindex 3b84635fa..7d02ab6ad 100644--- a/apps/web/typography.ts+++ b/apps/web/typography.ts@@ -22,7 +22,8 @@ export default function typographyStyles({ theme }: PluginUtils) {'--tw-prose-th-borders': theme('colors.zinc.300'),'--tw-prose-td-borders': theme('colors.zinc.200'),- '--tw-prose-invert-body': theme('colors.zinc.400'),+ // '--tw-prose-invert-body': theme('colors.zinc.400'),+ '--tw-prose-invert-body': '#f0f0f0','--tw-prose-invert-headings': theme('colors.white'),'--tw-prose-invert-links': theme('colors.brand.400'),'--tw-prose-invert-links-hover': theme('colors.brand.500'),