airtrain 0.1.12__py3-none-any.whl → 0.1.14__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.
@@ -0,0 +1,171 @@
1
+ from typing import Optional, List
2
+ from pathlib import Path
3
+ from pydantic import Field
4
+ from together import Together
5
+ import base64
6
+ import time
7
+
8
+ from airtrain.core.skills import Skill, ProcessingError
9
+ from airtrain.core.schemas import InputSchema, OutputSchema
10
+ from .credentials import TogetherAICredentials
11
+ from .image_models_config import get_image_model_config, get_default_image_model
12
+
13
+
14
+ class TogetherAIImageInput(InputSchema):
15
+ """Schema for Together AI image generation input"""
16
+
17
+ prompt: str = Field(..., description="Text prompt for image generation")
18
+ model: str = Field(
19
+ default=get_default_image_model(), description="Together AI image model to use"
20
+ )
21
+ steps: int = Field(default=10, description="Number of inference steps", ge=1, le=50)
22
+ n: int = Field(default=1, description="Number of images to generate", ge=1, le=4)
23
+ size: str = Field(
24
+ default="1024x1024", description="Image size in format WIDTHxHEIGHT"
25
+ )
26
+ negative_prompt: Optional[str] = Field(
27
+ default=None, description="Things to exclude from the generation"
28
+ )
29
+ seed: Optional[int] = Field(
30
+ default=None, description="Random seed for reproducibility"
31
+ )
32
+
33
+
34
+ class GeneratedImage(OutputSchema):
35
+ """Individual generated image data"""
36
+
37
+ b64_json: str = Field(..., description="Base64 encoded image data")
38
+ seed: Optional[int] = Field(None, description="Seed used for this image")
39
+ finish_reason: Optional[str] = Field(
40
+ None, description="Reason for finishing generation"
41
+ )
42
+ url: Optional[str] = Field(None, description="URL of the generated image")
43
+
44
+
45
+ class TogetherAIImageOutput(OutputSchema):
46
+ """Schema for Together AI image generation output"""
47
+
48
+ images: List[GeneratedImage] = Field(..., description="List of generated images")
49
+ model: str = Field(..., description="Model used for generation")
50
+ prompt: str = Field(..., description="Original prompt used")
51
+ total_time: float = Field(..., description="Time taken for generation in seconds")
52
+ usage: dict = Field(default_factory=dict, description="Usage statistics")
53
+
54
+
55
+ class TogetherAIImageSkill(Skill[TogetherAIImageInput, TogetherAIImageOutput]):
56
+ """Skill for generating images using Together AI"""
57
+
58
+ input_schema = TogetherAIImageInput
59
+ output_schema = TogetherAIImageOutput
60
+
61
+ def __init__(self, credentials: Optional[TogetherAICredentials] = None):
62
+ """Initialize the skill with optional credentials"""
63
+ super().__init__()
64
+ self.credentials = credentials or TogetherAICredentials.from_env()
65
+ self.client = Together(
66
+ api_key=self.credentials.together_api_key.get_secret_value()
67
+ )
68
+
69
+ def process(self, input_data: TogetherAIImageInput) -> TogetherAIImageOutput:
70
+ try:
71
+ # Validate the model exists in our config
72
+ get_image_model_config(input_data.model)
73
+
74
+ start_time = time.time()
75
+
76
+ # Generate images
77
+ response = self.client.images.generate(
78
+ prompt=input_data.prompt,
79
+ model=input_data.model,
80
+ steps=input_data.steps,
81
+ n=input_data.n,
82
+ size=input_data.size,
83
+ negative_prompt=input_data.negative_prompt,
84
+ seed=input_data.seed,
85
+ )
86
+
87
+ # Calculate total time
88
+ total_time = time.time() - start_time
89
+
90
+ # Debug print the response structure
91
+ print(f"Response type: {type(response)}")
92
+ print(f"Response data type: {type(response.data)}")
93
+ if response.data:
94
+ print(f"First image type: {type(response.data[0])}")
95
+ print(f"First image attributes: {dir(response.data[0])}")
96
+
97
+ # Convert response to our output format
98
+ generated_images = []
99
+ for img in response.data:
100
+ # Try different possible attribute names for image data
101
+ b64_data = None
102
+ for attr in ["b64_json", "image", "base64", "data"]:
103
+ if hasattr(img, attr):
104
+ b64_data = getattr(img, attr)
105
+ if b64_data:
106
+ break
107
+
108
+ if not b64_data:
109
+ # If no direct attribute found, try accessing as dictionary
110
+ try:
111
+ if hasattr(img, "__dict__"):
112
+ img_dict = img.__dict__
113
+ for key in ["b64_json", "image", "base64", "data"]:
114
+ if key in img_dict and img_dict[key]:
115
+ b64_data = img_dict[key]
116
+ break
117
+ except:
118
+ pass
119
+
120
+ if not b64_data:
121
+ raise ProcessingError(
122
+ f"No image data found in API response. Response structure: {dir(img)}"
123
+ )
124
+
125
+ generated_images.append(
126
+ GeneratedImage(
127
+ b64_json=b64_data,
128
+ seed=getattr(img, "seed", None),
129
+ finish_reason=getattr(img, "finish_reason", None),
130
+ url=getattr(img, "url", None),
131
+ )
132
+ )
133
+
134
+ return TogetherAIImageOutput(
135
+ images=generated_images,
136
+ model=input_data.model,
137
+ prompt=input_data.prompt,
138
+ total_time=total_time,
139
+ usage=getattr(response, "usage", {}),
140
+ )
141
+
142
+ except Exception as e:
143
+ raise ProcessingError(f"Together AI image generation failed: {str(e)}")
144
+
145
+ def save_images(
146
+ self, output: TogetherAIImageOutput, output_dir: Path
147
+ ) -> List[Path]:
148
+ """
149
+ Save generated images to disk
150
+
151
+ Args:
152
+ output (TogetherAIImageOutput): Generation output containing images
153
+ output_dir (Path): Directory to save images
154
+
155
+ Returns:
156
+ List[Path]: List of paths to saved images
157
+ """
158
+ output_dir = Path(output_dir)
159
+ output_dir.mkdir(parents=True, exist_ok=True)
160
+
161
+ saved_paths = []
162
+ for i, img in enumerate(output.images):
163
+ output_path = output_dir / f"image_{i}.png"
164
+ image_data = base64.b64decode(img.b64_json)
165
+
166
+ with open(output_path, "wb") as f:
167
+ f.write(image_data)
168
+
169
+ saved_paths.append(output_path)
170
+
171
+ return saved_paths
@@ -0,0 +1,56 @@
1
+ from typing import List, Optional
2
+ from pydantic import BaseModel, Field, validator
3
+ from pathlib import Path
4
+
5
+
6
+ class TogetherAIImageInput(BaseModel):
7
+ """Schema for Together AI image generation input"""
8
+
9
+ prompt: str = Field(..., description="Text prompt for image generation")
10
+ model: str = Field(
11
+ default="black-forest-labs/FLUX.1-schnell-Free",
12
+ description="Together AI image model to use",
13
+ )
14
+ steps: int = Field(default=10, description="Number of inference steps", ge=1, le=50)
15
+ n: int = Field(default=1, description="Number of images to generate", ge=1, le=4)
16
+ size: str = Field(
17
+ default="1024x1024", description="Image size in format WIDTHxHEIGHT"
18
+ )
19
+ negative_prompt: Optional[str] = Field(
20
+ default=None, description="Things to exclude from the generation"
21
+ )
22
+ seed: Optional[int] = Field(
23
+ default=None, description="Random seed for reproducibility"
24
+ )
25
+
26
+ @validator("size")
27
+ def validate_size(cls, v):
28
+ try:
29
+ width, height = map(int, v.split("x"))
30
+ if width <= 0 or height <= 0:
31
+ raise ValueError
32
+ return v
33
+ except:
34
+ raise ValueError("Size must be in format WIDTHxHEIGHT (e.g., 1024x1024)")
35
+
36
+
37
+ class GeneratedImage(BaseModel):
38
+ """Individual generated image data"""
39
+
40
+ b64_json: str = Field(..., description="Base64 encoded image data")
41
+ seed: Optional[int] = Field(None, description="Seed used for this image")
42
+ finish_reason: Optional[str] = Field(
43
+ None, description="Reason for finishing generation"
44
+ )
45
+
46
+
47
+ class TogetherAIImageOutput(BaseModel):
48
+ """Schema for Together AI image generation output"""
49
+
50
+ images: List[GeneratedImage] = Field(..., description="List of generated images")
51
+ model: str = Field(..., description="Model used for generation")
52
+ prompt: str = Field(..., description="Original prompt used")
53
+ total_time: float = Field(..., description="Time taken for generation in seconds")
54
+ usage: dict = Field(
55
+ default_factory=dict, description="Usage statistics and billing information"
56
+ )
@@ -0,0 +1,277 @@
1
+ from typing import Dict, NamedTuple
2
+
3
+
4
+ class ModelConfig(NamedTuple):
5
+ organization: str
6
+ display_name: str
7
+ context_length: int
8
+ quantization: str
9
+
10
+
11
+ TOGETHER_MODELS: Dict[str, ModelConfig] = {
12
+ # DeepSeek Models
13
+ "deepseek-ai/DeepSeek-R1": ModelConfig(
14
+ organization="DeepSeek",
15
+ display_name="DeepSeek-R1",
16
+ context_length=32768,
17
+ quantization="FP8",
18
+ ),
19
+ "deepseek-ai/DeepSeek-R1-Distill-Llama-70B": ModelConfig(
20
+ organization="DeepSeek",
21
+ display_name="DeepSeek R1 Distill Llama 70B",
22
+ context_length=131072,
23
+ quantization="FP16",
24
+ ),
25
+ "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B": ModelConfig(
26
+ organization="DeepSeek",
27
+ display_name="DeepSeek R1 Distill Qwen 1.5B",
28
+ context_length=131072,
29
+ quantization="FP16",
30
+ ),
31
+ "deepseek-ai/DeepSeek-R1-Distill-Qwen-14B": ModelConfig(
32
+ organization="DeepSeek",
33
+ display_name="DeepSeek R1 Distill Qwen 14B",
34
+ context_length=131072,
35
+ quantization="FP16",
36
+ ),
37
+ "deepseek-ai/DeepSeek-V3": ModelConfig(
38
+ organization="DeepSeek",
39
+ display_name="DeepSeek-V3",
40
+ context_length=16384,
41
+ quantization="FP8",
42
+ ),
43
+ # Meta Models
44
+ "meta-llama/Llama-3.3-70B-Instruct-Turbo": ModelConfig(
45
+ organization="Meta",
46
+ display_name="Llama 3.3 70B Instruct Turbo",
47
+ context_length=131072,
48
+ quantization="FP8",
49
+ ),
50
+ "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo": ModelConfig(
51
+ organization="Meta",
52
+ display_name="Llama 3.1 8B Instruct Turbo",
53
+ context_length=131072,
54
+ quantization="FP8",
55
+ ),
56
+ "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo": ModelConfig(
57
+ organization="Meta",
58
+ display_name="Llama 3.1 70B Instruct Turbo",
59
+ context_length=131072,
60
+ quantization="FP8",
61
+ ),
62
+ "meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo": ModelConfig(
63
+ organization="Meta",
64
+ display_name="Llama 3.1 405B Instruct Turbo",
65
+ context_length=130815,
66
+ quantization="FP8",
67
+ ),
68
+ "meta-llama/Meta-Llama-3-8B-Instruct-Turbo": ModelConfig(
69
+ organization="Meta",
70
+ display_name="Llama 3 8B Instruct Turbo",
71
+ context_length=8192,
72
+ quantization="FP8",
73
+ ),
74
+ "meta-llama/Meta-Llama-3-70B-Instruct-Turbo": ModelConfig(
75
+ organization="Meta",
76
+ display_name="Llama 3 70B Instruct Turbo",
77
+ context_length=8192,
78
+ quantization="FP8",
79
+ ),
80
+ "meta-llama/Llama-3.2-3B-Instruct-Turbo": ModelConfig(
81
+ organization="Meta",
82
+ display_name="Llama 3.2 3B Instruct Turbo",
83
+ context_length=131072,
84
+ quantization="FP16",
85
+ ),
86
+ "meta-llama/Meta-Llama-3-8B-Instruct-Lite": ModelConfig(
87
+ organization="Meta",
88
+ display_name="Llama 3 8B Instruct Lite",
89
+ context_length=8192,
90
+ quantization="INT4",
91
+ ),
92
+ "meta-llama/Meta-Llama-3-70B-Instruct-Lite": ModelConfig(
93
+ organization="Meta",
94
+ display_name="Llama 3 70B Instruct Lite",
95
+ context_length=8192,
96
+ quantization="INT4",
97
+ ),
98
+ "meta-llama/Llama-3-8b-chat-hf": ModelConfig(
99
+ organization="Meta",
100
+ display_name="Llama 3 8B Instruct Reference",
101
+ context_length=8192,
102
+ quantization="FP16",
103
+ ),
104
+ "meta-llama/Llama-3-70b-chat-hf": ModelConfig(
105
+ organization="Meta",
106
+ display_name="Llama 3 70B Instruct Reference",
107
+ context_length=8192,
108
+ quantization="FP16",
109
+ ),
110
+ "meta-llama/Llama-2-13b-chat-hf": ModelConfig(
111
+ organization="Meta",
112
+ display_name="LLaMA-2 Chat (13B)",
113
+ context_length=4096,
114
+ quantization="FP16",
115
+ ),
116
+ # Nvidia Models
117
+ "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF": ModelConfig(
118
+ organization="Nvidia",
119
+ display_name="Llama 3.1 Nemotron 70B",
120
+ context_length=32768,
121
+ quantization="FP16",
122
+ ),
123
+ # Qwen Models
124
+ "Qwen/Qwen2.5-Coder-32B-Instruct": ModelConfig(
125
+ organization="Qwen",
126
+ display_name="Qwen 2.5 Coder 32B Instruct",
127
+ context_length=32768,
128
+ quantization="FP16",
129
+ ),
130
+ "Qwen/QwQ-32B-Preview": ModelConfig(
131
+ organization="Qwen",
132
+ display_name="QwQ-32B-Preview",
133
+ context_length=32768,
134
+ quantization="FP16",
135
+ ),
136
+ "Qwen/Qwen2.5-7B-Instruct-Turbo": ModelConfig(
137
+ organization="Qwen",
138
+ display_name="Qwen 2.5 7B Instruct Turbo",
139
+ context_length=32768,
140
+ quantization="FP8",
141
+ ),
142
+ "Qwen/Qwen2.5-72B-Instruct-Turbo": ModelConfig(
143
+ organization="Qwen",
144
+ display_name="Qwen 2.5 72B Instruct Turbo",
145
+ context_length=32768,
146
+ quantization="FP8",
147
+ ),
148
+ "Qwen/Qwen2-72B-Instruct": ModelConfig(
149
+ organization="Qwen",
150
+ display_name="Qwen 2 Instruct (72B)",
151
+ context_length=32768,
152
+ quantization="FP16",
153
+ ),
154
+ "Qwen/Qwen2-VL-72B-Instruct": ModelConfig(
155
+ organization="Qwen",
156
+ display_name="Qwen2 VL 72B Instruct",
157
+ context_length=32768,
158
+ quantization="FP16",
159
+ ),
160
+ # Microsoft Models
161
+ "microsoft/WizardLM-2-8x22B": ModelConfig(
162
+ organization="Microsoft",
163
+ display_name="WizardLM-2 8x22B",
164
+ context_length=65536,
165
+ quantization="FP16",
166
+ ),
167
+ # Google Models
168
+ "google/gemma-2-27b-it": ModelConfig(
169
+ organization="Google",
170
+ display_name="Gemma 2 27B",
171
+ context_length=8192,
172
+ quantization="FP16",
173
+ ),
174
+ "google/gemma-2-9b-it": ModelConfig(
175
+ organization="Google",
176
+ display_name="Gemma 2 9B",
177
+ context_length=8192,
178
+ quantization="FP16",
179
+ ),
180
+ "google/gemma-2b-it": ModelConfig(
181
+ organization="Google",
182
+ display_name="Gemma Instruct (2B)",
183
+ context_length=8192,
184
+ quantization="FP16",
185
+ ),
186
+ # Databricks Models
187
+ "databricks/dbrx-instruct": ModelConfig(
188
+ organization="databricks",
189
+ display_name="DBRX Instruct",
190
+ context_length=32768,
191
+ quantization="FP16",
192
+ ),
193
+ # Gryphe Models
194
+ "Gryphe/MythoMax-L2-13b": ModelConfig(
195
+ organization="Gryphe",
196
+ display_name="MythoMax-L2 (13B)",
197
+ context_length=4096,
198
+ quantization="FP16",
199
+ ),
200
+ # Mistral AI Models
201
+ "mistralai/Mistral-Small-24B-Instruct-2501": ModelConfig(
202
+ organization="mistralai",
203
+ display_name="Mistral Small 3 Instruct (24B)",
204
+ context_length=32768,
205
+ quantization="FP16",
206
+ ),
207
+ "mistralai/Mistral-7B-Instruct-v0.1": ModelConfig(
208
+ organization="mistralai",
209
+ display_name="Mistral (7B) Instruct",
210
+ context_length=8192,
211
+ quantization="FP16",
212
+ ),
213
+ "mistralai/Mistral-7B-Instruct-v0.2": ModelConfig(
214
+ organization="mistralai",
215
+ display_name="Mistral (7B) Instruct v0.2",
216
+ context_length=32768,
217
+ quantization="FP16",
218
+ ),
219
+ "mistralai/Mistral-7B-Instruct-v0.3": ModelConfig(
220
+ organization="mistralai",
221
+ display_name="Mistral (7B) Instruct v0.3",
222
+ context_length=32768,
223
+ quantization="FP16",
224
+ ),
225
+ "mistralai/Mixtral-8x7B-Instruct-v0.1": ModelConfig(
226
+ organization="mistralai",
227
+ display_name="Mixtral-8x7B Instruct (46.7B)",
228
+ context_length=32768,
229
+ quantization="FP16",
230
+ ),
231
+ "mistralai/Mixtral-8x22B-Instruct-v0.1": ModelConfig(
232
+ organization="mistralai",
233
+ display_name="Mixtral-8x22B Instruct (141B)",
234
+ context_length=65536,
235
+ quantization="FP16",
236
+ ),
237
+ # NousResearch Models
238
+ "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO": ModelConfig(
239
+ organization="NousResearch",
240
+ display_name="Nous Hermes 2 - Mixtral 8x7B-DPO (46.7B)",
241
+ context_length=32768,
242
+ quantization="FP16",
243
+ ),
244
+ # Upstage Models
245
+ "upstage/SOLAR-10.7B-Instruct-v1.0": ModelConfig(
246
+ organization="upstage",
247
+ display_name="Upstage SOLAR Instruct v1 (11B)",
248
+ context_length=4096,
249
+ quantization="FP16",
250
+ ),
251
+ }
252
+
253
+
254
+ def get_model_config(model_id: str) -> ModelConfig:
255
+ """Get model configuration by model ID"""
256
+ if model_id not in TOGETHER_MODELS:
257
+ raise ValueError(f"Model {model_id} not found in Together AI models")
258
+ return TOGETHER_MODELS[model_id]
259
+
260
+
261
+ def list_models_by_organization(organization: str) -> Dict[str, ModelConfig]:
262
+ """Get all models for a specific organization"""
263
+ return {
264
+ model_id: config
265
+ for model_id, config in TOGETHER_MODELS.items()
266
+ if config.organization.lower() == organization.lower()
267
+ }
268
+
269
+
270
+ def get_default_model() -> str:
271
+ """Get the default model ID"""
272
+ return "meta-llama/Llama-3.3-70B-Instruct-Turbo"
273
+
274
+
275
+ if __name__ == "__main__":
276
+ print(len(TOGETHER_MODELS))
277
+ print(get_model_config("meta-llama/Llama-3.3-70B-Instruct-Turbo"))
@@ -0,0 +1,43 @@
1
+ from typing import Dict, NamedTuple
2
+
3
+
4
+ class RerankModelConfig(NamedTuple):
5
+ organization: str
6
+ display_name: str
7
+ model_size: str
8
+ max_doc_size: int
9
+ max_docs: int
10
+
11
+
12
+ TOGETHER_RERANK_MODELS: Dict[str, RerankModelConfig] = {
13
+ "Salesforce/Llama-Rank-v1": RerankModelConfig(
14
+ organization="Salesforce",
15
+ display_name="LlamaRank",
16
+ model_size="8B",
17
+ max_doc_size=8192,
18
+ max_docs=1024,
19
+ )
20
+ }
21
+
22
+
23
+ def get_rerank_model_config(model_id: str) -> RerankModelConfig:
24
+ """Get rerank model configuration by model ID"""
25
+ if model_id not in TOGETHER_RERANK_MODELS:
26
+ raise ValueError(f"Model {model_id} not found in Together AI rerank models")
27
+ return TOGETHER_RERANK_MODELS[model_id]
28
+
29
+
30
+ def list_rerank_models_by_organization(
31
+ organization: str,
32
+ ) -> Dict[str, RerankModelConfig]:
33
+ """Get all rerank models for a specific organization"""
34
+ return {
35
+ model_id: config
36
+ for model_id, config in TOGETHER_RERANK_MODELS.items()
37
+ if config.organization.lower() == organization.lower()
38
+ }
39
+
40
+
41
+ def get_default_rerank_model() -> str:
42
+ """Get the default rerank model ID"""
43
+ return "Salesforce/Llama-Rank-v1"
@@ -0,0 +1,49 @@
1
+ from typing import Optional
2
+ from together import Together
3
+ from airtrain.core.skills import Skill, ProcessingError
4
+ from .credentials import TogetherAICredentials
5
+ from .schemas import TogetherAIRerankInput, TogetherAIRerankOutput, RerankResult
6
+ from .rerank_models_config import get_rerank_model_config
7
+
8
+
9
+ class TogetherAIRerankSkill(Skill[TogetherAIRerankInput, TogetherAIRerankOutput]):
10
+ """Skill for reranking documents using Together AI"""
11
+
12
+ input_schema = TogetherAIRerankInput
13
+ output_schema = TogetherAIRerankOutput
14
+
15
+ def __init__(self, credentials: Optional[TogetherAICredentials] = None):
16
+ """Initialize the skill with optional credentials"""
17
+ super().__init__()
18
+ self.credentials = credentials or TogetherAICredentials.from_env()
19
+ self.client = Together(
20
+ api_key=self.credentials.together_api_key.get_secret_value()
21
+ )
22
+
23
+ def process(self, input_data: TogetherAIRerankInput) -> TogetherAIRerankOutput:
24
+ try:
25
+ # Validate the model exists in our config
26
+ get_rerank_model_config(input_data.model)
27
+
28
+ # Call Together AI rerank API
29
+ response = self.client.rerank.create(
30
+ model=input_data.model,
31
+ query=input_data.query,
32
+ documents=input_data.documents,
33
+ top_n=input_data.top_n,
34
+ )
35
+
36
+ # Transform results
37
+ results = [
38
+ RerankResult(
39
+ index=result.index,
40
+ relevance_score=result.relevance_score,
41
+ document=input_data.documents[result.index],
42
+ )
43
+ for result in response.results
44
+ ]
45
+
46
+ return TogetherAIRerankOutput(results=results, used_model=input_data.model)
47
+
48
+ except Exception as e:
49
+ raise ProcessingError(f"Together AI reranking failed: {str(e)}")
@@ -0,0 +1,33 @@
1
+ from typing import List, Optional
2
+ from pydantic import Field, BaseModel
3
+ from airtrain.core.schemas import InputSchema, OutputSchema
4
+
5
+
6
+ class RerankResult(BaseModel):
7
+ """Schema for individual rerank result"""
8
+
9
+ index: int = Field(..., description="Index of the document in original list")
10
+ relevance_score: float = Field(..., description="Relevance score for the document")
11
+ document: str = Field(..., description="The document content")
12
+
13
+
14
+ class TogetherAIRerankInput(InputSchema):
15
+ """Schema for Together AI rerank input"""
16
+
17
+ query: str = Field(..., description="Query to rank documents against")
18
+ documents: List[str] = Field(..., description="List of documents to rank")
19
+ model: str = Field(
20
+ default="Salesforce/Llama-Rank-v1",
21
+ description="Together AI rerank model to use",
22
+ )
23
+ top_n: Optional[int] = Field(
24
+ default=None,
25
+ description="Number of top results to return. If None, returns all results",
26
+ )
27
+
28
+
29
+ class TogetherAIRerankOutput(OutputSchema):
30
+ """Schema for Together AI rerank output"""
31
+
32
+ results: List[RerankResult] = Field(..., description="Ranked results")
33
+ used_model: str = Field(..., description="Model used for ranking")