Update slop_with_models.py See merge request engineering/unturf/slop.unturf.com!1 |
||
|---|---|---|
| static | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| README.md | ||
| requirements.txt | ||
| slop_with_models.py | ||
| streamlit_slop_with_models.py | ||
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
-
Clone the Repository:
git clone https://github.com/agnt-gg/slop cd slop/examples/streamlit -
Set Up Virtual Environment:
make setupThis creates a virtual environment (
venv) and installs dependencies fromrequirements.txt. -
Configure Model Endpoints: Edit
vars.shto 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).
- Gaps in numbering (e.g., skipping
Usage
-
Run the Flask Server: Open a terminal and start the backend:
make slop-flask- This sources
vars.shand runsslop_with_models.pyonhttp://localhost:31337. - Logs will show model discovery (e.g.,
Loaded models: [model1, endpoint_7:default]).
- This sources
-
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.
- Opens in your browser at
-
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.
-
Clean Up (optional):
make cleanRemoves 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: Simplifiesmake setupand running withmake slop-flaskandmake slop-streamlit.vars.sh: Environment variables for model endpoints. Feel free to start withvars.sh.sample!requirements.txt: Dependencies
How It Works
-
Model Discovery:
- The Flask server scans
MODEL_ENDPOINT_0toMODEL_ENDPOINT_999fromvars.sh. - Queries each endpoint’s
/v1/modelsusing the OpenAI client. - Maps model IDs to their respective clients
- The Flask server scans
-
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.
-
Frontend:
- Streamlit fetches the model list from
/modelsand provides a dropdown. - Sends requests to Flask for chat and other functionalities.
- Streamlit fetches the model list from
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/modelsto ensure they’re OpenAI-compatible.
- Check Flask logs (
- Server Not Responding:
- Ensure Flask is running (
make slop-flask) before starting Streamlit.
- Ensure Flask is running (
- Environment Variables:
- Verify
vars.shis correct and sourced (source vars.sh; echo $MODEL_ENDPOINT_0).
- Verify
Dependencies
Listed in requirements.txt:
flask: Backend serverstreamlit: Frontend UIopenai: Client for model endpointsrequests: 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.