참고소스 수정본

This commit is contained in:
LASTA_DEV01\lasta
2026-05-12 19:40:31 +09:00
parent 0f34a451fc
commit 2e9204243d
8708 changed files with 3259488 additions and 869 deletions

View File

@@ -0,0 +1 @@
"""Provider implementation."""

View File

@@ -0,0 +1,66 @@
from __future__ import annotations
from typing import overload, Any
import groq
import instructor
@overload
def from_groq(
client: groq.Groq,
mode: instructor.Mode = instructor.Mode.TOOLS,
**kwargs: Any,
) -> instructor.Instructor: ...
@overload
def from_groq(
client: groq.AsyncGroq,
mode: instructor.Mode = instructor.Mode.TOOLS,
**kwargs: Any,
) -> instructor.AsyncInstructor: ...
def from_groq(
client: groq.Groq | groq.AsyncGroq,
mode: instructor.Mode = instructor.Mode.TOOLS,
**kwargs: Any,
) -> instructor.Instructor | instructor.AsyncInstructor:
valid_modes = {
instructor.Mode.JSON,
instructor.Mode.TOOLS,
}
if mode not in valid_modes:
from ...core.exceptions import ModeError
raise ModeError(
mode=str(mode), provider="Groq", valid_modes=[str(m) for m in valid_modes]
)
if not isinstance(client, (groq.Groq, groq.AsyncGroq)):
from ...core.exceptions import ClientError
raise ClientError(
f"Client must be an instance of groq.Groq or groq.AsyncGroq. "
f"Got: {type(client).__name__}"
)
if isinstance(client, groq.Groq):
return instructor.Instructor(
client=client,
create=instructor.patch(create=client.chat.completions.create, mode=mode),
provider=instructor.Provider.GROQ,
mode=mode,
**kwargs,
)
else:
return instructor.AsyncInstructor(
client=client,
create=instructor.patch(create=client.chat.completions.create, mode=mode),
provider=instructor.Provider.GROQ,
mode=mode,
**kwargs,
)