synapsai-python 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- synapsai/__init__.py +16 -0
- synapsai/client.py +628 -0
- synapsai/exceptions.py +64 -0
- synapsai/logging.py +70 -0
- synapsai/processing.py +100 -0
- synapsai/resources/__init__.py +59 -0
- synapsai/resources/audio.py +495 -0
- synapsai/resources/chat.py +199 -0
- synapsai/resources/classifications.py +454 -0
- synapsai/resources/completions.py +162 -0
- synapsai/resources/embeddings.py +207 -0
- synapsai/resources/feature_extraction.py +80 -0
- synapsai/resources/fill_mask.py +88 -0
- synapsai/resources/images.py +560 -0
- synapsai/resources/models.py +80 -0
- synapsai/resources/question_answering.py +257 -0
- synapsai/resources/rerank.py +90 -0
- synapsai/resources/videos.py +303 -0
- synapsai/types/__init__.py +144 -0
- synapsai/types/audio.py +177 -0
- synapsai/types/classifications.py +228 -0
- synapsai/types/common.py +56 -0
- synapsai/types/completion.py +244 -0
- synapsai/types/embeddings.py +68 -0
- synapsai/types/feature_extraction.py +31 -0
- synapsai/types/fill_mask.py +38 -0
- synapsai/types/images.py +172 -0
- synapsai/types/models.py +28 -0
- synapsai/types/question_answering.py +127 -0
- synapsai/types/rerank.py +40 -0
- synapsai/types/videos.py +92 -0
- synapsai/utils.py +32 -0
- synapsai_python-0.1.0.dist-info/METADATA +312 -0
- synapsai_python-0.1.0.dist-info/RECORD +37 -0
- synapsai_python-0.1.0.dist-info/WHEEL +5 -0
- synapsai_python-0.1.0.dist-info/licenses/LICENSE +201 -0
- synapsai_python-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Copyright 2026 SynapsAI Technologies Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
Type definitions for SynapsAI client library
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from .completion import *
|
|
20
|
+
from .images import *
|
|
21
|
+
from .videos import *
|
|
22
|
+
from .embeddings import *
|
|
23
|
+
from .audio import *
|
|
24
|
+
from .classifications import *
|
|
25
|
+
from .question_answering import *
|
|
26
|
+
from .common import *
|
|
27
|
+
from .models import *
|
|
28
|
+
from .feature_extraction import *
|
|
29
|
+
from .fill_mask import *
|
|
30
|
+
from .rerank import *
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
# Models types
|
|
34
|
+
"Model",
|
|
35
|
+
"Models",
|
|
36
|
+
|
|
37
|
+
# Chat types
|
|
38
|
+
"ChatCompletionRequest",
|
|
39
|
+
"ChatCompletionResponse",
|
|
40
|
+
"ChatCompletionChunk",
|
|
41
|
+
"ChatMessage",
|
|
42
|
+
"ChatRole",
|
|
43
|
+
"ReasoningEffort",
|
|
44
|
+
"ChatCompletionChoice",
|
|
45
|
+
"CompletionChoice",
|
|
46
|
+
"Delta",
|
|
47
|
+
"FunctionCall",
|
|
48
|
+
"Tool",
|
|
49
|
+
"ToolCall",
|
|
50
|
+
"ChatCompletionMessageToolCall",
|
|
51
|
+
"ChatCompletionMessageToolCallFunction",
|
|
52
|
+
"DeltaFunctionCall",
|
|
53
|
+
"DeltaToolCall",
|
|
54
|
+
"ChoiceDeltaToolCall",
|
|
55
|
+
"ChatCompletionNamedToolChoice",
|
|
56
|
+
"ToolChoice",
|
|
57
|
+
"ChoiceDelta",
|
|
58
|
+
|
|
59
|
+
# Image types
|
|
60
|
+
"ImageGenerateRequest",
|
|
61
|
+
"ImageGenerateResponse",
|
|
62
|
+
"ImageEditRequest",
|
|
63
|
+
"ImageEditResponse",
|
|
64
|
+
"ImageAnalysisRequest",
|
|
65
|
+
"ImageAnalysisResponse",
|
|
66
|
+
"Image",
|
|
67
|
+
"ImageSource",
|
|
68
|
+
|
|
69
|
+
# Video types
|
|
70
|
+
"Video",
|
|
71
|
+
"VideoCreateError",
|
|
72
|
+
"VideoCreateRequest",
|
|
73
|
+
"VideoDeleteResponse",
|
|
74
|
+
"VideoInputReference",
|
|
75
|
+
"VideoStatus",
|
|
76
|
+
|
|
77
|
+
# Embedding types
|
|
78
|
+
"EmbeddingRequest",
|
|
79
|
+
"EmbeddingResponse",
|
|
80
|
+
"Embedding",
|
|
81
|
+
"SimilarityResponse",
|
|
82
|
+
"SimilarityResult",
|
|
83
|
+
|
|
84
|
+
# Audio types
|
|
85
|
+
"AudioSpeechRequest",
|
|
86
|
+
"AudioSpeechResponse",
|
|
87
|
+
"AudioTranscriptionRequest",
|
|
88
|
+
"AudioTranscriptionResponse",
|
|
89
|
+
"AudioTranslationRequest",
|
|
90
|
+
"AudioTranslationResponse",
|
|
91
|
+
"AudioTranscriptionChunk",
|
|
92
|
+
"AudioTranslationChunk",
|
|
93
|
+
"AudioFormat",
|
|
94
|
+
"Transcription",
|
|
95
|
+
"Usage",
|
|
96
|
+
|
|
97
|
+
# Classification types
|
|
98
|
+
"AudioClassificationRequest",
|
|
99
|
+
"AudioClassificationResponse",
|
|
100
|
+
"ImageClassificationRequest",
|
|
101
|
+
"ImageClassificationResponse",
|
|
102
|
+
"TextClassificationRequest",
|
|
103
|
+
"TextClassificationResponse",
|
|
104
|
+
"TokenClassificationRequest",
|
|
105
|
+
"TokenClassificationResponse",
|
|
106
|
+
"VideoClassificationRequest",
|
|
107
|
+
"VideoClassificationResponse",
|
|
108
|
+
"ZeroShotAudioClassificationRequest",
|
|
109
|
+
"ZeroShotAudioClassificationResponse",
|
|
110
|
+
"ZeroShotClassificationRequest",
|
|
111
|
+
"ZeroShotClassificationResponse",
|
|
112
|
+
"ZeroShotImageClassificationRequest",
|
|
113
|
+
"ZeroShotImageClassificationResponse",
|
|
114
|
+
"ZeroShotObjectDetectionRequest",
|
|
115
|
+
"ZeroShotObjectDetectionResponse",
|
|
116
|
+
|
|
117
|
+
# Question Answering types
|
|
118
|
+
"DocumentQuestionAnsweringRequest",
|
|
119
|
+
"DocumentQuestionAnsweringResponse",
|
|
120
|
+
"QuestionAnsweringRequest",
|
|
121
|
+
"QuestionAnsweringResponse",
|
|
122
|
+
"TableQuestionAnsweringRequest",
|
|
123
|
+
"TableQuestionAnsweringResponse",
|
|
124
|
+
"VisualQuestionAnsweringRequest",
|
|
125
|
+
"VisualQuestionAnsweringResponse",
|
|
126
|
+
|
|
127
|
+
# Feature extraction types
|
|
128
|
+
"FeatureExtractionRequest",
|
|
129
|
+
"FeatureExtractionResponse",
|
|
130
|
+
|
|
131
|
+
# Fill mask types
|
|
132
|
+
"FillMaskRequest",
|
|
133
|
+
"FillMaskResponse",
|
|
134
|
+
|
|
135
|
+
# Text ranking types
|
|
136
|
+
"RerankRequest",
|
|
137
|
+
"RerankResult",
|
|
138
|
+
"RerankResponse",
|
|
139
|
+
|
|
140
|
+
# Common types
|
|
141
|
+
"APIResponse",
|
|
142
|
+
"Error",
|
|
143
|
+
"ErrorResponse",
|
|
144
|
+
]
|
synapsai/types/audio.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Copyright 2026 SynapsAI Technologies Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
Audio speech and transcription type definitions
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from typing import Optional, List, Literal, Union
|
|
20
|
+
from pydantic import BaseModel, Field
|
|
21
|
+
from enum import Enum
|
|
22
|
+
|
|
23
|
+
from .common import APIResponse, Usage
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AudioFormat(str, Enum):
|
|
27
|
+
"""Audio format options"""
|
|
28
|
+
MP3 = "mp3"
|
|
29
|
+
OPUS = "opus"
|
|
30
|
+
AAC = "aac"
|
|
31
|
+
FLAC = "flac"
|
|
32
|
+
WAV = "wav"
|
|
33
|
+
PCM = "pcm"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class AudioSpeechRequest(BaseModel):
|
|
37
|
+
"""Audio speech request"""
|
|
38
|
+
model: str
|
|
39
|
+
input: str = Field(max_length=4096)
|
|
40
|
+
response_format: Optional[AudioFormat] = AudioFormat.MP3
|
|
41
|
+
speed: Optional[float] = Field(default=1.0, ge=0.25, le=4.0)
|
|
42
|
+
stream: Optional[bool] = False
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class AudioSpeechResponse(BaseModel):
|
|
46
|
+
"""Audio speech response"""
|
|
47
|
+
content: bytes = Field(description="Audio content as bytes")
|
|
48
|
+
content_type: str = Field(description="MIME type of the audio")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class TimestampGranularity(str, Enum):
|
|
52
|
+
"""Timestamp granularity options"""
|
|
53
|
+
WORD = "word"
|
|
54
|
+
SEGMENT = "segment"
|
|
55
|
+
CHAR = "char"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class Word(BaseModel):
|
|
59
|
+
"""Word-level timestamp"""
|
|
60
|
+
word: str
|
|
61
|
+
start: float
|
|
62
|
+
end: float
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class Segment(BaseModel):
|
|
66
|
+
"""Segment-level transcript"""
|
|
67
|
+
id: int
|
|
68
|
+
start: float
|
|
69
|
+
end: float
|
|
70
|
+
text: str
|
|
71
|
+
temperature: float
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class Char(BaseModel):
|
|
75
|
+
"""Character-level timestamp"""
|
|
76
|
+
char: str
|
|
77
|
+
start: float
|
|
78
|
+
end: float
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class AudioTranscriptionRequest(BaseModel):
|
|
82
|
+
"""Audio transcription request"""
|
|
83
|
+
model: str
|
|
84
|
+
file: str = Field(description="Audio file to transcribe (base64 encoded or file path)")
|
|
85
|
+
language: Optional[str] = Field(default=None, description="ISO-639-1 language code")
|
|
86
|
+
prompt: Optional[str] = Field(default=None, max_length=244)
|
|
87
|
+
response_format: Literal["json", "text", "str", "verbose_json", "vtt"] = "json"
|
|
88
|
+
temperature: Optional[float] = Field(default=0.0, ge=0.0, le=1.0)
|
|
89
|
+
seed: Optional[int] = None
|
|
90
|
+
top_p: Optional[float] = None
|
|
91
|
+
top_k: Optional[int] = None
|
|
92
|
+
n: Optional[int] = None
|
|
93
|
+
frequency_penalty: Optional[float] = None
|
|
94
|
+
presence_penalty: Optional[float] = None
|
|
95
|
+
max_completion_tokens: Optional[int] = None
|
|
96
|
+
to_language: Optional[str] = None
|
|
97
|
+
repetition_penalty: Optional[float] = None
|
|
98
|
+
timestamp_granularities: Optional[List[TimestampGranularity]] = Field(
|
|
99
|
+
default=[TimestampGranularity.SEGMENT]
|
|
100
|
+
)
|
|
101
|
+
stream: Optional[bool] = False
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class Transcription(BaseModel):
|
|
105
|
+
"""Transcription object"""
|
|
106
|
+
text: str
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class AudioTranscriptionResponse(APIResponse):
|
|
110
|
+
"""Audio transcription response"""
|
|
111
|
+
object: Literal["transcription"] = "transcription"
|
|
112
|
+
text: str
|
|
113
|
+
language: Optional[str] = None
|
|
114
|
+
duration: Optional[float] = None
|
|
115
|
+
words: Optional[List[Word]] = None
|
|
116
|
+
segments: Optional[List[Segment]] = None
|
|
117
|
+
chars: Optional[List[Char]] = None
|
|
118
|
+
usage: Optional[dict] = None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class AudioTranslationRequest(BaseModel):
|
|
122
|
+
"""Audio translation request"""
|
|
123
|
+
model: str
|
|
124
|
+
file: str = Field(description="Audio file to translate (base64 encoded or file path)")
|
|
125
|
+
language: Optional[str] = Field(default=None, description="ISO-639-1 language code")
|
|
126
|
+
prompt: Optional[str] = Field(default=None, max_length=244)
|
|
127
|
+
response_format: Literal["json", "text", "str", "verbose_json", "vtt"] = "json"
|
|
128
|
+
temperature: Optional[float] = Field(default=0.0, ge=0.0, le=1.0)
|
|
129
|
+
seed: Optional[int] = None
|
|
130
|
+
top_p: Optional[float] = None
|
|
131
|
+
top_k: Optional[int] = None
|
|
132
|
+
n: Optional[int] = None
|
|
133
|
+
frequency_penalty: Optional[float] = None
|
|
134
|
+
presence_penalty: Optional[float] = None
|
|
135
|
+
max_completion_tokens: Optional[int] = None
|
|
136
|
+
to_language: Optional[str] = None
|
|
137
|
+
repetition_penalty: Optional[float] = None
|
|
138
|
+
stream: Optional[bool] = False
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class AudioTranslationResponse(APIResponse):
|
|
142
|
+
"""Audio translation response"""
|
|
143
|
+
object: Literal["translation"] = "translation"
|
|
144
|
+
text: str
|
|
145
|
+
language: Optional[str] = None
|
|
146
|
+
duration: Optional[float] = None
|
|
147
|
+
segments: Optional[List[Segment]] = None
|
|
148
|
+
usage: Optional[dict] = None
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class Delta(BaseModel):
|
|
152
|
+
"""Delta object for streaming responses"""
|
|
153
|
+
content: Optional[str] = None
|
|
154
|
+
|
|
155
|
+
class ChatCompletionChoice(BaseModel):
|
|
156
|
+
"""Choice object"""
|
|
157
|
+
delta: Optional[Delta] = None
|
|
158
|
+
logprobs: Optional[dict | list[dict]] = None
|
|
159
|
+
|
|
160
|
+
class ChatCompletionResponse(APIResponse):
|
|
161
|
+
"""Chat completion response"""
|
|
162
|
+
model: str
|
|
163
|
+
object: Literal["chat.completion"] = "chat.completion"
|
|
164
|
+
choices: List[ChatCompletionChoice]
|
|
165
|
+
system_fingerprint: Optional[str] = None
|
|
166
|
+
usage: Optional[Usage] = None
|
|
167
|
+
|
|
168
|
+
class AudioTranscriptionChunk(APIResponse):
|
|
169
|
+
"""Chat completion chunk for streaming"""
|
|
170
|
+
model: str
|
|
171
|
+
object: Literal["transcription.chunk"] = "transcription.chunk"
|
|
172
|
+
choices: List[ChatCompletionChoice]
|
|
173
|
+
usage: Optional[Usage] = None
|
|
174
|
+
|
|
175
|
+
class AudioTranslationChunk(AudioTranscriptionChunk):
|
|
176
|
+
"""Streaming translation chunk"""
|
|
177
|
+
object: Literal["translation.chunk"] = "translation.chunk"
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Copyright 2026 SynapsAI Technologies Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
Classification type definitions
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from typing import Optional, Dict, Any, Union, List, Literal
|
|
20
|
+
from pydantic import BaseModel, Field, ConfigDict
|
|
21
|
+
from enum import Enum
|
|
22
|
+
from numpy import ndarray
|
|
23
|
+
from PIL.Image import Image as PilImage
|
|
24
|
+
|
|
25
|
+
from .common import APIResponse, Usage
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class AudioClassificationData(BaseModel):
|
|
29
|
+
"""Data model for audio classification result"""
|
|
30
|
+
label: str = Field(..., description="The label predicted for the audio")
|
|
31
|
+
score: float = Field(..., description="The probability/score for the label")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class AudioClassificationRequest(BaseModel):
|
|
35
|
+
"""Request model for audio classification"""
|
|
36
|
+
model: str
|
|
37
|
+
inputs: Union[ndarray, bytes, Dict[str, Any]] = Field(..., description="The audio data to classify. Can be raw waveform, bytes from an audio file, or a dict with sampling rate and raw audio.")
|
|
38
|
+
top_k: Optional[int] = Field(default=None, description="The number of top labels that will be returned by the pipeline.")
|
|
39
|
+
function_to_apply: Optional[Literal['sigmoid','softmax','none']] = Field(default=None, description="The function to apply to the model outputs to retrieve scores. Valid: 'sigmoid', 'softmax', 'none'.")
|
|
40
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class AudioClassificationResponse(APIResponse):
|
|
44
|
+
"""Audio classification response"""
|
|
45
|
+
object: Literal["list"] = "list"
|
|
46
|
+
data: List[AudioClassificationData]
|
|
47
|
+
usage: Optional[Usage] = None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class ImageClassificationData(BaseModel):
|
|
51
|
+
"""Data model for image classification result"""
|
|
52
|
+
label: str = Field(..., description="The label identified by the model")
|
|
53
|
+
score: float = Field(..., description="The score attributed by the model for that label")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class ImageClassificationRequest(BaseModel):
|
|
57
|
+
"""Request model for image classification"""
|
|
58
|
+
model: str
|
|
59
|
+
inputs: Union[str, List[str], PilImage, List[PilImage]] = Field(..., description="The image or list of images to classify. Can be a URL, base64, file path or PIL Image.")
|
|
60
|
+
function_to_apply: Optional[Literal['sigmoid','softmax','none']] = Field(default='default', description="The function to apply to the model outputs in order to retrieve the scores.")
|
|
61
|
+
top_k: Optional[int] = Field(default=5, description="The number of top labels that will be returned by the pipeline.")
|
|
62
|
+
timeout: Optional[float] = Field(default=None, description="Maximum time in seconds to wait for fetching images from the web. If None, no timeout is set.")
|
|
63
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
64
|
+
|
|
65
|
+
class ImageClassificationResponse(APIResponse):
|
|
66
|
+
"""Image classification response"""
|
|
67
|
+
object: Literal["list"] = "list"
|
|
68
|
+
data: List[ImageClassificationData]
|
|
69
|
+
usage: Optional[Usage] = None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class TextClassificationData(BaseModel):
|
|
73
|
+
"""Data model for text classification result"""
|
|
74
|
+
label: str = Field(..., description="The label predicted")
|
|
75
|
+
score: float = Field(..., description="The corresponding probability")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class TextClassificationRequest(BaseModel):
|
|
79
|
+
"""Request model for text classification"""
|
|
80
|
+
model: str
|
|
81
|
+
inputs: Union[str, List[str], Dict[str, Any], List[Dict[str, Any]]] = Field(..., description="One or several texts to classify. To use text pairs, send a dict with {'text', 'text_pair'} or a list of such dicts.")
|
|
82
|
+
top_k: Optional[int] = Field(default=1, description="How many results to return.")
|
|
83
|
+
function_to_apply: Optional[Literal['sigmoid','softmax','none']] = Field(default='default', description="The function to apply to the model outputs in order to retrieve the scores.")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class TextClassificationResponse(APIResponse):
|
|
87
|
+
"""Text classification response"""
|
|
88
|
+
object: Literal["list"] = "list"
|
|
89
|
+
data: List[TextClassificationData]
|
|
90
|
+
usage: Optional[Usage] = None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class TokenClassificationData(BaseModel):
|
|
94
|
+
"""Data model for token classification result"""
|
|
95
|
+
word: str = Field(..., description="The token/word")
|
|
96
|
+
score: float = Field(..., description="The score for this token")
|
|
97
|
+
entity: str = Field(..., description="The entity label for the token")
|
|
98
|
+
index: int = Field(..., description="Token index")
|
|
99
|
+
start: int = Field(..., description="Start char offset in the original text")
|
|
100
|
+
end: int = Field(..., description="End char offset in the original text")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class TokenClassificationRequest(BaseModel):
|
|
104
|
+
"""Request model for token classification"""
|
|
105
|
+
model: str
|
|
106
|
+
inputs: Union[str, List[str]] = Field(..., description="One or several texts (or one list of texts) for token classification.")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class TokenClassificationResponse(APIResponse):
|
|
110
|
+
"""Token classification response"""
|
|
111
|
+
object: Literal["list"] = "list"
|
|
112
|
+
data: List[TokenClassificationData] | list
|
|
113
|
+
usage: Optional[Usage] = None
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class VideoClassificationData(BaseModel):
|
|
117
|
+
"""Data model for video classification result"""
|
|
118
|
+
label: str = Field(..., description="The label identified by the model")
|
|
119
|
+
score: float = Field(..., description="The score attributed by the model for that label")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class VideoClassificationRequest(BaseModel):
|
|
123
|
+
"""Request model for video classification"""
|
|
124
|
+
model: str
|
|
125
|
+
inputs: Union[str, List[str]] = Field(..., description="A http link to a video or a local path to a video. Accepts single video or a batch.")
|
|
126
|
+
top_k: Optional[int] = Field(default=5, description="The number of top labels that will be returned by the pipeline.")
|
|
127
|
+
num_frames: Optional[int] = Field(default=16, description="The number of frames sampled from the video to run the classification on.")
|
|
128
|
+
frame_sampling_rate: Optional[int] = Field(default=1, description="The sampling rate used to select frames from the video.")
|
|
129
|
+
function_to_apply: Optional[Literal['sigmoid','softmax','none']] = Field(default='softmax', description="The function to apply to the model output. Valid: 'softmax', 'sigmoid', 'none'.")
|
|
130
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
131
|
+
|
|
132
|
+
class VideoClassificationResponse(APIResponse):
|
|
133
|
+
"""Video classification response"""
|
|
134
|
+
object: Literal["list"] = "list"
|
|
135
|
+
data: List[VideoClassificationData]
|
|
136
|
+
usage: Optional[Usage] = None
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# ================================
|
|
141
|
+
# Zero-Shot Classifications
|
|
142
|
+
# ================================
|
|
143
|
+
|
|
144
|
+
class ZeroShotAudioClassificationData(BaseModel):
|
|
145
|
+
"""Data model for zero-shot audio classification result"""
|
|
146
|
+
label: str = Field(..., description="The label predicted for the audio")
|
|
147
|
+
score: float = Field(..., description="The corresponding probability")
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class ZeroShotAudioClassificationRequest(BaseModel):
|
|
151
|
+
"""Request model for zero-shot audio classification"""
|
|
152
|
+
model: str
|
|
153
|
+
audios: Union[ndarray, List[ndarray]] = Field(..., description="An audio loaded in numpy. Accepts a single array or a list of arrays.")
|
|
154
|
+
candidate_labels: List[str] = Field(..., description="The candidate labels for this audio.")
|
|
155
|
+
hypothesis_template: Optional[str] = Field(default="This is a sound of {}", description="Template used with candidate labels.")
|
|
156
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class ZeroShotAudioClassificationResponse(APIResponse):
|
|
160
|
+
"""Zero-shot audio classification response"""
|
|
161
|
+
object: Literal["list"] = "list"
|
|
162
|
+
data: List[ZeroShotAudioClassificationData]
|
|
163
|
+
usage: Optional[Usage] = None
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class ZeroShotClassificationData(BaseModel):
|
|
167
|
+
"""Data model for zero-shot text classification result"""
|
|
168
|
+
sequence: str = Field(..., description="The input sequence")
|
|
169
|
+
labels: List[str] = Field(..., description="Candidate labels")
|
|
170
|
+
scores: List[float] = Field(..., description="Scores aligned with labels")
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class ZeroShotClassificationRequest(BaseModel):
|
|
174
|
+
"""Request model for zero-shot text classification"""
|
|
175
|
+
model: str
|
|
176
|
+
sequences: Union[str, List[str]] = Field(..., description="The sequence(s) to classify")
|
|
177
|
+
candidate_labels: Union[str, List[str]] = Field(..., description="Possible class labels")
|
|
178
|
+
hypothesis_template: Optional[str] = Field(default="This example is {}.", description="Template used with candidate labels")
|
|
179
|
+
multi_label: Optional[bool] = Field(default=False, description="Whether multiple labels can be true")
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
class ZeroShotClassificationResponse(APIResponse):
|
|
183
|
+
"""Zero-shot text classification response"""
|
|
184
|
+
object: Literal["list"] = "list"
|
|
185
|
+
data: List[ZeroShotClassificationData]
|
|
186
|
+
usage: Optional[Usage] = None
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class ZeroShotImageClassificationData(BaseModel):
|
|
190
|
+
"""Data model for zero-shot image classification result"""
|
|
191
|
+
label: str = Field(..., description="The label identified by the model")
|
|
192
|
+
score: float = Field(..., description="The corresponding probability")
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class ZeroShotImageClassificationRequest(BaseModel):
|
|
196
|
+
"""Request model for zero-shot image classification"""
|
|
197
|
+
model: str
|
|
198
|
+
image: Union[str, List[str], PilImage, List[PilImage]] = Field(..., description="An image or list of images to classify")
|
|
199
|
+
candidate_labels: List[str] = Field(..., description="The candidate labels for this image")
|
|
200
|
+
hypothesis_template: Optional[str] = Field(default="This is a photo of {}", description="Template used with candidate labels")
|
|
201
|
+
timeout: Optional[float] = Field(default=None, description="Timeout for fetching images from the web")
|
|
202
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class ZeroShotImageClassificationResponse(APIResponse):
|
|
206
|
+
"""Zero-shot image classification response"""
|
|
207
|
+
object: Literal["list"] = "list"
|
|
208
|
+
data: List[ZeroShotImageClassificationData]
|
|
209
|
+
usage: Optional[Usage] = None
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class ZeroShotObjectDetectionData(BaseModel):
|
|
213
|
+
"""Data model for zero-shot object detection result"""
|
|
214
|
+
bbox: Dict[str, int] = Field(..., description="Bounding box in corners format")
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class ZeroShotObjectDetectionRequest(BaseModel):
|
|
218
|
+
"""Request model for zero-shot object detection"""
|
|
219
|
+
model: str
|
|
220
|
+
box: Any = Field(..., description="Tensor or list containing the coordinates in corners format")
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class ZeroShotObjectDetectionResponse(APIResponse):
|
|
224
|
+
"""Zero-shot object detection response"""
|
|
225
|
+
object: Literal["list"] = "list"
|
|
226
|
+
data: List[ZeroShotObjectDetectionData]
|
|
227
|
+
usage: Optional[Usage] = None
|
|
228
|
+
|
synapsai/types/common.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Copyright 2026 SynapsAI Technologies Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
Common type definitions used across SynapsAI API
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from typing import Optional, Dict, Any, Union, List
|
|
20
|
+
from pydantic import BaseModel, Field
|
|
21
|
+
from enum import Enum
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class APIResponse(BaseModel):
|
|
25
|
+
"""Base response model for all API responses"""
|
|
26
|
+
object: str
|
|
27
|
+
created: Optional[int] = None
|
|
28
|
+
id: Optional[str] = None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Error(BaseModel):
|
|
32
|
+
"""Error object"""
|
|
33
|
+
message: str
|
|
34
|
+
type: Optional[str] = None
|
|
35
|
+
param: Optional[str] = None
|
|
36
|
+
code: Optional[str] = None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ErrorResponse(BaseModel):
|
|
40
|
+
"""Error response model"""
|
|
41
|
+
error: Error
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class FinishReason(str, Enum):
|
|
45
|
+
"""Reason why the generation finished"""
|
|
46
|
+
STOP = "stop"
|
|
47
|
+
LENGTH = "length"
|
|
48
|
+
FUNCTION_CALL = "function_call"
|
|
49
|
+
TOOL_CALLS = "tool_calls"
|
|
50
|
+
CONTENT_FILTER = "content_filter"
|
|
51
|
+
|
|
52
|
+
class Usage(BaseModel):
|
|
53
|
+
"""Token usage information"""
|
|
54
|
+
prompt_tokens: int
|
|
55
|
+
completion_tokens: Optional[int] = None
|
|
56
|
+
total_tokens: int
|