Skip to content

feat: add model discovery / direct connection #1865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

nzlz
Copy link

@nzlz nzlz commented May 29, 2025

  1. -discover-models flag to discover and select models from local APIs
  2. Add -dd/--discover-direct flag for direct connection to last used model
  3. Support for Ollama, LM Studio, and other OpenAI-compatible endpoints
  4. Persistent configuration storage in ~/.pydantic-ai/discovery.json
  5. Interactive model selection with last-used indicators
  6. Update README with new CLI options

What do you think?

image

…-discover-models flag to discover and select models from local APIs - Add -dd/--discover-direct flag for direct connection to last used model - Support for Ollama, LM Studio, and other OpenAI-compatible endpoints - Persistent configuration storage in ~/.pydantic-ai/discovery.json - Interactive model selection with last-used indicators - Update README with new CLI options
Copy link
Contributor

hyperlint-ai bot commented May 29, 2025

PR Change Summary

Enhanced the CLI with model discovery and direct connection features for improved user experience.

  • Introduced the -d/--discover-models flag for discovering models from local APIs.
  • Added the -dd/--discover-direct flag for direct connection to the last used model.
  • Implemented support for Ollama, LM Studio, and other OpenAI-compatible endpoints.
  • Enabled persistent configuration storage for model discovery.

Modified Files

  • clai/README.md

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

@nzlz
Copy link
Author

nzlz commented Jun 12, 2025

ping @DouweM @Kludex any thoughts? I hope this or alternative solution gets merged so that we can use it locally

I see older related PRs lost in limbo https://github.com/pydantic/pydantic-ai/pull/1103/files

@DouweM
Copy link
Contributor

DouweM commented Jun 12, 2025

@nzlz Thanks for the ping, sorry for having missed this originally.

I like adding OpenAI-compatible API base URL support and model discovery to the CLI, as well as a way to reuse the most recently used model instead of having to specify it again.

I think we can clean up the implementation and UX a bit though, and implement it in a few stages so this is easier to reason about and review:

Stage 1

  1. We add a --provider/-p argument that takes one of the known provider names (see the infer_provider method in providers/__init__.py)
  2. We change --model/-m to take the base model name, without the provider: prefix, if a provider is specified
  3. We change --list/-l to return only model names for that provider (by matching on prefix, and stripping it because -m wouldn't need it)

Stage 2

  1. We extend --provider/-p to take a OpenAI-compatible base URL.
  2. We add a discover_models method to OpenAIProvider that returns a list of model names
  3. If the provider is a base URL, we call OpenAIProvider.discover_models and list those names

Stage 3

  1. We store the last used provider+model or agent in .pydantic-ai
  2. We add a --repeat/-r flag to use the last used model/agent

Stage 4

  1. We add a --choose/-c option that lets the user interactively pick a provider (by number or string, or by entering a URL) and then a model (known or discovered, by number or name) and then launch them into the chat. If a provider name/URL is already specified, we only let them pick a model.

I suggest doing each of those stages in a separate PR.

Would that give you the features you're looking for, even if a bit different than you've implemented it currently?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants