Add your description here
Project description
pydantic-ai-lmstudio-provider
A Pydantic AI provider for LM Studio local inference.
Installation
uv add pydantic-ai-lmstudio-provider
Requirements
- Python 3.12+
- LM Studio installed and running locally
Quick Start
-
Start LM Studio and load a model (e.g., via
http://localhost:1234) -
Use with Pydantic AI:
from pydantic_ai import Agent
from pydantic_ai_lmstudio_provider import LMStudioProvider
provider = LMStudioProvider()
agent = Agent(
provider=provider,
model='lmstudio-ai/qwen2.5-7b-instruct', # or any model loaded in LM Studio
)
result = agent.run_sync('What is the capital of France?')
print(result.data)
Configuration
The LMStudioProvider supports several initialization patterns:
Default (uses cached HTTP client)
provider = LMStudioProvider()
Custom API key
provider = LMStudioProvider(api_key='your-api-key')
Custom HTTP client
import httpx
from pydantic_ai_lmstudio_provider import LMStudioProvider
http_client = httpx.AsyncClient(timeout=60.0)
provider = LMStudioProvider(http_client=http_client)
Pass your own OpenAI client
from openai import AsyncOpenAI
from pydantic_ai_lmstudio_provider import LMStudioProvider
openai_client = AsyncOpenAI(
base_url='http://localhost:1234/v1',
api_key='lmstudio',
)
provider = LMStudioProvider(openai_client=openai_client)
LM Studio Setup
- Download and install LM Studio
- Open LM Studio and download a model (recommended: Qwen2.5, Llama 3.2, or Mistral)
- Click "Start Server" and ensure the local server is running at
http://localhost:1234 - Select your model and click "Apply"
Usage with Tools
You can use Pydantic AI agents with tools:
from pydantic import BaseModel
from pydantic_ai import Agent
from pydantic_ai_lmstudio_provider import LMStudioProvider
class WeatherResult(BaseModel):
temperature: int
conditions: str
weather_agent = Agent(
provider=LMStudioProvider(),
model='lmstudio-ai/qwen2.5-7b-instruct',
result_type=WeatherResult,
)
result = weather_agent.run_sync('What is the weather in Paris?')
print(result.data.temperature) # e.g., 22
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_ai_lmstudio_provider-0.1.0.tar.gz.
File metadata
- Download URL: pydantic_ai_lmstudio_provider-0.1.0.tar.gz
- Upload date:
- Size: 2.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9bd5662715655d01308091dc66c364ec8bc14998382e3b12dc454983b1a2e01
|
|
| MD5 |
628555861dacd44b31e752b8cc96de58
|
|
| BLAKE2b-256 |
be4c91579b8bac7175cc39e8e8df75b2e69928cbae4d8e713cb1f8c9635fde1e
|
File details
Details for the file pydantic_ai_lmstudio_provider-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_ai_lmstudio_provider-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf605fe5310eb067e5c237c7f9ea6dd963fb2b166985e32972f29262d4ff0272
|
|
| MD5 |
7c8bb616ad03183ec40f765f4231ead4
|
|
| BLAKE2b-256 |
9e3f881af6aed35e5b2f906af7e7aaaed9da9db34f7e45403d9a024169ea1d63
|