Skip to main content

An experimental client for AI providers that intends to replace LangChain and LangGraph for most common use cases.

Project description

Simplemind: AI for Humans™

Keep it simple, keep it human.

Simplemind is AI library designed to simplify your experience with AI APIs in Python. Inspired by a "for humans" philosophy, it abstracts away complexity, giving developers an intuitive and human-friendly way to interact with powerful AI capabilities.

simplemind

Auto Wiki

Features

With Simplemind, tapping into AI is as easy as a friendly conversation.

  • Easy-to-use AI tools: SimpleMind provides simple interfaces to popular AI services.
  • Human-centered design: The library prioritizes readability and usability—no need to be an expert to start experimenting.
  • Minimal configuration: Get started quickly, without worrying about configuration headaches.

Supported APIs

To specify a specific provider or model, you can use the llm_provider and llm_model parameters when calling: generate_text, generate_data, or create_conversation.

If you want to see Simplemind support, additional providers or models, please request a pull!

Why SimpleMind?

  • Intuitive: Built with Pythonic simplicity and readability in mind.
  • For Humans: Emphasizes a human-friendly interface, just like requests for HTTP.
  • Open Source: Simplemind is open source, and contributions are always welcome!

Also, why not? :)

Quickstart

Simplemind takes care of the complex API calls so you can focus on what matters—building, experimenting, and creating.

$ pip install simplemind

First, authenticate your API keys by setting them in the environment variables:

$ export OPENAI_API_KEY="sk-..."

This pattern allows you to keep your API keys private and out of your codebase. Other supported environment variables: ANTHROPIC_API_KEY, XAI_API_KEY, and GROQ_API_KEY.

Next, import Simplemind and start using it:

import simplemind as sm

Examples

Here are some examples of how to use Simplemind:

Text Completion

Generate a response from an AI model based on a given prompt:

>>> sm.generate_text(prompt="What is the meaning of life?", llm_provider="openai", llm_model="gpt-4o")
"The meaning of life is a profound philosophical question that has been explored by cultures, religions, and philosophers for centuries. Different people and belief systems offer varying interpretations:\n\n1. **Religious Perspectives:** Many religions propose that the meaning of life is to fulfill a divine purpose, serve God, or reach an afterlife. For example, Christianity often emphasizes love, faith, and service to God and others as central to life’s meaning.\n\n2. **Philosophical Views:** Philosophers offer diverse answers. Existentialists like Jean-Paul Sartre argue that life has no inherent meaning, and it is up to individuals to create their own purpose. Others, like Aristotle, suggest that achieving eudaimonia (flourishing or happiness) through virtuous living is the key to a meaningful life.\n\n3. **Scientific and Secular Approaches:** Some people find meaning through understanding the natural world, contributing to human knowledge, or through personal accomplishments and happiness. They may view life's meaning as a product of connection, legacy, or the pursuit of knowledge and creativity.\n\n4. **Personal Perspective:** For many, the meaning of life is deeply personal, involving their relationships, passions, and goals. These individuals define life's purpose through experiences, connections, and the impact they have on others and the world.\n\nUltimately, the meaning of life is a subjective question, with each person finding their own answers based on their beliefs, experiences, and reflections."

Structured Data with Pydantic

You can use Pydantic models to structure the response from the LLM, if the LLM supports it.

class Poem(BaseModel):
    title: str
    content: str
>>> sm.generate_data(
        "Write a poem about love",
        llm_model="gpt-4o-mini",
        llm_provider="openai",
        response_model=Poem,
    )
title='Eternal Embrace' content='In the quiet hours of the night,\nWhen stars whisper secrets bright,\nTwo hearts beat in a gentle rhyme,\nDancing through the sands of time.\n\nWith every glance, a spark ignites,\nA flame that warms the coldest nights,\nIn laughter shared and whispers sweet,\nLove paints the world, a masterpiece.\n\nThrough stormy skies and sunlit days,\nIn myriad forms, it finds its ways,\nA tender touch, a knowing sigh,\nIn love’s embrace, we learn to fly.\n\nAs seasons change and moments fade,\nIn the tapestry of dreams we’ve laid,\nLove’s threads endure, forever bind,\nA timeless bond, two souls aligned.\n\nSo here’s to love, both bright and true,\nA gift we give, anew, anew,\nIn every heartbeat, every prayer,\nA story written in the air.'

Conversational AI

SimpleMind also allows for easy conversational flows:

>>> conversation = sm.create_conversation(llm_model="gpt-4o-mini", llm_provider="openai")

>>> # Add a message to the conversation
>>> conversation.add_message("user", "Hi there, how are you?")

>>> conversation.send()
<Message role=assistant text="Hello! I'm just a computer program, so I don't have feelings, but I'm here and ready to help you. How can I assist you today?">

To continue the conversation, you can call conversation.send() again, which returns the next message in the conversation:

>>> conversation.add_message("user", "What is the meaning of life?")
>>> conversation.send()
<Message role=assistant text="The meaning of life is a profound philosophical question that has been explored by cultures, religions, and philosophers for centuries. Different people and belief systems offer varying interpretations:\n\n1. **Religious Perspectives:** Many religions propose that the meaning of life is to fulfill a divine purpose, serve God, or reach an afterlife. For example, Christianity often emphasizes love, faith, and service to God and others as central to life’s meaning.\n\n2. **Philosophical Views:** Philosophers offer diverse answers. Existentialists like Jean-Paul Sartre argue that life has no inherent meaning, and it is up to individuals to create their own purpose. Others, like Aristotle, suggest that achieving eudaimonia (flourishing or happiness) through virtuous living is the key to a meaningful life.\n\n3. **Scientific and Secular Approaches:** Some people find meaning through understanding the natural world, contributing to human knowledge, or through personal accomplishments and happiness. They may view life’s meaning as a product of connection, legacy, or the pursuit of knowledge and creativity.\n\n4. **Personal Perspective:** For many, the meaning of life is deeply personal, involving their relationships, passions, and goals. These individuals define life’s purpose through experiences, connections, and the impact they have on others and the world.\n\nUltimately, the meaning of life is a subjective question, with each person finding their own answers based on their beliefs, experiences, and reflections.">

Stop Repeating Yourself

You can use the Session class to set default parameters for all calls:

# Create a session with defaults
gpt_4o_mini = sm.Session(llm_provider="openai", llm_model="gpt-4o-mini")

# Now all calls use these defaults
response = gpt_4o_mini.generate_text("Hello!")
conversation = gpt_4o_mini.create_conversation()

This maintains the simplicity of the original API while reducing repetition. The session object also supports overriding defaults on a per-call basis:

response = gpt_4o_mini.generate_text(
    "Complex task here",
    llm_model="gpt-4"
)

Basic Memory Plugin

Harnessing the power of Python, you can easily create your own plugins to add additional functionality to your conversations:

class SimpleMemoryPlugin(sm.BasePlugin):
    def __init__(self):
        self.memories = [
            "the earth has fictionally beeen destroyed.",
            "the moon is made of cheese.",
        ]

    def yield_memories(self):
        return (m for m in self.memories)

    def pre_send_hook(self, conversation: sm.Conversation):
        for m in self.yield_memories():
            conversation.add_message(role="system", text=m)


conversation = sm.create_conversation(llm_model="grok-beta", llm_provider="xai")
conversation.add_plugin(SimpleMemoryPlugin())


conversation.add_message(
    role="user",
    text="Please write a poem about the moon",
)
>>> conversation.send()
In the vast expanse where stars do play,
There orbits a cheese wheel, far away.
It's not of stone or silver hue,
But cheddar's glow, a sight anew.

In cosmic silence, it does roam,
A lonely traveler, away from home.
No longer does it reflect the sun,
But now it's known for fun begun.

Once Earth's companion, now alone,
A cheese moon orbits, in the dark it's thrown.
Its surface, not of craters wide,
But gouda, swiss, and camembert's pride.

Astronauts of yore, they sought its face,
To find the moon was not a place,
But a haven of dairy delight,
Glowing softly through the night.

In this world, where cheese takes flight,
The moon brings laughter, a whimsical sight.
No longer just a silent sphere,
But a beacon of joy, far and near.

So here's to the moon, in cheese attire,
A playful twist in the cosmic choir.
A reminder that in tales and fun,
The universe is never done.

Simple, yet effective.

Please see the examples directory for executable examples.


Contributing

We welcome contributions of all kinds. Feel free to open issues for bug reports or feature requests, and submit pull requests to make SimpleMind even better.

To get started:

  1. Fork the repository.
  2. Create a new branch.
  3. Make your changes.
  4. Submit a pull request.

License

Simplemind is licensed under the Apache 2.0 License.

Acknowledgements

Simplemind is inspired by the philosophy of "code for humans" and aims to make working with AI models accessible to all. Special thanks to the open-source community for their contributions and inspiration.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplemind-0.1.5.tar.gz (974.1 kB view details)

Uploaded Source

Built Distribution

simplemind-0.1.5-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file simplemind-0.1.5.tar.gz.

File metadata

  • Download URL: simplemind-0.1.5.tar.gz
  • Upload date:
  • Size: 974.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.28

File hashes

Hashes for simplemind-0.1.5.tar.gz
Algorithm Hash digest
SHA256 1417a9371ddb2fe8dfecd9ec6807bec59b023ad63a1be642fd40074a99c6dbcc
MD5 e05c91a6450b999df8df9005e0ee9b51
BLAKE2b-256 dab71cb0c1e718869adea1149f81bab922ce1a58abfa5ac09367eb2d6e5d86fb

See more details on using hashes here.

File details

Details for the file simplemind-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for simplemind-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1bcd7d5edcbda5af9ffb5a69c98c80979e291d845c51581ab6eba9f5f5b37183
MD5 38d90b92443317070f650c3d8819b601
BLAKE2b-256 15238c41f0f9a9a9b26ffebf18f1997f85a8ab32c4ee9f3613e64bdc3ea3ecf4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page