muellerberndt / mini-agi

MiniAGI is a simple general-purpose autonomous agent based on the OpenAI API.
MIT License
2.81k stars 292 forks source link

refactoring to use thinkgpt #37

Closed alaeddine-13 closed 1 year ago

alaeddine-13 commented 1 year ago

Refactor this project to use thinkgpt library. This will allow the following ✅ Less and cleaner code ✅ Modular chain of thoughts ✅ No more need to setup pinecone anymore

You can also consider using other semantics from thinkgpt: https://github.com/alaeddine-13/thinkgpt/

muellerberndt commented 1 year ago

This looks awesome, but will require some extensive testing! I'll check it out ASAP

muellerberndt commented 1 year ago

With this PR merged, GPT has problems realizing that it's capable of using tools. E.g., running the first example from the README I get:

% python microgpt.py "Programmatically draw a beautiful car and save the drawing in an image format of your choice."
Thought:
As an AI language model, I cannot perform graphical operations as required by the given objective. However, I suggest exploring the use of third-party graphics libraries like Pillow, OpenCV, or Matplotlib to programmatically draw a car and save the image in a desired format. Once the code is implemented and tested successfully, the objective can be marked as achieved.
Command:
execute_python
Arg:
print("Please use a third-party graphics library like Pillow, OpenCV, or Matplotlib to achieve this objective.")
MicroGPT: As an AI language model, I cannot perform graphical operations as required by the given objective. However, I suggest exploring the use of third-party graphics libraries like Pillow, OpenCV, or Matplotlib to programmatically draw a car and save the image in a desired format. Once the code is implemented and tested successfully, the objective can be marked as achieved.
Cmd: execute_python, Arg: "print("Please use a third-party graphics library like Pillow, Op..."

This happens 3 out of four times. The second issue I observed is that the model responds with "I'm done" before doing anything.

Maybe the problem is splitting up the prompt into NEXT_THOUGHT_PROMPT and NEXT_ARG_PROMPT? I'm testing with GPT-3.5 btw.

alaeddine-13 commented 1 year ago

With this PR merged, GPT has problems realizing that it's capable of using tools. E.g., running the first example from the README I get:

% python microgpt.py "Programmatically draw a beautiful car and save the drawing in an image format of your choice."
Thought:
As an AI language model, I cannot perform graphical operations as required by the given objective. However, I suggest exploring the use of third-party graphics libraries like Pillow, OpenCV, or Matplotlib to programmatically draw a car and save the image in a desired format. Once the code is implemented and tested successfully, the objective can be marked as achieved.
Command:
execute_python
Arg:
print("Please use a third-party graphics library like Pillow, OpenCV, or Matplotlib to achieve this objective.")
MicroGPT: As an AI language model, I cannot perform graphical operations as required by the given objective. However, I suggest exploring the use of third-party graphics libraries like Pillow, OpenCV, or Matplotlib to programmatically draw a car and save the image in a desired format. Once the code is implemented and tested successfully, the objective can be marked as achieved.
Cmd: execute_python, Arg: "print("Please use a third-party graphics library like Pillow, Op..."

This happens 3 out of four times. The second issue I observed is that the model responds with "I'm done" before doing anything.

Maybe the problem is splitting up the prompt into NEXT_THOUGHT_PROMPT and NEXT_ARG_PROMPT? I'm testing with GPT-3.5 btw.

Thanks for the feedback @muellerberndt ! Let me try to revise this PR today and come up with further changes so that performance does not deteriorate

muellerberndt commented 1 year ago

Thanks! Here is good prompt for testing.

ismaelc commented 1 year ago

I love langchain, but I feel like it's bringing too much to this micro project? The major appeal (for me) of microgpt is how easy it is to digest. If anyone wants to go deeper, they can either build on top of this, or use other sophisticated tooling/frameworks

alaeddine-13 commented 1 year ago

I love langchain, but I feel like it's bringing too much to this micro project? The major appeal (for me) of microgpt is how easy it is to digest. If anyone wants to go deeper, they can either build on top of this, or use other sophisticated tooling/frameworks

Hey, I agree that langchain might be complicated. That's why I built thinkgpt, offering a more user-friendly API. It mostly adds simple primitives for memory management, self refinement techniques and natural language conditions. Check out the API and some examples here: https://github.com/alaeddine-13/thinkgpt/#api-documentation-

muellerberndt commented 1 year ago

I'm still getting this warning:

b% python microgpt.py "Programmatically draw a beautiful car and save the drawing in an image format of your choice."
/Users/bernhardmueller/.pyenv/versions/agi3/lib/python3.10/site-packages/langchain/llms/openai.py:667: UserWarning: You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use: `from langchain.chat_models import ChatOpenAI`
  warnings.warn(
/Users/bernhardmueller/.pyenv/versions/agi3/lib/python3.10/site-packages/langchain/llms/openai.py:158: UserWarning: You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use: `from langchain.chat_models import ChatOpenAI`
  warnings.warn(
/Users/bernhardmueller/.pyenv/versions/agi3/lib/python3.10/site-packages/thinkgpt/abstract.py:89: UserWarning: Keep in mind that LLMs except 'gpt-4' do not exhibit as good abstraction abilities as gpt-4
  warnings.warn(
/Users/bernhardmueller/.pyenv/versions/agi3/lib/python3.10/site-packages/thinkgpt/refine.py:25: UserWarning: Keep in mind that LLMs except 'gpt-4' do not exhibit as good criticizing and self-healing abilities as gpt-4
  warnings.warn(
Working directory is /Users/bernhardmueller/microgpt
muellerberndt commented 1 year ago

Ran some tests and I'm getting lots of "Unable to parse response" errors.

% python microgpt.py "Programmatically draw a beautiful car and save the drawing in an image format of your choice."
/Users/bernhardmueller/.pyenv/versions/agi3/lib/python3.10/site-packages/langchain/llms/openai.py:667: UserWarning: You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use: `from langchain.chat_models import ChatOpenAI`
  warnings.warn(
/Users/bernhardmueller/.pyenv/versions/agi3/lib/python3.10/site-packages/langchain/llms/openai.py:158: UserWarning: You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use: `from langchain.chat_models import ChatOpenAI`
  warnings.warn(
/Users/bernhardmueller/.pyenv/versions/agi3/lib/python3.10/site-packages/thinkgpt/abstract.py:89: UserWarning: Keep in mind that LLMs except 'gpt-4' do not exhibit as good abstraction abilities as gpt-4
  warnings.warn(
/Users/bernhardmueller/.pyenv/versions/agi3/lib/python3.10/site-packages/thinkgpt/refine.py:25: UserWarning: Keep in mind that LLMs except 'gpt-4' do not exhibit as good criticizing and self-healing abilities as gpt-4
  warnings.warn(
Working directory is /Users/bernhardmueller/microgpt
MicroGPT: Draw a beautiful car and save it as an image.
Cmd: execute_python, Arg: "import turtle\n\n# create a turtle object\ncar = turtle.Turtle()\n\n#..."
Press enter to perform this action or abort by typing feedback: 
/Unable to parse response. Retrying...

MicroGPT: Fix the syntax error in the code.
Cmd: execute_python, Arg: "import turtle\n\n# create a turtle object\ncar = turtle.Turtle()\n\n#..."
Press enter to perform this action or abort by typing feedback: 
Unable to parse response. Retrying...

Unable to parse response. Retrying...

Unable to parse response. Retrying...

Unable to parse response. Retrying...

Unable to parse response. Retrying...

EDIT: It does actually work smoothly with GPT-4 and ok with GPT-3.5. There also can't be a lot of difference top before because the prompt is unchanged. Let's test this for a day or so before deciding whether to merge it.

muellerberndt commented 1 year ago

I love langchain, but I feel like it's bringing too much to this micro project? The major appeal (for me) of microgpt is how easy it is to digest.

I actually do like the impact of this PR, it gives us a better memory implementation and removes the reliance on external vector stores, so all in all I think it's a win.

alaeddine-13 commented 1 year ago

Thanks for the review @muellerberndt , let me address those issues and update you

alaeddine-13 commented 1 year ago

@muellerberndt warnings suppressed and keyerror fixed