ThinkGPT is an innovative Python library that extends the capabilities of large language models, enabling them to think, reason and take action more effectively. If you are keen to integrate ThinkGPT into your Python scripts and make use of its advanced features, you have come to the right place! In this blog post, we guide you through the first steps of using ThinkGPT in your Python projects.
Below, we explore the core features of ThinkGPT, including its advanced memory capabilities, self-refinement mechanisms and higher-order reasoning skills. You will discover how this innovative library is changing the landscape of AI development and how you can harness its power to improve your own projects. So join me on this exciting journey as we dive into the world of ThinkGPT and uncover its potential!
ThinkGPT is hosted on GitHub. The repository can be found at: https://github.com/alaeddine-13/thinkgpt

Key features of ThinkGPT
Memory : ThinkGPT lets large language models (LLMs) remember experiences and learn new concepts.
Self-refinement : This feature lets the model improve the content it generates by addressing criticism, fixing problems and refining its understanding.
Abstraction : It encourages LLMs to generalize rules from examples or observations, which helps create compressed knowledge that fits better within the model's limited context length.
Inference : It enables the LLM to make educated guesses based on the available information.
Natural language conditions : Users can easily express tasks and conditions in natural language, allowing the model to make intelligent decisions.
Easy setup and Pythonic API: Thanks to DocArray, ThinkGPT offers a very easy setup process and a Pythonic API.
Installation
Installing ThinkGPT is simple and can be done with pip:
pip install git+https://github.com/alaeddine-13/thinkgpt.GitHub
This command installs the ThinkGPT library directly from its GitHub repository.
First steps with ThinkGPT in your Python script
Once installation is complete, you can start using ThinkGPT in your Python script. To do this, simply import the ThinkGPT class from the thinkgpt.llm module and create a new instance of the class:
from thinkgpt.llm import ThinkGPT
llm = ThinkGPT(model_name="gpt-3.5-turbo")
This code snippet initializes a new ThinkGPT instance with the specified model, in this case “gpt-3.5-turbo”.
With the ThinkGPT instance created, you can now teach the AI model new concepts or facts using the memorize() method
llm.memorize(['DocArray is a library for representing, sending, and storing multi-modal data.'])
To recall the memorized information, you can use the remember() method:
memory = llm.remember('DocArray definition')
Once your AI model has learned some information, you can use the predict() method to make predictions or answer questions based on the memorized data:
llm.predict('what is DocArray ?', remember=memory)
This code snippet uses the remember() method to retrieve the memorized information and feeds it to the predict() method to answer the question.
Practical examples
ThinkGPT comes with some easy-to-understand use-case examples. The corresponding Python scripts can be found in the repository's examples folder:

Let's take a closer look at one of the provided examples: replay_expand_memory.py:
from thinkgpt.llm import ThinkGPT
llm = ThinkGPT(model_name="gpt-3.5-turbo")
# Load old memory
old_memory = [
"Klaus Mueller is writing a research paper",
"Klaus Mueller enjoys reading a book on gentrification",
"Klaus Mueller is conversing with Ayesha Khan about exercising"
]
# Teach the LLM the old memory
llm.memorize(old_memory)
# Induce reflections based on the old memory
new_observations = llm.infer(facts=llm.remember())
print('new thoughts:')
print('\n'.join(new_observations))
llm.memorize(new_observations)
In this ThinkGPT example script, the goal is to use the ThinkGPT library to induce new reflections or observations based on existing information about Klaus Mueller.
- First, the script imports the ThinkGPT class from the thinkgpt.llm module.
- A new ThinkGPT instance is created and initialized with the “gpt-3.5-turbo” model.
- The variable old_memory is defined and contains three statements about Klaus Mueller, representing prior knowledge.
- The memorize() method is used to teach the large language model (LLM) the information stored in old_memory.
- The infer() method is called with the facts parameter set to the result of the remember() method. This directs the LLM to induce new observations or reflections based on the previously memorized information.
- The newly induced observations are printed to the console under the heading “new thoughts“.
- Finally, the memorize() method is called again to store the new observations in the LLM's memory, allowing it to build on its understanding of Klaus Mueller in future interactions.
Before we are ready to run the script and see what the result looks like, we need to obtain an OpenAI API key and set the corresponding environment variable OPENAI_API_KEY to the key's value.
To get an OpenAI API key, follow these simple steps:
- Visit the OpenAI website at https://www.openai.com/.
- Sign up for an account if you do not have one. Click ” Sign Up ” in the top-right corner of the home page and follow the sign-up process.
- After signing up or logging in, go to the API section by clicking “API” at the top of the page or by visiting https://www.openai.com/api/.
- Review the available API pricing plans and choose the one that suits your needs. Some plans may offer free access with limited usage, while others offer different levels of access depending on your requirements and budget.
- After choosing a plan, you will be given your unique API key. Keep it secure, because it grants access to the API with your account's usage limits and privileges.
In the terminal, use the following command to set the OpenAI API key:
export OPENAI_API_KEY="YOUR OPENAI API KEY"
We are now ready to run the script by typing:
python replay_expand_memory.py
You should then see a result similar to the following:

Conclusion
ThinkGPT is a powerful Python library that improves the capabilities of large language models by adding advanced memory, self-refinement, abstraction and inference features. Its easy installation process and Pythonic API make it a valuable addition to many AI projects. By exploring the practical examples in this blog post, you can harness the power of ThinkGPT to transform the way your AI thinks, draws conclusions and takes action.

