Skip to main content

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

  1. Start LM Studio and load a model (e.g., via http://localhost:1234)

  2. 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

  1. Download and install LM Studio
  2. Open LM Studio and download a model (recommended: Qwen2.5, Llama 3.2, or Mistral)
  3. Click "Start Server" and ensure the local server is running at http://localhost:1234
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_ai_lmstudio_provider-0.1.0.tar.gz (2.0 kB view details)

Uploaded Source

Built Distribution

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

pydantic_ai_lmstudio_provider-0.1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

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

Hashes for pydantic_ai_lmstudio_provider-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a9bd5662715655d01308091dc66c364ec8bc14998382e3b12dc454983b1a2e01
MD5 628555861dacd44b31e752b8cc96de58
BLAKE2b-256 be4c91579b8bac7175cc39e8e8df75b2e69928cbae4d8e713cb1f8c9635fde1e

See more details on using hashes here.

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

Hashes for pydantic_ai_lmstudio_provider-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf605fe5310eb067e5c237c7f9ea6dd963fb2b166985e32972f29262d4ff0272
MD5 7c8bb616ad03183ec40f765f4231ead4
BLAKE2b-256 9e3f881af6aed35e5b2f906af7e7aaaed9da9db34f7e45403d9a024169ea1d63

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