remove gitignore
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
from .audio import (
|
||||
Audio
|
||||
)
|
||||
|
||||
from .transcriptions import (
|
||||
Transcriptions
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
'Audio',
|
||||
'Transcriptions'
|
||||
]
|
||||
@@ -0,0 +1,119 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, List, Mapping, cast, Optional, Dict
|
||||
from .transcriptions import Transcriptions
|
||||
|
||||
from zhipuai.core._utils import extract_files
|
||||
|
||||
from zhipuai.types.sensitive_word_check import SensitiveWordCheckRequest
|
||||
from zhipuai.types.audio import AudioSpeechParams
|
||||
from ...types.audio import audio_customization_param
|
||||
|
||||
from zhipuai.core import BaseAPI, maybe_transform, StreamResponse
|
||||
from zhipuai.core import NOT_GIVEN, Body, Headers, NotGiven, FileTypes
|
||||
from zhipuai.core import _legacy_response
|
||||
|
||||
import httpx
|
||||
from ...core import BaseAPI, cached_property
|
||||
|
||||
from zhipuai.core import (
|
||||
make_request_options,
|
||||
)
|
||||
from zhipuai.core import deepcopy_minimal
|
||||
from ...types.audio.audio_speech_chunk import AudioSpeechChunk
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from zhipuai._client import ZhipuAI
|
||||
|
||||
__all__ = ["Audio"]
|
||||
|
||||
|
||||
class Audio(BaseAPI):
|
||||
|
||||
@cached_property
|
||||
def transcriptions(self) -> Transcriptions:
|
||||
return Transcriptions(self._client)
|
||||
|
||||
def __init__(self, client: "ZhipuAI") -> None:
|
||||
super().__init__(client)
|
||||
|
||||
def speech(
|
||||
self,
|
||||
*,
|
||||
model: str,
|
||||
input: str = None,
|
||||
voice: str = None,
|
||||
response_format: str = None,
|
||||
sensitive_word_check: Optional[SensitiveWordCheckRequest] | NotGiven = NOT_GIVEN,
|
||||
request_id: str = None,
|
||||
user_id: str = None,
|
||||
stream: bool = False,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
encode_format: str,
|
||||
) -> _legacy_response.HttpxBinaryResponseContent | StreamResponse[AudioSpeechChunk]:
|
||||
body = deepcopy_minimal(
|
||||
{
|
||||
"model": model,
|
||||
"input": input,
|
||||
"voice": voice,
|
||||
"stream": stream,
|
||||
"response_format": response_format,
|
||||
"sensitive_word_check": sensitive_word_check,
|
||||
"request_id": request_id,
|
||||
"user_id": user_id,
|
||||
"encode_format": encode_format
|
||||
}
|
||||
)
|
||||
return self._post(
|
||||
"/audio/speech",
|
||||
body=body,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_type=_legacy_response.HttpxBinaryResponseContent,
|
||||
stream= stream or False,
|
||||
stream_cls=StreamResponse[AudioSpeechChunk]
|
||||
)
|
||||
|
||||
def customization(
|
||||
self,
|
||||
*,
|
||||
model: str,
|
||||
input: str = None,
|
||||
voice_text: str = None,
|
||||
voice_data: FileTypes = None,
|
||||
response_format: str = None,
|
||||
sensitive_word_check: Optional[SensitiveWordCheckRequest] | NotGiven = NOT_GIVEN,
|
||||
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,
|
||||
) -> _legacy_response.HttpxBinaryResponseContent:
|
||||
body = deepcopy_minimal(
|
||||
{
|
||||
"model": model,
|
||||
"input": input,
|
||||
"voice_text": voice_text,
|
||||
"voice_data": voice_data,
|
||||
"response_format": response_format,
|
||||
"sensitive_word_check": sensitive_word_check,
|
||||
"request_id": request_id,
|
||||
"user_id": user_id
|
||||
}
|
||||
)
|
||||
files = extract_files(cast(Mapping[str, object], body), paths=[["voice_data"]])
|
||||
|
||||
if files:
|
||||
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
|
||||
return self._post(
|
||||
"/audio/customization",
|
||||
body=maybe_transform(body, audio_customization_param.AudioCustomizationParam),
|
||||
files=files,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_type=_legacy_response.HttpxBinaryResponseContent
|
||||
)
|
||||
@@ -0,0 +1,74 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, List, Mapping, cast, Optional, Dict
|
||||
from ...types.audio import transcriptions_create_param
|
||||
|
||||
import httpx
|
||||
import logging
|
||||
from typing_extensions import Literal
|
||||
|
||||
from ...core import BaseAPI, deepcopy_minimal, maybe_transform, drop_prefix_image_data
|
||||
from ...core import make_request_options
|
||||
from ...core import StreamResponse
|
||||
from ...types.chat.chat_completion import Completion
|
||||
from ...types.chat.chat_completion_chunk import ChatCompletionChunk
|
||||
from ...types.sensitive_word_check import SensitiveWordCheckRequest
|
||||
from ...core import NOT_GIVEN, Body, Headers, NotGiven, FileTypes
|
||||
from zhipuai.core._utils import extract_files
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..._client import ZhipuAI
|
||||
|
||||
|
||||
__all__ = ["Transcriptions"]
|
||||
|
||||
class Transcriptions(BaseAPI):
|
||||
def __init__(self, client: "ZhipuAI") -> None:
|
||||
super().__init__(client)
|
||||
|
||||
def create(
|
||||
self,
|
||||
*,
|
||||
file: FileTypes,
|
||||
model: str,
|
||||
request_id: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
user_id: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
|
||||
temperature: Optional[float] | NotGiven = NOT_GIVEN,
|
||||
sensitive_word_check: Optional[SensitiveWordCheckRequest] | NotGiven = NOT_GIVEN,
|
||||
extra_headers: Headers | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN
|
||||
) -> Completion | StreamResponse[ChatCompletionChunk]:
|
||||
if temperature is not None and temperature != NOT_GIVEN:
|
||||
if temperature <= 0:
|
||||
temperature = 0.01
|
||||
if temperature >= 1:
|
||||
temperature = 0.99
|
||||
|
||||
body = deepcopy_minimal({
|
||||
"model": model,
|
||||
"file": file,
|
||||
"request_id": request_id,
|
||||
"user_id": user_id,
|
||||
"temperature": temperature,
|
||||
"sensitive_word_check": sensitive_word_check,
|
||||
"stream": stream
|
||||
})
|
||||
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
|
||||
if files:
|
||||
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
|
||||
return self._post(
|
||||
"/audio/transcriptions",
|
||||
body=maybe_transform(body, transcriptions_create_param.TranscriptionsParam),
|
||||
files=files,
|
||||
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],
|
||||
)
|
||||
Reference in New Issue
Block a user