Find a file
2025-03-21 12:35:34 +00:00
static modified: static/openapi.yaml 2025-03-19 20:04:32 -04:00
.gitignore ship it. 2025-03-19 19:45:20 -04:00
.gitlab-ci.yml Update .gitlab-ci.yml 2025-03-20 23:20:03 +00:00
README.md ship it. 2025-03-19 19:45:20 -04:00
requirements.txt ship it. 2025-03-19 19:45:20 -04:00
slop_with_models.py Instructions 2025-03-21 12:33:23 +00:00
streamlit_slop_with_models.py Update streamlit_slop_with_models.py 2025-03-21 12:35:34 +00:00

SLOP Streamlit Example

Streamlit-based SLOP example with dynamic model endpoints. It explains the purpose, setup, usage, and structure in a clear and concise way.

This is a Python implementation of the SLOP pattern using Flask as a backend server and Streamlit as a frontend interface. It dynamically discovers and utilizes language models from OpenAI-compatible endpoints (e.g., vLLM, Ollama, etc.) specified via environment variables.

Features

  • Chat: Send messages to dynamically discovered AI models.
  • Tools: Use simple tools like a calculator and greeter. (broken, please help fix this)
  • Memory: Store and retrieve key-value pairs.
  • Resources: Access predefined static content.
  • Pay: Simulate a payment transaction.

Prerequisites

  • Python 3.8+
  • A terminal to run commands
  • Optional: Access to OpenAI-compatible model endpoints (e.g., https://hermes.ai.unturf.com/v1)

Setup

  1. Clone the Repository:

    git clone https://github.com/agnt-gg/slop
    cd slop/examples/streamlit
    
  2. Set Up Virtual Environment:

    make setup
    

    This creates a virtual environment (venv) and installs dependencies from requirements.txt.

  3. Configure Model Endpoints: Edit vars.sh to specify your model endpoints:

    # vars.sh
    export MODEL_ENDPOINT_0=https://hermes.ai.unturf.com/v1
    export MODEL_ENDPOINT_1=https://node2.naptha.ai/inference
    export MODEL_ENDPOINT_2=https://node3.naptha.ai/inference
    
    • Gaps in numbering (e.g., skipping MODEL_ENDPOINT_1) are supported.
    • API keys are optional; defaults to "not-needed" if unset (e.g., export MODEL_API_KEY_0=your-key).

Usage

  1. Run the Flask Server: Open a terminal and start the backend:

    make slop-flask
    
    • This sources vars.sh and runs slop_with_models.py on http://localhost:31337.
    • Logs will show model discovery (e.g., Loaded models: [model1, endpoint_7:default]).
  2. Run the Streamlit App: Open a second terminal and start the frontend:

    make slop-streamlit
    
    • Opens in your browser at http://localhost:8501.
    • Displays a UI with Chat, Tools, Memory, Resources, and Pay sections.
  3. Interact:

    • Chat: Select a model from the dropdown and send a message.
    • Tools: Use the calculator or greeter.
    • Memory: Store/retrieve values.
    • Resources: View static content.
    • Pay: Simulate a transaction.
  4. Clean Up (optional):

    make clean
    

    Removes the virtual environment.

Files

  • slop_with_models.py: Flask server implementing the SLOP pattern with dynamic model discovery.
  • streamlit_slop_with_models.py: Streamlit frontend for user interaction.
  • Makefile: Simplifies make setup and running with make slop-flask and make slop-streamlit.
  • vars.sh: Environment variables for model endpoints. Feel free to start with vars.sh.sample!
  • requirements.txt: Dependencies

How It Works

  1. Model Discovery:

    • The Flask server scans MODEL_ENDPOINT_0 to MODEL_ENDPOINT_999 from vars.sh.
    • Queries each endpoints /v1/models using the OpenAI client.
    • Maps model IDs to their respective clients
  2. API Endpoints:

    • /models: Returns the list of discovered models.
    • /chat: Handles chat completions with the selected model.
    • /tools, /memory, /resources, /pay: Implement SLOP pattern features.
  3. Frontend:

    • Streamlit fetches the model list from /models and provides a dropdown.
    • Sends requests to Flask for chat and other functionalities.

Troubleshooting

  • No Models in Dropdown:
    • Check Flask logs (make slop-flask) for errors (e.g., Failed to list models for endpoint_X).
    • Test endpoints with curl <endpoint>/v1/models to ensure theyre OpenAI-compatible.
  • Server Not Responding:
    • Ensure Flask is running (make slop-flask) before starting Streamlit.
  • Environment Variables:
    • Verify vars.sh is correct and sourced (source vars.sh; echo $MODEL_ENDPOINT_0).

Dependencies

Listed in requirements.txt:

  • flask: Backend server
  • streamlit: Frontend UI
  • openai: Client for model endpoints
  • requests: HTTP requests in Streamlit

Learn More

This example demonstrates a flexible, extensible SLOP implementation with a modern UI. Contributions and feedback are welcome!


This is research into the genesis of of the future https://slop.unturf.com/

The code in this example is Public Domain.