97e91a83f3
Ruff / Ruff (push) Has been cancelled
Test / Core Tests (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.10) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.11) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.12) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.13) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.9) (push) Has been cancelled
Test / Full Coverage (Python 3.11) (push) Has been cancelled
Test / Core Provider Tests (OpenAI) (push) Has been cancelled
Test / Core Provider Tests (Anthropic) (push) Has been cancelled
Test / Core Provider Tests (Google) (push) Has been cancelled
Test / Core Provider Tests (Other) (push) Has been cancelled
Test / Anthropic Tests (push) Has been cancelled
Test / Gemini Tests (push) Has been cancelled
Test / Google GenAI Tests (push) Has been cancelled
Test / Vertex AI Tests (push) Has been cancelled
Test / OpenAI Tests (push) Has been cancelled
Test / Writer Tests (push) Has been cancelled
Test / Auto Client Tests (push) Has been cancelled
ty / type-check (push) Has been cancelled
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""Legacy Gemini-specific schema helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
import functools
|
|
import warnings
|
|
from typing import Any, cast
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from instructor.v2.providers.gemini.utils import map_to_gemini_function_schema
|
|
from instructor.v2.providers.openai.schema import generate_openai_schema
|
|
|
|
|
|
@functools.lru_cache(maxsize=256)
|
|
def generate_gemini_schema(model: type[BaseModel]) -> Any:
|
|
"""Generate a legacy Gemini function schema from a Pydantic model."""
|
|
warnings.warn(
|
|
"generate_gemini_schema is deprecated. The google-generativeai library is being replaced by google-genai.",
|
|
DeprecationWarning,
|
|
stacklevel=2,
|
|
)
|
|
|
|
try:
|
|
genai_types = cast(Any, importlib.import_module("google.generativeai.types"))
|
|
openai_schema = generate_openai_schema(model)
|
|
return genai_types.FunctionDeclaration(
|
|
name=openai_schema["name"],
|
|
description=openai_schema["description"],
|
|
parameters=map_to_gemini_function_schema(openai_schema["parameters"]),
|
|
)
|
|
except ImportError as e:
|
|
raise ImportError(
|
|
"google-generativeai is deprecated. Please install google-genai instead: pip install google-genai"
|
|
) from e
|