Skip to main content

Unified LLM connectors for OpenAI, Google Gemini, Ollama, and LM Studio.

Project description

rwu-llmconnector

Unified Python connectors for calling large language models through a common interface.

Supported backends:

  • OpenAI (official API and OpenAI-compatible endpoints)
  • Google Gemini (google-genai)
  • Ollama (local server)
  • LM Studio (local or remote server, including stateful conversations)

Installation

pip install rwu-llmconnector

With a virtual environment (recommended):

python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install rwu-llmconnector

Quick start

OpenAI

from openai import OpenAI
from rwu_llmconnector import OpenAIClient

client = OpenAI(api_key="your-openai-api-key")
llm = OpenAIClient(client, model="gpt-4o-mini")

response, prompt_tokens, completion_tokens, reasoning_tokens, runtime = llm.send_request(
    "What is PyPI?",
    system_message="you are a helpful assistant",
)
print(response)

Google Gemini

from google import genai
from rwu_llmconnector import GeminiClient

client = genai.Client(api_key="your-gemini-api-key")
llm = GeminiClient(client, model="gemini-2.5-flash-lite")

response, *_ = llm.send_request(
    "What is PyPI?",
    system_message="you are a helpful assistant",
)
print(response)

Ollama

from rwu_llmconnector import OllamaClient

llm = OllamaClient(model="llama3.2", host="http://localhost:11434")

response, *_ = llm.send_request(
    "What is PyPI?",
    system_message="you are a helpful assistant",
)
print(response)

LM Studio

from rwu_llmconnector import LMStudioClient

llm = LMStudioClient(
    model="qwen/qwen3-4b-2507",
    base_url="http://localhost:1234",
    api_key=None,  # optional; set LMSTUDIO_API_KEY when required
)

response, *_ = llm.send_request(
    "What is PyPI?",
    system_message="you are a helpful assistant",
)
print(response)

For server-side conversation state, use StatefulLMStudioClient instead of LMStudioClient.

Model loader helpers

from rwu_llmconnector.model_loader import load_openai_model, load_ollama_model

llm = load_openai_model("gpt-4o-mini", env="openai")
ollama = load_ollama_model("llama3.2")

Set OPENAI_API_KEY in the environment when using env="openai".

Development

Clone the repository, then:

uv sync --group dev
cp .env.example .env   # add your API keys locally; never commit .env

Run integration tests (live APIs; Ollama skipped without a running server):

uv run pytest -v

Tests load variables from .env via python-dotenv. See .env.example for supported names.

Variable Used for
OPENAI_API_KEY OpenAI
GEMINI_API_KEY or GOOGLE_API_KEY Gemini
LMSTUDIO_BASE_URL, LMSTUDIO_MODEL LM Studio (required for those tests)
LMSTUDIO_API_KEY or MAC_STUDIO_API_KEY LM Studio auth (optional locally)
OLLAMA_MODEL, OLLAMA_HOST Ollama (optional)

Project layout

src/rwu_llmconnector/   # library code
tests/                           # integration tests
pyproject.toml
uv.lock                          # pinned dev dependencies
.env.example                     # template for local secrets (commit this)

Do not commit: .env, .venv/, dist/, __pycache__/, .pytest_cache/, .idea/

Publishing to PyPI

Build and upload (requires PyPI account and API token):

uv build
uv publish

Upload only the files in dist/; do not add dist/ to git.

After creating the GitHub repository, uncomment and set Repository under [project.urls] in pyproject.toml.

License

MIT — see LICENSE.

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

rwu_llmconnector-0.1.0.tar.gz (73.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rwu_llmconnector-0.1.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file rwu_llmconnector-0.1.0.tar.gz.

File metadata

  • Download URL: rwu_llmconnector-0.1.0.tar.gz
  • Upload date:
  • Size: 73.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rwu_llmconnector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f727b68f1498389feb6b421cacdb6cfff61dcfb3b04a8f92a8dc0d686c16509f
MD5 3206508ab8cc0dae2eb5fa640ab707b4
BLAKE2b-256 540df9442a86cbb965511d73bef8ea38a6a2b4fb37c5abb5d6307644f6fe1c4f

See more details on using hashes here.

File details

Details for the file rwu_llmconnector-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rwu_llmconnector-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rwu_llmconnector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4025a92c2c59f6f68b1173762b9766f5e6f60477ba52222a265f0f3a78bcf511
MD5 dfb8f7db757c81290e18a463c0434c29
BLAKE2b-256 fce369b278a9cba207c20c06bcd23ee27afeb8d5d2ae4641b45cb6395f4be71f

See more details on using hashes here.

Supported by

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