.ipynb
.pdf
Python Agent
 Contents 
Python Agent
Fibonacci Example
Training neural net
Python Agent#
This notebook showcases an agent designed to write and execute python code to answer a question.
from langchain.agents.agent_toolkits import create_python_agent
from langchain.tools.python.tool import PythonREPLTool
from langchain.python import PythonREPL
from langchain.llms.openai import OpenAI
agent_executor = create_python_agent(
    llm=OpenAI(temperature=0, max_tokens=1000),
    tool=PythonREPLTool(),
    verbose=True
)
Fibonacci Example#
This example was created by John Wiseman.
agent_executor.run("What is the 10th fibonacci number?")
> Entering new AgentExecutor chain...
 I need to calculate the 10th fibonacci number
Action: Python REPL
Action Input: def fibonacci(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fibonacci(n-1) + fibonacci(n-2)
Observation: 
Thought: I need to call the function with 10 as the argument
Action: Python REPL
Action Input: fibonacci(10)
Observation: 
Thought: I now know the final answer
Final Answer: 55
> Finished chain.
'55'
Training neural net#
This example was created by Samee Ur Rehman.
agent_executor.run("""Understand, write a single neuron neural network in PyTorch.
Take synthetic data for y=2x. Train for 1000 epochs and print every 100 epochs.
Return prediction for x = 5""")
> Entering new AgentExecutor chain...
 I need to write a neural network in PyTorch and train it on the given data.