diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..6ac2281 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,34 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +import os +import sys + +sys.path.insert(0, os.path.abspath("..")) + +import simplemind + +project = "simplemind" +copyright = "2024, Kenneth Reitz" +author = "Kenneth Reitz" +release = "v0.1.2" + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = ["sphinx.ext.autodoc"] + +templates_path = ["_templates"] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = "alabaster" +html_static_path = ["_static"] diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..9ea26e7 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,167 @@ +.. simplemind documentation master file, created by + sphinx-quickstart on Wed Oct 30 08:08:14 2024. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +SimpleMind: AI for Humans™ +========================== + +**SimpleMind** is a versatile Python library designed to simplify interactions with various AI models. It provides a consistent and user-friendly interface to numerous AI providers, enabling developers to seamlessly integrate powerful AI capabilities into their applications without the overhead of managing multiple APIs and configurations. + +Features +-------- + +- **Unified Interface**: Interact with multiple AI providers using a single, consistent API +- **Plugin Architecture**: Extend functionality with custom plugins for tasks like memory management and sentiment analysis +- **Structured Data Support**: Generate and manipulate structured data using Pydantic models +- **Human-Centered Design**: Prioritizes readability and ease of use, making AI integration accessible to all developers +- **Minimal Configuration**: Quickly get started without extensive setup or configuration + +Supported Providers +------------------ + +SimpleMind supports a variety of AI providers: + +- `OpenAI's GPT `_ +- `Anthropic's Claude `_ +- `xAI's Grok `_ +- `Groq's Groq `_ +- `Ollama `_ + +Installation +----------- + +Install SimpleMind using pip: + +.. code-block:: shell + + $ pip install simplemind + +Quickstart +---------- + +1. Set your API keys as environment variables: + + .. code-block:: bash + + $ export OPENAI_API_KEY="sk-..." + $ export ANTHROPIC_API_KEY="..." + $ export XAI_API_KEY="..." + $ export GROQ_API_KEY="..." + +2. Import and use SimpleMind: + + .. code-block:: python + + import simplemind as sm + + # Generate text using the default provider (OpenAI) + response = sm.generate_text("Write a poem about the moon.", llm_model="gpt-4o-mini") + print(response) + +Things to know: + +- The primary function for generating text is ``generate_text()``, which is used in the example above. +- To generate structured data, use ``generate_data()``, which most providers support. This is extremely useful. +- The third function, ``create_conversation()``, is used to engage in conversations with AI models. + +All of these functions accept a ``llm_model`` and ``llm_provider`` parameter, which allows you to specify the AI model to use. If not provided, the default model for the given provider will be used. + + +Usage Examples +-------------- + +Here are some examples demonstrating SimpleMind's key features. From generating creative text and structured data to engaging in conversations and extending functionality with plugins, these examples showcase the library's versatility and ease of use. + +Feel free to adapt these examples to your specific use cases! + + +Text Generation +~~~~~~~~~~~~~~~ + +This example generates a poem about the moon using the ``gpt-4o-mini`` model. + +.. code-block:: python + + import simplemind as sm + + poem = sm.generate_text("Write a poem about the moon.", llm_model="gpt-4o-mini") + print(poem) + +Structured Data Generation +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This example generates a poem about love using the ``gpt-4o-mini`` model. + +.. code-block:: python + + from pydantic import BaseModel + + class Poem(BaseModel): + title: str + content: str + + poem = sm.generate_data( + prompt="Write a poem about love", + llm_model="gpt-4o-mini", + response_model=Poem, + ) + print(poem) + +Conversational AI +~~~~~~~~~~~~~~~~~ + +This example engages in a conversation with the ``gpt-4o-mini`` model. + + +.. code-block:: python + + conversation = sm.create_conversation(llm_model="gpt-4o-mini") + conversation.add_message("user", "Hi there, how are you?") + response = conversation.send() + print(response.text) + +Plugins +~~~~~~~ + +This example adds a simple custom memory plugin to the conversation. + +.. code-block:: python + + class SimpleMemoryPlugin: + def __init__(self): + self.memories = ["the moon is made of cheese."] + + def send_hook(self, conversation): + for memory in self.memories: + conversation.add_message(role="system", text=memory) + + conversation = sm.create_conversation() + conversation.add_plugin(SimpleMemoryPlugin()) + conversation.add_message("user", "Write a poem about the moon") + print(conversation.send().text) + +Contributing +----------- + +1. Fork the Repository +2. Create a New Branch +3. Make Your Changes +4. Submit a Pull Request + +Please review our `Code of Conduct `_ before contributing. + +License +------- + +SimpleMind is licensed under the `Apache 2.0 License `_. + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + installation + usage + api + contributing + changelog diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..32bb245 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd