8000 Added provider names by ivanleomk · Pull Request #1513 · 567-labs/instructor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added provider names #1513

New issue

Have a question about this project? Sign up for a free GitHub account to open 8000 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

Merged
merged 3 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ jobs:
uv run coverage report
uv run coverage html
env:
INSTRUCTOR_ENV: CI
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
32 changes: 24 additions & 8 deletions instructor/auto_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Union, Literal, overload
from instructor.client import AsyncInstructor, Instructor
import instructor
from instructor.models import KnownModelName

# Type alias for the return type
InstructorType = Union[Instructor, AsyncInstructor]
Expand All @@ -27,22 +28,38 @@

@overload
def from_provider(
model: str, async_client: Literal[True], **kwargs: Any
model: KnownModelName,
async_client: Literal[True] = True,
**kwargs: Any,
) -> AsyncInstructor: ...


@overload
def from_provider(
model: KnownModelName,
async_client: Literal[False] = False,
**kwargs: Any,
) -> Instructor: ...


@overload
def from_provider(
model: str, async_client: Literal[True] = True, **kwargs: Any
) -> AsyncInstructor: ...


@overload
def from_provider(
model: str, async_client: Literal[False], **kwargs: Any
model: str, async_client: Literal[False] = False, **kwargs: Any
) -> Instructor: ...


def from_provider(
model: str,
model: Union[str, KnownModelName], # noqa: UP007
async_client: bool = False,
mode: instructor.Mode | None = None, # noqa: ARG001
mode: Union[instructor.Mode, None] = None, # noqa: ARG001, UP007
**kwargs: Any,
) -> Instructor | AsyncInstructor:
) -> Union[Instructor, AsyncInstructor]: # noqa: UP007
"""Create an Instructor client from a model string.

Args:
Expand Down Expand Up @@ -104,13 +121,12 @@ def from_provider(
client = (
anthropic.AsyncAnthropic() if async_client else anthropic.Anthropic()
)
max_tokens = kwargs.pop("max_tokens", 4096)
return from_anthropic(
client,
model=model_name,
mode=mode if mode else instructor.Mode.ANTHROPIC_TOOLS,
max_tokens=4096
if kwargs.get("max_tokens") is None
else kwargs.get("max_tokens"),
max_tokens=max_tokens,
**kwargs,
)
except ImportError:
Expand Down
135 changes: 135 additions & 0 deletions instructor/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
from typing_extensions import TypeAliasType
from typing import Literal


KnownModelName = TypeAliasType(
"KnownModelName",
Literal[
# Anthropic Models
"anthropic/claude-3-7-sonnet-latest",
"anthropic/claude-3-7-sonnet-20250219",
"anthropic/claude-3-5-sonnet-latest",
"anthropic/claude-3-5-sonnet-20241022",
"anthropic/claude-3-5-sonnet-20240620",
"anthropic/claude-3-5-haiku-latest",
"anthropic/claude-3-5-haiku-20241022",
"anthropic/claude-3-opus-latest",
"anthropic/claude-3-opus-20240229",
"anthropic/claude-3-haiku-20240307",
# Cohere Models
"cohere/c4ai-aya-expanse-32b",
"cohere/c4ai-aya-expanse-8b",
"cohere/command",
"cohere/command-light",
"cohere/command-light-nightly",
"cohere/command-nightly",
"cohere/command-r",
"cohere/command-r-03-2024",
"cohere/command-r-08-2024",
"cohere/command-r-plus",
"cohere/command-r-plus-04-2024",
"cohere/command-r-plus-08-2024",
"cohere/command-r7b-12-2024",
# OpenAI Models
"openai/gpt-3.5-turbo",
"openai/gpt-3.5-turbo-0125",
"openai/gpt-3.5-turbo-1106",
"openai/gpt-3.5-turbo-16k",
"openai/gpt-4",
"openai/gpt-4-0125-preview",
"openai/gpt-4-0613",
"openai/gpt-4-1106-preview",
"openai/gpt-4-32k",
"openai/gpt-4-32k-0613",
"openai/gpt-4-turbo",
"openai/gpt-4-turbo-2024-04-09",
"openai/gpt-4-turbo-preview",
"openai/gpt-4.1",
"openai/gpt-4.1-2025-04-14",
"openai/gpt-4.1-mini",
"openai/gpt-4.1-mini-2025-04-14",
"openai/gpt-4.1-nano",
"openai/gpt-4.1-nano-2025-04-14",
"openai/gpt-4o",
"openai/gpt-4o-2024-05-13",
"openai/gpt-4o-2024-08-06",
"openai/gpt-4o-2024-11-20",
"openai/gpt-4o-audio-preview",
"openai/gpt-4o-audio-preview-2024-10-01",
"openai/gpt-4o-audio-preview-2024-12-17",
"openai/gpt-4o-mini",
"openai/gpt-4o-mini-2024-07-18",
# Groq Models
"groq/gemma2-9b-it",
"groq/llama-3.3-70b-versatile",
"groq/llama-3.1-8b-instant",
"groq/llama3-70b-8192",
"groq/llama3-8b-8192",
"groq/qwen-qwq-32b",
# Mistral
"mistral/codestral-latest",
"mistral/mistral-large-latest",
"mistral/mistral-small-latest",
"mistral/pixtral-large-latest",
"mistral/mistral-saba-latest",
"mistral/ministral-3b-latest",
"mistral/ministral-8b-latest",
# Google Models
"google/gemini-1.5-flash",
"google/gemini-1.5-flash-8b",
"google/gemini-1.5-pro",
"google/gemini-2.0-flash-exp",
"google/gemini-2.0-flash-thinking-exp-01-21",
"google/gemini-exp-1206",
"google/gemini-2.0-flash",
"google/gemini-2.0-flash-lite-preview-02-05",
"google/gemini-2.0-pro-exp-02-05",
"google/gemini-2.5-flash-preview-04-17",
"google/gemini-2.5-pro-exp-03-25",
"google/gemini-2.5-pro-preview-03-25",
# VertexAI Models
"vertexai/gemini-1.5-flash",
"vertexai/gemini-1.5-pro",
"vertexai/gemini-2.0-flash-exp",
"vertexai/gemini-2.0-flash-001",
"vertexai/gemini-2.0-flash-lite",
"vertexai/gemini-2.5-pro-preview-03-25",
"vertexai/gemini-2.5-pro-exp-03-25",
"vertexai/gemini-2.5-flash-preview-04-17",
# Generative AI models
"generative-ai/gemini-1.5-flash",
"generative-ai/gemini-1.5-flash-8b",
"generative-ai/gemini-1.5-pro",
"generative-ai/gemini-2.0-flash-exp",
"generative-ai/gemini-2.0-flash-thinking-exp-01-21",
"generative-ai/gemini-exp-1206",
"generative-ai/gemini-2.0-flash",
"generative-ai/gemini-2.0-flash-lite-preview-02-05",
"generative-ai/gemini-2.0-pro-exp-02-05",
"generative-ai/gemini-2.5-flash-preview-04-17",
"generative-ai/gemini-2.5-pro-exp-03-25",
"generative-ai/gemini-2.5-pro-preview-03-25",
# Fireworks AI
"fireworks/accounts/fireworks/models/llama4-maverick-instruct-basic",
"fireworks/accounts/fireworks/models/llama-v3p1-405b-instruct",
"fireworks/accounts/fireworks/models/llama4-scout-instruct-basic",
"fireworks/accounts/fireworks/models/qwen3-30b-a3b",
"fireworks/accounts/fireworks/models/qwen3-235b-a22b",
"fireworks/accounts/fireworks/models/deepseek-v3",
"fireworks/accounts/fireworks/models/llama-v3p1-8b-instruct",
"fireworks/accounts/fireworks/models/llama-v3p3-70b-instruct",
# Cerebras
"cerebras/llama-4-scout-17b-16e-instruct",
"cerebras/llama3.1-8b",
"cerebras/llama-3.3-70b",
# Writer
"writer/palmyra-x5",
"writer/palmyra-x4",
# Perplexity
"perplexity/sonar-deep-research",
"perplexity/sonar-reasoning-pro",
"perplexity/sonar-pro",
"perplexity/sonar",
"perplexity/r1-1776",
],
)
Loading
0