langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Added SmartGPT workflow (issue #4463)

Open UmerHA opened this issue 2 years ago • 3 comments
trafficstars

Added SmartGPT workflow by providing SmartLLM wrapper around LLMs

Edit: As @hwchase17 suggested, this should be a chain, not an LLM. I have adapted the PR.

It is used like this:

from langchain.prompts import PromptTemplate
from langchain.chains import SmartLLMChain
from langchain.chat_models import ChatOpenAI

hard_question = "I have a 12 liter jug and a 6 liter jug. I want to measure 6 liters. How do I do it?"
hard_question_prompt = PromptTemplate.from_template(hard_question)

llm = ChatOpenAI(model_name="gpt-4")
prompt = PromptTemplate.from_template(hard_question)
chain = SmartLLMChain(llm=llm, prompt=prompt, verbose=True)

chain.run({})

Original text: Added SmartLLM wrapper around LLMs to allow for SmartGPT workflow (as in https://youtu.be/wVzuvf9D9BU). SmartLLM can be used wherever LLM can be used. E.g:

smart_llm = SmartLLM(llm=OpenAI())
smart_llm("What would be a good company name for a company that makes colorful socks?")

or

smart_llm = SmartLLM(llm=OpenAI())
prompt = PromptTemplate(
    input_variables=["product"],
    template="What is a good name for a company that makes {product}?",
)
chain = LLMChain(llm=smart_llm, prompt=prompt)
chain.run("colorful socks")

SmartGPT consists of 3 steps:

  1. Ideate - generate n possible solutions ("ideas") to user prompt
  2. Critique - find flaws in every idea & select best one
  3. Resolve - improve upon best idea & return it

Fixes #4463

Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

  • @hwchase17
  • @agola11

Twitter: @UmerHAdil | Discord: RicChilligerDude#7589

UmerHA avatar May 16 '23 21:05 UmerHA

Looks great! Is it possible to add some real results to the example, please? The example should show that it works and produces very helpful results.

leo-gan avatar May 18 '23 16:05 leo-gan

Agreed - will change

UmerHA avatar May 19 '23 08:05 UmerHA

Requires https://github.com/hwchase17/langchain/pull/5030 to be merged. Will re-request review, when it's merged.

UmerHA avatar May 20 '23 11:05 UmerHA

Hey @hwchase17 any more comments?

UmerHA avatar May 30 '23 21:05 UmerHA

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 11, 2023 10:43pm

vercel[bot] avatar Jun 22 '23 10:06 vercel[bot]

Nice work! 😃

batmanscode avatar Jul 05 '23 18:07 batmanscode

Hi @hinthornw! Also pinging you here, as you're the maintainer for Agents :) Any feedback?

UmerHA avatar Jul 14 '23 03:07 UmerHA

@UmerHA do you think this could be used for a pandas/xorbits agent? To break down complex questions before answering

batmanscode avatar Jul 17 '23 18:07 batmanscode

@UmerHA do you think this could be used for a pandas/xorbits agent? To break down complex questions before answering

Sure, why not. This is a general approach and should improve any task (at the cost of more token usage).

UmerHA avatar Jul 18 '23 10:07 UmerHA

@UmerHA do you think this could be used for a pandas/xorbits agent? To break down complex questions before answering

Sure, why not. This is a general approach and should improve any task (at the cost of more token usage).

Interesting thanks. Must look into using this as an agent with tools!

batmanscode avatar Jul 18 '23 18:07 batmanscode

apologies for the delay in reviewing, this is very cool! thank you @UmerHA!!

baskaryan avatar Aug 11 '23 22:08 baskaryan