Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SmartGPT workflow (issue #4463) #4816

Merged
merged 22 commits into from
Aug 11, 2023

Conversation

UmerHA
Copy link
Contributor

@UmerHA UmerHA commented May 16, 2023

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:

Twitter: @UmerHAdil | Discord: RicChilligerDude#7589

@leo-gan
Copy link
Collaborator

leo-gan commented May 18, 2023

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.

Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is probably more of chain than an LLM (in the same way the constitutional AI chain exists

@UmerHA
Copy link
Contributor Author

UmerHA commented May 19, 2023

Agreed - will change

@UmerHA
Copy link
Contributor Author

UmerHA commented May 20, 2023

Requires #5030 to be merged. Will re-request review, when it's merged.

langchain/schema.py Outdated Show resolved Hide resolved
langchain/chat_models/fake.py Outdated Show resolved Hide resolved
langchain/chains/smart_llm/base.py Outdated Show resolved Hide resolved
@UmerHA UmerHA requested a review from hwchase17 May 21, 2023 02:21
"metadata": {},
"outputs": [],
"source": [
"hard_question = \"I have a 12 liter jug and a 6 liter jug. I want to measure 6 liters. How do I do it?\"\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't get it.
To measure 6 liter you have to fill in the 6 liter jug. That's all.
The answer definitely didn't provide a good answer.
Probably, the question can be like the puzzle for the "Die hard" move:
Given a 5-gallon jug and a 3-gallon jug. Please, fill one with exactly 4 gallons of water.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I disagree :) This is the example shown in the original SmartGPT video (https://youtu.be/wVzuvf9D9BU?t=384). The point is none of the original ideas work at all (even with GPT4!), only with the SmartGPT workflow do we get a correct answer.

But I agree this is confusing without context. I added more explanation.

@hwchase17 hwchase17 added the 03 enhancement Enhancement of existing functionality label May 22, 2023
@UmerHA
Copy link
Contributor Author

UmerHA commented May 30, 2023

Hey @hwchase17 any more comments?

@vercel
Copy link

vercel bot commented Jun 22, 2023

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

@batmanscode
Copy link

Nice work! 😃

@UmerHA
Copy link
Contributor Author

UmerHA commented Jul 14, 2023

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

@batmanscode
Copy link

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

@UmerHA
Copy link
Contributor Author

UmerHA commented Jul 18, 2023

@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).

@batmanscode
Copy link

@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!

@baskaryan baskaryan added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Aug 11, 2023
@baskaryan
Copy link
Collaborator

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

@baskaryan baskaryan merged commit 8aab39e into langchain-ai:master Aug 11, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
03 enhancement Enhancement of existing functionality lgtm PR looks good. Use to confirm that a PR is ready for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SmartGPT workflow
5 participants