This project implements a WebSocket client and server for the Ollama API, allowing users to communicate with an Ollama server. The server is designed to handle multiple concurrent connections and stream responses back to clients.
client.py
)The client connects to the Ollama API via WebSocket and handles incoming messages. It supports concurrent connections and logs important events.
websocket_client(url: str, ollama_url: str)
: Connects to the WebSocket server and handles message exchange.main(concurrency: int, ollama_url: str)
: Initializes multiple WebSocket connections based on the specified concurrency level.validate_url(url: str)
: Validates the provided URL format.server.py
)The server listens for incoming WebSocket connections and manages message forwarding to and from the Ollama API.
OllamaServer
: Manages individual WebSocket connections and message queues.ServerManager
: Manages multiple OllamaServer
instances and forwards messages between them.websocket_handler(request)
: Handles incoming WebSocket connections and initializes OllamaServer
.http_handler(request)
: Handles HTTP requests and forwards them to the appropriate WebSocket server.index.html
)The HTML file provides a user-friendly interface for interacting with the Ollama server. It includes instructions for using the server and a code snippet for the client.
Makefile
)To set up the project, run the following commands:
make install
make server
make client
make test
requirements.txt
)The project requires the following Python packages:
aiohttp
: For asynchronous HTTP and WebSocket handling.test.py
)The test file contains unit tests to ensure the functionality of the client and server components.
Contributions to improve the project are welcome. Please follow the standard practices for submitting issues and pull requests.
This project is licensed under the MIT License.