GithubHelp home page GithubHelp logo

Comments (9)

benman1 avatar benman1 commented on August 25, 2024

@rkchaganti sorry for not getting back earlier. The message is a bit cryptic without context, unfortunately. If you can provide a bit more information about what you are trying to run this would be helpful.

from generative_ai_with_langchain.

benman1 avatar benman1 commented on August 25, 2024

I am closing this. I am not very good at guessing. Please feel free to re-open once you've posted more context.

from generative_ai_with_langchain.

SheldonLiu0412 avatar SheldonLiu0412 commented on August 25, 2024

I am closing this. I am not very good at guessing. Please feel free to re-open once you've posted more context.

from langchain_openai import ChatOpenAI
from langchain.agents import load_tools, initialize_agent, AgentType
from langchain_experimental.tools import PythonREPLTool
llm = ChatOpenAI()
tools = load_tools(["python_repl"])
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
result = agent("What are the prime numbers until 20?")
print(result)

line 614, in load_tools
raise ValueError(f"Got unknown tool {name}")
ValueError: Got unknown tool python_repl

from generative_ai_with_langchain.

benman1 avatar benman1 commented on August 25, 2024

@SheldonLiu0412 I've just searched for PythonREPLTool. It's in the data science notebook, here:

" llm=OpenAI(temperature=0, max_tokens=1000),\n",
- but the code looks different.

Could you please specify your LC version? pip show langchain?

from generative_ai_with_langchain.

SheldonLiu0412 avatar SheldonLiu0412 commented on August 25, 2024

LC Version: 0.1.14,Currently I am changing my code to:
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from langchain_experimental.tools import PythonREPLTool
llm = ChatOpenAI()
tools = PythonREPLTool(),
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
result = agent.invoke("What are the prime numbers until 20?")
print(result)
It works,I don't know if I'm doing the right thing

from generative_ai_with_langchain.

benman1 avatar benman1 commented on August 25, 2024

Please note that the code and the book refer to LC version 0.0258. Because LC is changing so heavily, if you are using different versions the code will not work without modifications. The code that you are using should work, but is deprecated for version 0.2.

from generative_ai_with_langchain.

SheldonLiu0412 avatar SheldonLiu0412 commented on August 25, 2024

I changed the latest code:
from langchain import hub
from langchain.agents import AgentExecutor
from langchain_experimental.tools import PythonREPLTool
tools = [PythonREPLTool()]
from langchain.agents import create_openai_functions_agent
from langchain_openai import ChatOpenAI
instructions = """You are an agent designed to write and execute python code to answer questions.
You have access to a python REPL, which you can use to execute python code.
If you get an error, debug your code and try again.
Only use the output of your code to answer the question.
You might know the answer without running any code, but you should still run the code to get the answer.
If it does not seem like you can write code to answer the question, just return "I don't know" as the answer.
"""
base_prompt = hub.pull("langchain-ai/openai-functions-template")
prompt = base_prompt.partial(instructions=instructions)
agent = create_openai_functions_agent(ChatOpenAI(), tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
result = agent_executor.invoke({"input":"What are the prime numbers until 20?"})
print(result)
Maybe it can run in version 0.2,The change of version brought many minor problems,Thank you for your timely answer and help. Thank you again

from generative_ai_with_langchain.

benman1 avatar benman1 commented on August 25, 2024

@SheldonLiu0412 no problem! I am very happy that you found the solution! It's indeed a big change in some cases to the latest version. BTW, I've created a new branch for the 0.1 version that I am updating now - it's work in progress; I am just working on chapter 5.

image

from generative_ai_with_langchain.

SheldonLiu0412 avatar SheldonLiu0412 commented on August 25, 2024

@benman1 Look forward to your new share! It is very meaningful to follow this book to learn LangChain step by step.

from generative_ai_with_langchain.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.