# Julia response to Auto-GPT

**URL:** https://discourse.julialang.org/t/julia-response-to-auto-gpt/98229
**Category:** Machine Learning
**Created:** [May 3, 2023, 3:00am UTC](https://discourse.julialang.org/t/julia-response-to-auto-gpt/98229 "2023-05-03T03:00:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![alex-s-gardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex-s-gardner/32/30210_2.png) [@alex-s-gardner](https://discourse.julialang.org/u/alex-s-gardner)
#### Post date: [May 3, 2023, 3:00am UTC](https://discourse.julialang.org/t/julia-response-to-auto-gpt/98229/1 "2023-05-03T03:00:18Z")

</div>

Now that we have a wrapper for the [openAI API](https://github.com/JuliaML/OpenAI.jl) it would be pretty cool to have an [Auto-GPT](https://github.com/Significant-Gravitas/Auto-GPT) like package that the julia community could contribute to. It’s pretty amazing how simply having the LLM talk to itself(s) can greatly increase the skill and complexity of tasks that it can tackle. Maybe someone is already working on such a package.

---

<div class="post-metadata">

### Author: ![apieum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/apieum/32/2928_2.png) [@apieum](https://discourse.julialang.org/u/apieum)
#### Post date: [May 6, 2023, 7:26pm UTC](https://discourse.julialang.org/t/julia-response-to-auto-gpt/98229/2 "2023-05-06T19:26:06Z")

</div>

Actually you don’t need a package to do that, you can just use langchain with PyCall.  
On langchain website you’ve an implementation example of auto-gpt using langchain primitives: [AutoGPT — 🦜🔗 LangChain 0.0.161](https://python.langchain.com/en/latest/use_cases/autonomous_agents/autogpt.html)

Python code “autogpt.py”:

```julia
from langchain.utilities import SerpAPIWrapper
from langchain.agents import Tool
from langchain.tools.file_management.write import WriteFileTool
from langchain.tools.file_management.read import ReadFileTool

search = SerpAPIWrapper()
tools = [
    Tool(
        name = "search",
        func=search.run,
        description="useful for when you need to answer questions about current events. You should ask targeted questions"
    ),
    WriteFileTool(),
    ReadFileTool(),
    ]
from langchain.vectorstores import FAISS
from langchain.docstore import InMemoryDocstore
from langchain.embeddings import OpenAIEmbeddings
# Define your embedding model
embeddings_model = OpenAIEmbeddings()
# Initialize the vectorstore as empty
import faiss

embedding_size = 1536
index = faiss.IndexFlatL2(embedding_size)
vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {})
from langchain.experimental import AutoGPT
from langchain.chat_models import ChatOpenAI
agent = AutoGPT.from_llm_and_tools(
    ai_name="Tom",
    ai_role="Assistant",
    tools=tools,
    llm=ChatOpenAI(temperature=0),
    memory=vectorstore.as_retriever()
)
# Set verbose to be true
agent.chain.verbose = True

agent.run(["write a weather report for SF today"])

```

Julia equivalent with PyCall “autogpt.jl”:

```julia
using PyCall

utilities = pyimport("langchain.utilities")
agents = pyimport("langchain.agents")
write = pyimport("langchain.tools.file_management.write")
read = pyimport("langchain.tools.file_management.read")
vectorstores = pyimport("langchain.vectorstores")
docstore = pyimport("langchain.docstore")
embeddings = pyimport("langchain.embeddings")
experimental = pyimport("langchain.experimental")
chat_models = pyimport("langchain.chat_models")
faiss = pyimport("faiss")

search = utilities.SerpAPIWrapper()
tools = [
    agents.Tool(
        name = "search",
        func=search.run,
        description="useful for when you need to answer questions about current events. You should ask targeted questions"
    ),
    write.WriteFileTool(),
    read.ReadFileTool(),
]

embeddings_model = embeddings.OpenAIEmbeddings()
embedding_size = 1536
index = faiss.IndexFlatL2(embedding_size)
vectorstore = vectorstores.FAISS(embeddings_model.embed_query, index, docstore.InMemoryDocstore(Dict()), Dict())

agent = experimental.AutoGPT.from_llm_and_tools(
    ai_name="Tom",
    ai_role="Assistant",
    tools=tools,
    llm=chat_models.ChatOpenAI(temperature=0),
    memory=vectorstore.as_retriever()
)

agent.chain.verbose = true

agent.run(["write a weather report for SF today"])

```

To use this code you need to specify OPENAI\_API\_KEY and SERPAPI\_API\_KEY environment variables.  
example in a shell:

```julia
OPENAI_API_KEY="YOUR_OPENAI_API_KEY" SERPAPI_API_KEY="YOUR_SERPAPI_API_KEY" julia autogpt.jl

```

Have fun !

---

<div class="post-metadata">

### Author: ![alex-s-gardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex-s-gardner/32/30210_2.png) [@alex-s-gardner](https://discourse.julialang.org/u/alex-s-gardner)
#### Post date: [May 6, 2023, 7:44pm UTC](https://discourse.julialang.org/t/julia-response-to-auto-gpt/98229/3 "2023-05-06T19:44:28Z")

</div>

This is awesome, thanks!
