Skip to content

Conversation

@botkalista
Copy link

Added some generics to the main functions to have better result types for ensureConnection, includeCost and outputType.

Some examples:

import { EPhotoMakerEnum, Runware } from "../Runware";

const runware = new Runware({ apiKey: "API_KEY" });

async function testRequestImages() {

    await runware.ensureConnection(); // Promise<void>

    const result = await runware.requestImages({
        model: '',
        outputType: 'URL',
        positivePrompt: '',
        includeCost
    });

    if (!result) return;
    const res = result[0];

    const url = res.imageURL; // string
    const b64 = res.imageBase64Data; // Property 'imageBase64Data' does not exist on type 'ITextToImage<"URL">'
    const uri = res.imageDataURI; // Property 'imageDataURI' does not exist on type 'ITextToImage<"URL">'

    const cost = res.cost; // number
}

async function testUpscale() {

    await runware.ensureConnection(); // Promise<void>

    const result = await runware.upscaleGan({
        outputType: 'URL',
        inputImage: '',
        upscaleFactor: 1,
    });

    if (!result) return;
    const res = result;

    const url = res.imageURL; //  string
    const b64 = res.imageBase64Data; // Property 'imageBase64Data' does not exist on type 'ITextToImage<"URL">'
    const uri = res.imageDataURI; // Property 'imageDataURI' does not exist on type 'ITextToImage<"URL">'

    const cost = res.cost; // Property 'cost' does not exist on type 'IImage<"URL", false>'.
}


async function testUpscale() {

    await runware.ensureConnection(); //  Promise<void>

    const result = await runware.removeImageBackground({
        outputType: 'URL',
        inputImage: '',
        model: '',
        includeCost: true
    });

    if (!result) return;
    const res = result;

    const url = res.imageURL; // string
    const b64 = res.imageBase64Data; // Property 'imageBase64Data' does not exist on type 'ITextToImage<"URL">'
    const uri = res.imageDataURI; // Property 'imageDataURI' does not exist on type 'ITextToImage<"URL">'

    const cost = res.cost; // number
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant