MCPcopy Create free account
hub / github.com/Bytez-com/docs / Model

Class Model

sdk/javascript/src/model.ts:9–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import { Response, RequestBody } from "./interface/Client";
8
9export default class Model {
10 constructor(
11 modelId: string,
12 bytez: Bytez,
13 client: Client,
14 providerKey?: string
15 ) {
16 this.#client = client;
17 this.id = modelId;
18 this.#providerKey = providerKey;
19 this.#ready = bytez.list.models({ modelId }).then((response: Response) => {
20 const mediaGenerators = [
21 "text-to-audio",
22 "text-to-image",
23 "text-to-video",
24 "text-to-speech"
25 ];
26
27 this.details = response?.output?.[0] ?? {};
28 this.#isGeneratingMedia = mediaGenerators.includes(this.details.task);
29 });
30 }
31 #client: Client;
32 #ready: Promise<void>;
33 #isGeneratingMedia = false;
34 #providerKey: string | undefined;
35 /** The modelId, for example `openai-community/gpt2` */
36 id: string;
37 /** Default model params */
38 params: Inference | undefined;
39 /** details about the model */
40 details: Details;
41
42 /**
43 * `Run` model by passing in an `input`, and optionally passing in `params` and/or a `stream` flag.
44 *
45 * Execute this function in 1 of 4 ways:
46
47 * 1. run(`input`) => returns JSON => { error, output }
48 * 2. run(`input`, `params`) => returns JSON => { error, output }
49 * 3. run(`input`, `stream`) => stream === true? returns read stream, else returns JSON
50 * 4. run(`input`, `params`, `stream`) => stream === true? returns read stream, else returns JSON
51 *
52 * Parameters:
53 * @param input - Input to pass to model (e.g., text, URL, base64).
54 * @param params - models parameters object
55 * @param stream - boolean
56 */
57 async run(input?: any, params?: Inference): Promise<Response>;
58 async run<Stream extends boolean = false>(
59 input?: any,
60 stream?: Stream
61 ): Promise<ModelRunOutput<Stream>>;
62 async run<Stream extends boolean = false>(
63 input?: any,
64 params?: Inference,
65 stream?: Stream
66 ): Promise<ModelRunOutput<Stream>>;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected