feat(tools/cogview): Updated cogview tool to support cogview-3 and the latest cogview-3-plus (#8382)
This commit is contained in:
parent
0665268578
commit
740fad06c1
108 changed files with 6498 additions and 390 deletions
|
|
@ -1,7 +1,8 @@
|
|||
from .__version__ import __version__
|
||||
from ._client import ZhipuAI
|
||||
from .core._errors import (
|
||||
from .core import (
|
||||
APIAuthenticationError,
|
||||
APIConnectionError,
|
||||
APIInternalError,
|
||||
APIReachLimitError,
|
||||
APIRequestFailedError,
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
__version__ = "v2.0.1"
|
||||
__version__ = "v2.1.0"
|
||||
|
|
|
|||
|
|
@ -9,15 +9,13 @@ from httpx import Timeout
|
|||
from typing_extensions import override
|
||||
|
||||
from . import api_resource
|
||||
from .core import _jwt_token
|
||||
from .core._base_type import NOT_GIVEN, NotGiven
|
||||
from .core._errors import ZhipuAIError
|
||||
from .core._http_client import ZHIPUAI_DEFAULT_MAX_RETRIES, HttpClient
|
||||
from .core import NOT_GIVEN, ZHIPUAI_DEFAULT_MAX_RETRIES, HttpClient, NotGiven, ZhipuAIError, _jwt_token
|
||||
|
||||
|
||||
class ZhipuAI(HttpClient):
|
||||
chat: api_resource.chat
|
||||
chat: api_resource.chat.Chat
|
||||
api_key: str
|
||||
_disable_token_cache: bool = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
|
@ -28,10 +26,15 @@ class ZhipuAI(HttpClient):
|
|||
max_retries: int = ZHIPUAI_DEFAULT_MAX_RETRIES,
|
||||
http_client: httpx.Client | None = None,
|
||||
custom_headers: Mapping[str, str] | None = None,
|
||||
disable_token_cache: bool = True,
|
||||
_strict_response_validation: bool = False,
|
||||
) -> None:
|
||||
if api_key is None:
|
||||
raise ZhipuAIError("No api_key provided, please provide it through parameters or environment variables")
|
||||
api_key = os.environ.get("ZHIPUAI_API_KEY")
|
||||
if api_key is None:
|
||||
raise ZhipuAIError("未提供api_key,请通过参数或环境变量提供")
|
||||
self.api_key = api_key
|
||||
self._disable_token_cache = disable_token_cache
|
||||
|
||||
if base_url is None:
|
||||
base_url = os.environ.get("ZHIPUAI_BASE_URL")
|
||||
|
|
@ -42,21 +45,31 @@ class ZhipuAI(HttpClient):
|
|||
super().__init__(
|
||||
version=__version__,
|
||||
base_url=base_url,
|
||||
max_retries=max_retries,
|
||||
timeout=timeout,
|
||||
custom_httpx_client=http_client,
|
||||
custom_headers=custom_headers,
|
||||
_strict_response_validation=_strict_response_validation,
|
||||
)
|
||||
self.chat = api_resource.chat.Chat(self)
|
||||
self.images = api_resource.images.Images(self)
|
||||
self.embeddings = api_resource.embeddings.Embeddings(self)
|
||||
self.files = api_resource.files.Files(self)
|
||||
self.fine_tuning = api_resource.fine_tuning.FineTuning(self)
|
||||
self.batches = api_resource.Batches(self)
|
||||
self.knowledge = api_resource.Knowledge(self)
|
||||
self.tools = api_resource.Tools(self)
|
||||
self.videos = api_resource.Videos(self)
|
||||
self.assistant = api_resource.Assistant(self)
|
||||
|
||||
@property
|
||||
@override
|
||||
def _auth_headers(self) -> dict[str, str]:
|
||||
def auth_headers(self) -> dict[str, str]:
|
||||
api_key = self.api_key
|
||||
return {"Authorization": f"{_jwt_token.generate_token(api_key)}"}
|
||||
if self._disable_token_cache:
|
||||
return {"Authorization": f"Bearer {api_key}"}
|
||||
else:
|
||||
return {"Authorization": f"Bearer {_jwt_token.generate_token(api_key)}"}
|
||||
|
||||
def __del__(self) -> None:
|
||||
if not hasattr(self, "_has_custom_http_client") or not hasattr(self, "close") or not hasattr(self, "_client"):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,34 @@
|
|||
from .chat import chat
|
||||
from .assistant import (
|
||||
Assistant,
|
||||
)
|
||||
from .batches import Batches
|
||||
from .chat import (
|
||||
AsyncCompletions,
|
||||
Chat,
|
||||
Completions,
|
||||
)
|
||||
from .embeddings import Embeddings
|
||||
from .files import Files
|
||||
from .fine_tuning import fine_tuning
|
||||
from .files import Files, FilesWithRawResponse
|
||||
from .fine_tuning import FineTuning
|
||||
from .images import Images
|
||||
from .knowledge import Knowledge
|
||||
from .tools import Tools
|
||||
from .videos import (
|
||||
Videos,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Videos",
|
||||
"AsyncCompletions",
|
||||
"Chat",
|
||||
"Completions",
|
||||
"Images",
|
||||
"Embeddings",
|
||||
"Files",
|
||||
"FilesWithRawResponse",
|
||||
"FineTuning",
|
||||
"Batches",
|
||||
"Knowledge",
|
||||
"Tools",
|
||||
"Assistant",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
from .assistant import Assistant
|
||||
|
||||
__all__ = ["Assistant"]
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
import httpx
|
||||
|
||||
from ...core import (
|
||||
NOT_GIVEN,
|
||||
BaseAPI,
|
||||
Body,
|
||||
Headers,
|
||||
NotGiven,
|
||||
StreamResponse,
|
||||
deepcopy_minimal,
|
||||
make_request_options,
|
||||
maybe_transform,
|
||||
)
|
||||
from ...types.assistant import AssistantCompletion
|
||||
from ...types.assistant.assistant_conversation_resp import ConversationUsageListResp
|
||||
from ...types.assistant.assistant_support_resp import AssistantSupportResp
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..._client import ZhipuAI
|
||||
|
||||
from ...types.assistant import assistant_conversation_params, assistant_create_params
|
||||
|
||||
__all__ = ["Assistant"]
|
||||
|
||||
|
||||
class Assistant(BaseAPI):
|
||||
def __init__(self, client: ZhipuAI) -> None:
|
||||
super().__init__(client)
|
||||
|
||||
def conversation(
|
||||
self,
|
||||
assistant_id: str,
|
||||
model: str,
|
||||
messages: list[assistant_create_params.ConversationMessage],
|
||||
*,
|
||||
stream: bool = True,
|
||||
conversation_id: Optional[str] = None,
|
||||
attachments: Optional[list[assistant_create_params.AssistantAttachments]] = None,
|
||||
metadata: dict | None = None,
|
||||
request_id: str = None,
|
||||
user_id: str = None,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> StreamResponse[AssistantCompletion]:
|
||||
body = deepcopy_minimal(
|
||||
{
|
||||
"assistant_id": assistant_id,
|
||||
"model": model,
|
||||
"messages": messages,
|
||||
"stream": stream,
|
||||
"conversation_id": conversation_id,
|
||||
"attachments": attachments,
|
||||
"metadata": metadata,
|
||||
"request_id": request_id,
|
||||
"user_id": user_id,
|
||||
}
|
||||
)
|
||||
return self._post(
|
||||
"/assistant",
|
||||
body=maybe_transform(body, assistant_create_params.AssistantParameters),
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=AssistantCompletion,
|
||||
stream=stream or True,
|
||||
stream_cls=StreamResponse[AssistantCompletion],
|
||||
)
|
||||
|
||||
def query_support(
|
||||
self,
|
||||
*,
|
||||
assistant_id_list: list[str] = None,
|
||||
request_id: str = None,
|
||||
user_id: str = None,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> AssistantSupportResp:
|
||||
body = deepcopy_minimal(
|
||||
{
|
||||
"assistant_id_list": assistant_id_list,
|
||||
"request_id": request_id,
|
||||
"user_id": user_id,
|
||||
}
|
||||
)
|
||||
return self._post(
|
||||
"/assistant/list",
|
||||
body=body,
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=AssistantSupportResp,
|
||||
)
|
||||
|
||||
def query_conversation_usage(
|
||||
self,
|
||||
assistant_id: str,
|
||||
page: int = 1,
|
||||
page_size: int = 10,
|
||||
*,
|
||||
request_id: str = None,
|
||||
user_id: str = None,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> ConversationUsageListResp:
|
||||
body = deepcopy_minimal(
|
||||
{
|
||||
"assistant_id": assistant_id,
|
||||
"page": page,
|
||||
"page_size": page_size,
|
||||
"request_id": request_id,
|
||||
"user_id": user_id,
|
||||
}
|
||||
)
|
||||
return self._post(
|
||||
"/assistant/conversation/list",
|
||||
body=maybe_transform(body, assistant_conversation_params.ConversationParameters),
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=ConversationUsageListResp,
|
||||
)
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Literal, Optional
|
||||
|
||||
import httpx
|
||||
|
||||
from ..core import NOT_GIVEN, BaseAPI, Body, Headers, NotGiven, make_request_options, maybe_transform
|
||||
from ..core.pagination import SyncCursorPage
|
||||
from ..types import batch_create_params, batch_list_params
|
||||
from ..types.batch import Batch
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .._client import ZhipuAI
|
||||
|
||||
|
||||
class Batches(BaseAPI):
|
||||
def __init__(self, client: ZhipuAI) -> None:
|
||||
super().__init__(client)
|
||||
|
||||
def create(
|
||||
self,
|
||||
*,
|
||||
completion_window: str | None = None,
|
||||
endpoint: Literal["/v1/chat/completions", "/v1/embeddings"],
|
||||
input_file_id: str,
|
||||
metadata: Optional[dict[str, str]] | NotGiven = NOT_GIVEN,
|
||||
auto_delete_input_file: bool = True,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> Batch:
|
||||
return self._post(
|
||||
"/batches",
|
||||
body=maybe_transform(
|
||||
{
|
||||
"completion_window": completion_window,
|
||||
"endpoint": endpoint,
|
||||
"input_file_id": input_file_id,
|
||||
"metadata": metadata,
|
||||
"auto_delete_input_file": auto_delete_input_file,
|
||||
},
|
||||
batch_create_params.BatchCreateParams,
|
||||
),
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=Batch,
|
||||
)
|
||||
|
||||
def retrieve(
|
||||
self,
|
||||
batch_id: str,
|
||||
*,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> Batch:
|
||||
"""
|
||||
Retrieves a batch.
|
||||
|
||||
Args:
|
||||
extra_headers: Send extra headers
|
||||
|
||||
extra_body: Add additional JSON properties to the request
|
||||
|
||||
timeout: Override the client-level default timeout for this request, in seconds
|
||||
"""
|
||||
if not batch_id:
|
||||
raise ValueError(f"Expected a non-empty value for `batch_id` but received {batch_id!r}")
|
||||
return self._get(
|
||||
f"/batches/{batch_id}",
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=Batch,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after: str | NotGiven = NOT_GIVEN,
|
||||
limit: int | NotGiven = NOT_GIVEN,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> SyncCursorPage[Batch]:
|
||||
"""List your organization's batches.
|
||||
|
||||
Args:
|
||||
after: A cursor for use in pagination.
|
||||
|
||||
`after` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include after=obj_foo in order to
|
||||
fetch the next page of the list.
|
||||
|
||||
limit: A limit on the number of objects to be returned. Limit can range between 1 and
|
||||
100, and the default is 20.
|
||||
|
||||
extra_headers: Send extra headers
|
||||
|
||||
extra_body: Add additional JSON properties to the request
|
||||
|
||||
timeout: Override the client-level default timeout for this request, in seconds
|
||||
"""
|
||||
return self._get_api_list(
|
||||
"/batches",
|
||||
page=SyncCursorPage[Batch],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"after": after,
|
||||
"limit": limit,
|
||||
},
|
||||
batch_list_params.BatchListParams,
|
||||
),
|
||||
),
|
||||
model=Batch,
|
||||
)
|
||||
|
||||
def cancel(
|
||||
self,
|
||||
batch_id: str,
|
||||
*,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> Batch:
|
||||
"""
|
||||
Cancels an in-progress batch.
|
||||
|
||||
Args:
|
||||
batch_id: The ID of the batch to cancel.
|
||||
extra_headers: Send extra headers
|
||||
|
||||
extra_body: Add additional JSON properties to the request
|
||||
|
||||
timeout: Override the client-level default timeout for this request, in seconds
|
||||
|
||||
"""
|
||||
if not batch_id:
|
||||
raise ValueError(f"Expected a non-empty value for `batch_id` but received {batch_id!r}")
|
||||
return self._post(
|
||||
f"/batches/{batch_id}/cancel",
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=Batch,
|
||||
)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
from .async_completions import AsyncCompletions
|
||||
from .chat import Chat
|
||||
from .completions import Completions
|
||||
|
||||
__all__ = ["AsyncCompletions", "Chat", "Completions"]
|
||||
|
|
@ -1,13 +1,25 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, Literal, Optional, Union
|
||||
|
||||
import httpx
|
||||
|
||||
from ...core._base_api import BaseAPI
|
||||
from ...core._base_type import NOT_GIVEN, Headers, NotGiven
|
||||
from ...core._http_client import make_user_request_input
|
||||
from ...core import (
|
||||
NOT_GIVEN,
|
||||
BaseAPI,
|
||||
Body,
|
||||
Headers,
|
||||
NotGiven,
|
||||
drop_prefix_image_data,
|
||||
make_request_options,
|
||||
maybe_transform,
|
||||
)
|
||||
from ...types.chat.async_chat_completion import AsyncCompletion, AsyncTaskStatus
|
||||
from ...types.chat.code_geex import code_geex_params
|
||||
from ...types.sensitive_word_check import SensitiveWordCheckRequest
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..._client import ZhipuAI
|
||||
|
|
@ -22,6 +34,7 @@ class AsyncCompletions(BaseAPI):
|
|||
*,
|
||||
model: str,
|
||||
request_id: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
user_id: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
do_sample: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
|
||||
temperature: Optional[float] | NotGiven = NOT_GIVEN,
|
||||
top_p: Optional[float] | NotGiven = NOT_GIVEN,
|
||||
|
|
@ -29,50 +42,74 @@ class AsyncCompletions(BaseAPI):
|
|||
seed: int | NotGiven = NOT_GIVEN,
|
||||
messages: Union[str, list[str], list[int], list[list[int]], None],
|
||||
stop: Optional[Union[str, list[str], None]] | NotGiven = NOT_GIVEN,
|
||||
sensitive_word_check: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
sensitive_word_check: Optional[SensitiveWordCheckRequest] | NotGiven = NOT_GIVEN,
|
||||
tools: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
tool_choice: str | NotGiven = NOT_GIVEN,
|
||||
meta: Optional[dict[str, str]] | NotGiven = NOT_GIVEN,
|
||||
extra: Optional[code_geex_params.CodeGeexExtra] | NotGiven = NOT_GIVEN,
|
||||
extra_headers: Headers | None = None,
|
||||
disable_strict_validation: Optional[bool] | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> AsyncTaskStatus:
|
||||
_cast_type = AsyncTaskStatus
|
||||
logger.debug(f"temperature:{temperature}, top_p:{top_p}")
|
||||
if temperature is not None and temperature != NOT_GIVEN:
|
||||
if temperature <= 0:
|
||||
do_sample = False
|
||||
temperature = 0.01
|
||||
# logger.warning("temperature:取值范围是:(0.0, 1.0) 开区间,do_sample重写为:false(参数top_p temperture不生效)") # noqa: E501
|
||||
if temperature >= 1:
|
||||
temperature = 0.99
|
||||
# logger.warning("temperature:取值范围是:(0.0, 1.0) 开区间")
|
||||
if top_p is not None and top_p != NOT_GIVEN:
|
||||
if top_p >= 1:
|
||||
top_p = 0.99
|
||||
# logger.warning("top_p:取值范围是:(0.0, 1.0) 开区间,不能等于 0 或 1")
|
||||
if top_p <= 0:
|
||||
top_p = 0.01
|
||||
# logger.warning("top_p:取值范围是:(0.0, 1.0) 开区间,不能等于 0 或 1")
|
||||
|
||||
if disable_strict_validation:
|
||||
_cast_type = object
|
||||
logger.debug(f"temperature:{temperature}, top_p:{top_p}")
|
||||
if isinstance(messages, list):
|
||||
for item in messages:
|
||||
if item.get("content"):
|
||||
item["content"] = drop_prefix_image_data(item["content"])
|
||||
|
||||
body = {
|
||||
"model": model,
|
||||
"request_id": request_id,
|
||||
"user_id": user_id,
|
||||
"temperature": temperature,
|
||||
"top_p": top_p,
|
||||
"do_sample": do_sample,
|
||||
"max_tokens": max_tokens,
|
||||
"seed": seed,
|
||||
"messages": messages,
|
||||
"stop": stop,
|
||||
"sensitive_word_check": sensitive_word_check,
|
||||
"tools": tools,
|
||||
"tool_choice": tool_choice,
|
||||
"meta": meta,
|
||||
"extra": maybe_transform(extra, code_geex_params.CodeGeexExtra),
|
||||
}
|
||||
return self._post(
|
||||
"/async/chat/completions",
|
||||
body={
|
||||
"model": model,
|
||||
"request_id": request_id,
|
||||
"temperature": temperature,
|
||||
"top_p": top_p,
|
||||
"do_sample": do_sample,
|
||||
"max_tokens": max_tokens,
|
||||
"seed": seed,
|
||||
"messages": messages,
|
||||
"stop": stop,
|
||||
"sensitive_word_check": sensitive_word_check,
|
||||
"tools": tools,
|
||||
"tool_choice": tool_choice,
|
||||
},
|
||||
options=make_user_request_input(extra_headers=extra_headers, timeout=timeout),
|
||||
body=body,
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=_cast_type,
|
||||
enable_stream=False,
|
||||
stream=False,
|
||||
)
|
||||
|
||||
def retrieve_completion_result(
|
||||
self,
|
||||
id: str,
|
||||
extra_headers: Headers | None = None,
|
||||
disable_strict_validation: Optional[bool] | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> Union[AsyncCompletion, AsyncTaskStatus]:
|
||||
_cast_type = Union[AsyncCompletion, AsyncTaskStatus]
|
||||
if disable_strict_validation:
|
||||
_cast_type = object
|
||||
return self._get(
|
||||
path=f"/async-result/{id}",
|
||||
cast_type=_cast_type,
|
||||
options=make_user_request_input(extra_headers=extra_headers, timeout=timeout),
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from ...core._base_api import BaseAPI
|
||||
from ...core import BaseAPI, cached_property
|
||||
from .async_completions import AsyncCompletions
|
||||
from .completions import Completions
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..._client import ZhipuAI
|
||||
pass
|
||||
|
||||
|
||||
class Chat(BaseAPI):
|
||||
completions: Completions
|
||||
@cached_property
|
||||
def completions(self) -> Completions:
|
||||
return Completions(self._client)
|
||||
|
||||
def __init__(self, client: "ZhipuAI") -> None:
|
||||
super().__init__(client)
|
||||
self.completions = Completions(client)
|
||||
self.asyncCompletions = AsyncCompletions(client)
|
||||
@cached_property
|
||||
def asyncCompletions(self) -> AsyncCompletions: # noqa: N802
|
||||
return AsyncCompletions(self._client)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,28 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, Literal, Optional, Union
|
||||
|
||||
import httpx
|
||||
|
||||
from ...core._base_api import BaseAPI
|
||||
from ...core._base_type import NOT_GIVEN, Headers, NotGiven
|
||||
from ...core._http_client import make_user_request_input
|
||||
from ...core._sse_client import StreamResponse
|
||||
from ...core import (
|
||||
NOT_GIVEN,
|
||||
BaseAPI,
|
||||
Body,
|
||||
Headers,
|
||||
NotGiven,
|
||||
StreamResponse,
|
||||
deepcopy_minimal,
|
||||
drop_prefix_image_data,
|
||||
make_request_options,
|
||||
maybe_transform,
|
||||
)
|
||||
from ...types.chat.chat_completion import Completion
|
||||
from ...types.chat.chat_completion_chunk import ChatCompletionChunk
|
||||
from ...types.chat.code_geex import code_geex_params
|
||||
from ...types.sensitive_word_check import SensitiveWordCheckRequest
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..._client import ZhipuAI
|
||||
|
|
@ -24,6 +37,7 @@ class Completions(BaseAPI):
|
|||
*,
|
||||
model: str,
|
||||
request_id: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
user_id: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
do_sample: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
|
||||
stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
|
||||
temperature: Optional[float] | NotGiven = NOT_GIVEN,
|
||||
|
|
@ -32,23 +46,43 @@ class Completions(BaseAPI):
|
|||
seed: int | NotGiven = NOT_GIVEN,
|
||||
messages: Union[str, list[str], list[int], object, None],
|
||||
stop: Optional[Union[str, list[str], None]] | NotGiven = NOT_GIVEN,
|
||||
sensitive_word_check: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
sensitive_word_check: Optional[SensitiveWordCheckRequest] | NotGiven = NOT_GIVEN,
|
||||
tools: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
tool_choice: str | NotGiven = NOT_GIVEN,
|
||||
meta: Optional[dict[str, str]] | NotGiven = NOT_GIVEN,
|
||||
extra: Optional[code_geex_params.CodeGeexExtra] | NotGiven = NOT_GIVEN,
|
||||
extra_headers: Headers | None = None,
|
||||
disable_strict_validation: Optional[bool] | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> Completion | StreamResponse[ChatCompletionChunk]:
|
||||
_cast_type = Completion
|
||||
_stream_cls = StreamResponse[ChatCompletionChunk]
|
||||
if disable_strict_validation:
|
||||
_cast_type = object
|
||||
_stream_cls = StreamResponse[object]
|
||||
return self._post(
|
||||
"/chat/completions",
|
||||
body={
|
||||
logger.debug(f"temperature:{temperature}, top_p:{top_p}")
|
||||
if temperature is not None and temperature != NOT_GIVEN:
|
||||
if temperature <= 0:
|
||||
do_sample = False
|
||||
temperature = 0.01
|
||||
# logger.warning("temperature:取值范围是:(0.0, 1.0) 开区间,do_sample重写为:false(参数top_p temperture不生效)") # noqa: E501
|
||||
if temperature >= 1:
|
||||
temperature = 0.99
|
||||
# logger.warning("temperature:取值范围是:(0.0, 1.0) 开区间")
|
||||
if top_p is not None and top_p != NOT_GIVEN:
|
||||
if top_p >= 1:
|
||||
top_p = 0.99
|
||||
# logger.warning("top_p:取值范围是:(0.0, 1.0) 开区间,不能等于 0 或 1")
|
||||
if top_p <= 0:
|
||||
top_p = 0.01
|
||||
# logger.warning("top_p:取值范围是:(0.0, 1.0) 开区间,不能等于 0 或 1")
|
||||
|
||||
logger.debug(f"temperature:{temperature}, top_p:{top_p}")
|
||||
if isinstance(messages, list):
|
||||
for item in messages:
|
||||
if item.get("content"):
|
||||
item["content"] = drop_prefix_image_data(item["content"])
|
||||
|
||||
body = deepcopy_minimal(
|
||||
{
|
||||
"model": model,
|
||||
"request_id": request_id,
|
||||
"user_id": user_id,
|
||||
"temperature": temperature,
|
||||
"top_p": top_p,
|
||||
"do_sample": do_sample,
|
||||
|
|
@ -60,11 +94,15 @@ class Completions(BaseAPI):
|
|||
"stream": stream,
|
||||
"tools": tools,
|
||||
"tool_choice": tool_choice,
|
||||
},
|
||||
options=make_user_request_input(
|
||||
extra_headers=extra_headers,
|
||||
),
|
||||
cast_type=_cast_type,
|
||||
enable_stream=stream or False,
|
||||
stream_cls=_stream_cls,
|
||||
"meta": meta,
|
||||
"extra": maybe_transform(extra, code_geex_params.CodeGeexExtra),
|
||||
}
|
||||
)
|
||||
return self._post(
|
||||
"/chat/completions",
|
||||
body=body,
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=Completion,
|
||||
stream=stream or False,
|
||||
stream_cls=StreamResponse[ChatCompletionChunk],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@ from typing import TYPE_CHECKING, Optional, Union
|
|||
|
||||
import httpx
|
||||
|
||||
from ..core._base_api import BaseAPI
|
||||
from ..core._base_type import NOT_GIVEN, Headers, NotGiven
|
||||
from ..core._http_client import make_user_request_input
|
||||
from ..core import NOT_GIVEN, BaseAPI, Body, Headers, NotGiven, make_request_options
|
||||
from ..types.embeddings import EmbeddingsResponded
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -22,10 +20,13 @@ class Embeddings(BaseAPI):
|
|||
*,
|
||||
input: Union[str, list[str], list[int], list[list[int]]],
|
||||
model: Union[str],
|
||||
dimensions: Union[int] | NotGiven = NOT_GIVEN,
|
||||
encoding_format: str | NotGiven = NOT_GIVEN,
|
||||
user: str | NotGiven = NOT_GIVEN,
|
||||
request_id: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
sensitive_word_check: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
disable_strict_validation: Optional[bool] | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> EmbeddingsResponded:
|
||||
|
|
@ -37,11 +38,13 @@ class Embeddings(BaseAPI):
|
|||
body={
|
||||
"input": input,
|
||||
"model": model,
|
||||
"dimensions": dimensions,
|
||||
"encoding_format": encoding_format,
|
||||
"user": user,
|
||||
"request_id": request_id,
|
||||
"sensitive_word_check": sensitive_word_check,
|
||||
},
|
||||
options=make_user_request_input(extra_headers=extra_headers, timeout=timeout),
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=_cast_type,
|
||||
enable_stream=False,
|
||||
stream=False,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,19 +1,30 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from collections.abc import Mapping
|
||||
from typing import TYPE_CHECKING, Literal, cast
|
||||
|
||||
import httpx
|
||||
|
||||
from ..core._base_api import BaseAPI
|
||||
from ..core._base_type import NOT_GIVEN, FileTypes, Headers, NotGiven
|
||||
from ..core._files import is_file_content
|
||||
from ..core._http_client import make_user_request_input
|
||||
from ..types.file_object import FileObject, ListOfFileObject
|
||||
from ..core import (
|
||||
NOT_GIVEN,
|
||||
BaseAPI,
|
||||
Body,
|
||||
FileTypes,
|
||||
Headers,
|
||||
NotGiven,
|
||||
_legacy_binary_response,
|
||||
_legacy_response,
|
||||
deepcopy_minimal,
|
||||
extract_files,
|
||||
make_request_options,
|
||||
maybe_transform,
|
||||
)
|
||||
from ..types.files import FileDeleted, FileObject, ListOfFileObject, UploadDetail, file_create_params
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .._client import ZhipuAI
|
||||
|
||||
__all__ = ["Files"]
|
||||
__all__ = ["Files", "FilesWithRawResponse"]
|
||||
|
||||
|
||||
class Files(BaseAPI):
|
||||
|
|
@ -23,30 +34,69 @@ class Files(BaseAPI):
|
|||
def create(
|
||||
self,
|
||||
*,
|
||||
file: FileTypes,
|
||||
purpose: str,
|
||||
file: FileTypes = None,
|
||||
upload_detail: list[UploadDetail] = None,
|
||||
purpose: Literal["fine-tune", "retrieval", "batch"],
|
||||
knowledge_id: str = None,
|
||||
sentence_size: int = None,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> FileObject:
|
||||
if not is_file_content(file):
|
||||
prefix = f"Expected file input `{file!r}`"
|
||||
raise RuntimeError(
|
||||
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(file)} instead."
|
||||
) from None
|
||||
files = [("file", file)]
|
||||
|
||||
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
|
||||
|
||||
if not file and not upload_detail:
|
||||
raise ValueError("At least one of `file` and `upload_detail` must be provided.")
|
||||
body = deepcopy_minimal(
|
||||
{
|
||||
"file": file,
|
||||
"upload_detail": upload_detail,
|
||||
"purpose": purpose,
|
||||
"knowledge_id": knowledge_id,
|
||||
"sentence_size": sentence_size,
|
||||
}
|
||||
)
|
||||
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
|
||||
if files:
|
||||
# It should be noted that the actual Content-Type header that will be
|
||||
# sent to the server will contain a `boundary` parameter, e.g.
|
||||
# multipart/form-data; boundary=---abc--
|
||||
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
|
||||
return self._post(
|
||||
"/files",
|
||||
body={
|
||||
"purpose": purpose,
|
||||
},
|
||||
body=maybe_transform(body, file_create_params.FileCreateParams),
|
||||
files=files,
|
||||
options=make_user_request_input(extra_headers=extra_headers, timeout=timeout),
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=FileObject,
|
||||
)
|
||||
|
||||
# def retrieve(
|
||||
# self,
|
||||
# file_id: str,
|
||||
# *,
|
||||
# extra_headers: Headers | None = None,
|
||||
# extra_body: Body | None = None,
|
||||
# timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
# ) -> FileObject:
|
||||
# """
|
||||
# Returns information about a specific file.
|
||||
#
|
||||
# Args:
|
||||
# file_id: The ID of the file to retrieve information about
|
||||
# extra_headers: Send extra headers
|
||||
#
|
||||
# extra_body: Add additional JSON properties to the request
|
||||
#
|
||||
# timeout: Override the client-level default timeout for this request, in seconds
|
||||
# """
|
||||
# if not file_id:
|
||||
# raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
|
||||
# return self._get(
|
||||
# f"/files/{file_id}",
|
||||
# options=make_request_options(
|
||||
# extra_headers=extra_headers, extra_body=extra_body, timeout=timeout
|
||||
# ),
|
||||
# cast_type=FileObject,
|
||||
# )
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
|
|
@ -55,13 +105,15 @@ class Files(BaseAPI):
|
|||
after: str | NotGiven = NOT_GIVEN,
|
||||
order: str | NotGiven = NOT_GIVEN,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> ListOfFileObject:
|
||||
return self._get(
|
||||
"/files",
|
||||
cast_type=ListOfFileObject,
|
||||
options=make_user_request_input(
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query={
|
||||
"purpose": purpose,
|
||||
|
|
@ -71,3 +123,72 @@ class Files(BaseAPI):
|
|||
},
|
||||
),
|
||||
)
|
||||
|
||||
def delete(
|
||||
self,
|
||||
file_id: str,
|
||||
*,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> FileDeleted:
|
||||
"""
|
||||
Delete a file.
|
||||
|
||||
Args:
|
||||
file_id: The ID of the file to delete
|
||||
extra_headers: Send extra headers
|
||||
|
||||
extra_body: Add additional JSON properties to the request
|
||||
|
||||
timeout: Override the client-level default timeout for this request, in seconds
|
||||
"""
|
||||
if not file_id:
|
||||
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
|
||||
return self._delete(
|
||||
f"/files/{file_id}",
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=FileDeleted,
|
||||
)
|
||||
|
||||
def content(
|
||||
self,
|
||||
file_id: str,
|
||||
*,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> _legacy_response.HttpxBinaryResponseContent:
|
||||
"""
|
||||
Returns the contents of the specified file.
|
||||
|
||||
Args:
|
||||
extra_headers: Send extra headers
|
||||
|
||||
extra_body: Add additional JSON properties to the request
|
||||
|
||||
timeout: Override the client-level default timeout for this request, in seconds
|
||||
"""
|
||||
if not file_id:
|
||||
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
|
||||
extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
|
||||
return self._get(
|
||||
f"/files/{file_id}/content",
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=_legacy_binary_response.HttpxBinaryResponseContent,
|
||||
)
|
||||
|
||||
|
||||
class FilesWithRawResponse:
|
||||
def __init__(self, files: Files) -> None:
|
||||
self._files = files
|
||||
|
||||
self.create = _legacy_response.to_raw_response_wrapper(
|
||||
files.create,
|
||||
)
|
||||
self.list = _legacy_response.to_raw_response_wrapper(
|
||||
files.list,
|
||||
)
|
||||
self.content = _legacy_response.to_raw_response_wrapper(
|
||||
files.content,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
from .fine_tuning import FineTuning
|
||||
from .jobs import Jobs
|
||||
from .models import FineTunedModels
|
||||
|
||||
__all__ = ["Jobs", "FineTunedModels", "FineTuning"]
|
||||
|
|
@ -1,15 +1,18 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from ...core._base_api import BaseAPI
|
||||
from ...core import BaseAPI, cached_property
|
||||
from .jobs import Jobs
|
||||
from .models import FineTunedModels
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..._client import ZhipuAI
|
||||
pass
|
||||
|
||||
|
||||
class FineTuning(BaseAPI):
|
||||
jobs: Jobs
|
||||
@cached_property
|
||||
def jobs(self) -> Jobs:
|
||||
return Jobs(self._client)
|
||||
|
||||
def __init__(self, client: "ZhipuAI") -> None:
|
||||
super().__init__(client)
|
||||
self.jobs = Jobs(client)
|
||||
@cached_property
|
||||
def models(self) -> FineTunedModels:
|
||||
return FineTunedModels(self._client)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
from .jobs import Jobs
|
||||
|
||||
__all__ = ["Jobs"]
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
import httpx
|
||||
|
||||
from ....core import (
|
||||
NOT_GIVEN,
|
||||
BaseAPI,
|
||||
Body,
|
||||
Headers,
|
||||
NotGiven,
|
||||
make_request_options,
|
||||
)
|
||||
from ....types.fine_tuning import (
|
||||
FineTuningJob,
|
||||
FineTuningJobEvent,
|
||||
ListOfFineTuningJob,
|
||||
job_create_params,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ...._client import ZhipuAI
|
||||
|
||||
__all__ = ["Jobs"]
|
||||
|
||||
|
||||
class Jobs(BaseAPI):
|
||||
def __init__(self, client: ZhipuAI) -> None:
|
||||
super().__init__(client)
|
||||
|
||||
def create(
|
||||
self,
|
||||
*,
|
||||
model: str,
|
||||
training_file: str,
|
||||
hyperparameters: job_create_params.Hyperparameters | NotGiven = NOT_GIVEN,
|
||||
suffix: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
request_id: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
validation_file: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> FineTuningJob:
|
||||
return self._post(
|
||||
"/fine_tuning/jobs",
|
||||
body={
|
||||
"model": model,
|
||||
"training_file": training_file,
|
||||
"hyperparameters": hyperparameters,
|
||||
"suffix": suffix,
|
||||
"validation_file": validation_file,
|
||||
"request_id": request_id,
|
||||
},
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=FineTuningJob,
|
||||
)
|
||||
|
||||
def retrieve(
|
||||
self,
|
||||
fine_tuning_job_id: str,
|
||||
*,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> FineTuningJob:
|
||||
return self._get(
|
||||
f"/fine_tuning/jobs/{fine_tuning_job_id}",
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=FineTuningJob,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after: str | NotGiven = NOT_GIVEN,
|
||||
limit: int | NotGiven = NOT_GIVEN,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> ListOfFineTuningJob:
|
||||
return self._get(
|
||||
"/fine_tuning/jobs",
|
||||
cast_type=ListOfFineTuningJob,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query={
|
||||
"after": after,
|
||||
"limit": limit,
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
def cancel(
|
||||
self,
|
||||
fine_tuning_job_id: str,
|
||||
*,
|
||||
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # noqa: E501
|
||||
# The extra values given here take precedence over values defined on the client or passed to this method.
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> FineTuningJob:
|
||||
if not fine_tuning_job_id:
|
||||
raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
|
||||
return self._post(
|
||||
f"/fine_tuning/jobs/{fine_tuning_job_id}/cancel",
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=FineTuningJob,
|
||||
)
|
||||
|
||||
def list_events(
|
||||
self,
|
||||
fine_tuning_job_id: str,
|
||||
*,
|
||||
after: str | NotGiven = NOT_GIVEN,
|
||||
limit: int | NotGiven = NOT_GIVEN,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> FineTuningJobEvent:
|
||||
return self._get(
|
||||
f"/fine_tuning/jobs/{fine_tuning_job_id}/events",
|
||||
cast_type=FineTuningJobEvent,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query={
|
||||
"after": after,
|
||||
"limit": limit,
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
def delete(
|
||||
self,
|
||||
fine_tuning_job_id: str,
|
||||
*,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> FineTuningJob:
|
||||
if not fine_tuning_job_id:
|
||||
raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
|
||||
return self._delete(
|
||||
f"/fine_tuning/jobs/{fine_tuning_job_id}",
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=FineTuningJob,
|
||||
)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
from .fine_tuned_models import FineTunedModels
|
||||
|
||||
__all__ = ["FineTunedModels"]
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import httpx
|
||||
|
||||
from ....core import (
|
||||
NOT_GIVEN,
|
||||
BaseAPI,
|
||||
Body,
|
||||
Headers,
|
||||
NotGiven,
|
||||
make_request_options,
|
||||
)
|
||||
from ....types.fine_tuning.models import FineTunedModelsStatus
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ...._client import ZhipuAI
|
||||
|
||||
__all__ = ["FineTunedModels"]
|
||||
|
||||
|
||||
class FineTunedModels(BaseAPI):
|
||||
def __init__(self, client: ZhipuAI) -> None:
|
||||
super().__init__(client)
|
||||
|
||||
def delete(
|
||||
self,
|
||||
fine_tuned_model: str,
|
||||
*,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> FineTunedModelsStatus:
|
||||
if not fine_tuned_model:
|
||||
raise ValueError(f"Expected a non-empty value for `fine_tuned_model` but received {fine_tuned_model!r}")
|
||||
return self._delete(
|
||||
f"fine_tuning/fine_tuned_models/{fine_tuned_model}",
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=FineTunedModelsStatus,
|
||||
)
|
||||
|
|
@ -4,10 +4,9 @@ from typing import TYPE_CHECKING, Optional
|
|||
|
||||
import httpx
|
||||
|
||||
from ..core._base_api import BaseAPI
|
||||
from ..core._base_type import NOT_GIVEN, Body, Headers, NotGiven
|
||||
from ..core._http_client import make_user_request_input
|
||||
from ..core import NOT_GIVEN, BaseAPI, Body, Headers, NotGiven, make_request_options
|
||||
from ..types.image import ImagesResponded
|
||||
from ..types.sensitive_word_check import SensitiveWordCheckRequest
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .._client import ZhipuAI
|
||||
|
|
@ -27,8 +26,10 @@ class Images(BaseAPI):
|
|||
response_format: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
size: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
style: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
sensitive_word_check: Optional[SensitiveWordCheckRequest] | NotGiven = NOT_GIVEN,
|
||||
user: str | NotGiven = NOT_GIVEN,
|
||||
request_id: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
user_id: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
disable_strict_validation: Optional[bool] | None = None,
|
||||
|
|
@ -45,12 +46,14 @@ class Images(BaseAPI):
|
|||
"n": n,
|
||||
"quality": quality,
|
||||
"response_format": response_format,
|
||||
"sensitive_word_check": sensitive_word_check,
|
||||
"size": size,
|
||||
"style": style,
|
||||
"user": user,
|
||||
"user_id": user_id,
|
||||
"request_id": request_id,
|
||||
},
|
||||
options=make_user_request_input(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
options=make_request_options(extra_headers=extra_headers, extra_body=extra_body, timeout=timeout),
|
||||
cast_type=_cast_type,
|
||||
enable_stream=False,
|
||||
stream=False,
|
||||
)
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue