ThinkGPT is a Python library designed to implement Chain of Thoughts for large language models (LLMs), prompting the model to think, reason, and create generative agents. The library's goals include: solving the problems of limited context and long memory and compressed knowledge; enhancing the one-shot reasoning ability of LLMs through high-level reasoning primitives; and adding intelligent decision-making to codebases.
Main capabilities (thinking building blocks):
- Memory: GPT can remember experiences.
- Self-refinement: improving model-generated content by processing criticism.
- Compressed knowledge: compressing knowledge and adapting it to the LLM context by abstracting rules from observations or summarizing large content.
- Reasoning: making informed guesses based on available information.
- Natural language conditionals: easily expressing choices and conditions in natural language.
Other features:
- Efficient and measurable GPT context length.
- Extremely simple setup and a Pythonic API with the help of DocArray.
Installation method: ThinkGPT can be installed using pip:
pip install thinkgpt
Usage:
- Remembering and recalling information: Use the limit parameter to specify the maximum number of documents to retrieve. If you want to fit documents to a specific context size, you can also use the max_tokens parameter to specify the maximum number of tokens to retrieve. Note that joining documents with a separator increases the token count of the final result, and the remember method does not account for these tokens.
- Use context from long-term memory for prediction.
- Self-refinement: One application is self-healing code generation, implemented by projects such as gptdeploy and wolverine.
- Compressing knowledge: If you want knowledge to fit into the LLM's context, you can compress it using the following techniques:
- Use the LLM itself to summarize content. Two methods are provided:
- One-shot summarization: Use the LLM for one-shot summarization. Since this technique relies on a single LLM call for summarization, you can only pass content that does not exceed the LLM's context length.
- Chunked summarization: Split the content into different chunks, summarize each chunk, and then use the LLM to combine them together.
- Abstract higher-level, more general observations from current observations: This helps obtain compressed knowledge that better fits the LLM's limited context length. For example, instead of trying to put code examples into the LLM context, use it to prompt the LLM to understand high-level rules and put those into the context.
- Use the LLM itself to summarize content. Two methods are provided:
- Natural language condition: Introduce intelligent conditions for code, letting the LLM make decisions.
- Natural language choice: Let the LLM choose from a list of options. You can also use num_choices to prompt the LLM to choose an exact number of answers. The default value is None, which means the LLM will choose any number it considers correct.
Example demonstrations:
- Teach ThinkGPT a new language.
- Teach ThinkGPT how to code using the thinkgpt library.
- Replay agent memory and infer new observations: Refer to the script example. This concept is proposed in the paper "Generative Agents: Interactive Simulacra of Human Behavior".
- Replay agent memory, critique and refine knowledge in memory: Refer to the script example. This technique is mainly implemented in the paper "Self-Refine: Iterative Refinement with Self-Feedback".
For more detailed usage and code examples, please see ./examples.
Applicable scenarios: Python projects that need to enhance LLM reasoning capabilities, manage long-term memory, compress knowledge, implement self-refinement, or add intelligent decision-making to code.
Limitations: No other limitation information is currently provided.