MCPcopy Index your code
hub / github.com/Bytez-com/docs / Model

Class Model

sdk/python/bytez/model.py:5–104  ·  view source on GitHub ↗

Represents a model in the Bytez API

Source from the content-addressed store, hash-verified

3
4
5class Model:
6 """
7 Represents a model in the Bytez API
8 """
9
10 def __init__(self, model_id: str, bytez, client: Client, provider_key: str = None):
11 """
12 Initialize a model instance.
13
14 Args:
15 model_id (str): The model ID, e.g., `openai-community/gpt2`.
16 bytez (Bytez): The Bytez API client instance.
17 client (Client): The internal request client.
18 provider_key (str, optional): closed source model provider key
19 """
20 self._client = client
21 self.provider_key: str = provider_key
22 self.id: str = model_id # The modelId, for example `openai-community/gpt2`
23 self.details: Dict = {} # Details about the model
24 self._is_generating_media: bool = (
25 False # Whether the model generates media output
26 )
27 self._bytez = bytez
28 self._ready = False
29
30 def _initialize(self):
31 """Fetch model details and set up internal state."""
32 result = self._bytez.list.models({"modelId": self.id})
33 media_generators = {
34 "text-to-audio",
35 "text-to-image",
36 "text-to-video",
37 "text-to-speech",
38 }
39
40 self.details = result.output[0] if result.output else {}
41 self._is_generating_media = self.details.get("task") in media_generators
42 self._ready = True
43
44 def run(
45 self,
46 input: Any = None,
47 params: Union[Dict, bool, None] = None,
48 stream: bool = False
49 ):
50 """
51 Execute the model with the given input.
52
53 This method supports flexible argument passing. You can pass parameters usually,
54 or pass a boolean as the second argument as a shorthand for streaming.
55
56 Args:
57 input (Any): The input data (text, URL, base64, etc).
58 params (Dict | bool, optional): Model parameters (e.g. temp, top_p) OR a boolean flag for streaming.
59 stream (bool, optional): Explicitly set the stream flag.
60
61 Examples:
62 >>> # 1. Standard run

Callers 1

modelMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected