Leonardo-Interactive / leonardo-ts-sdk

Typescript SDK for Leonardo AI
MIT License
50 stars 16 forks source link

Feature request: Alchemy support #49

Closed ejkkan closed 11 months ago

ejkkan commented 1 year ago

Alchemy pipeline is really superior in the results it brings and would definitely be my (and probably a lot of others) default option for generations.

mavdi commented 1 year ago

It seems Leonardo have abandoned their API, Alchemy is far superior and not yet available on the API. Same goes with some of the photo realistic models and other beta features.

I mean we could probably write a scraper for it, but then what would be the point of this SDK.

ejkkan commented 1 year ago

I started doing this but stopped as it comes with handling sessions auth and so on. I really wish that there would be an effirt to push for alchemy(and other beta features)

Anyone from the Leonardo who could help us out here?

roschler commented 1 year ago

Alchemy pipeline is really superior in the results it brings and would definitely be my (and probably a lot of others) default option for generations.

@ejkkan

So you just can't specify those newer models by changing parameters like you can with other API SDKs? In other words, there isn't an engine/model field that you could just specify (or try guessing) the engine/model name for the models not recognized by this package? This is disappointing. I've been using the OpenAI Dalle-2 API and it's very easy to use. But I want to add Leonardo.AI support because I really love the image quality. I'll send an E-mail directly to Leonardo AI about this and why no one seems to be answering the (only) issue on this discussion forum. Maybe all of us should try the same.

raymerjacque commented 1 year ago

Alchemy is already supported, you simply have to know how to add it.

try these parameters :

        "alchemy": True,
        "contrastRatio": 0.5,
        "expandedDomain": True,
        "highResolution": False,
        "presetStyle": "DYNAMIC",
        "promptMagicVersion": "v3", 
roschler commented 1 year ago

@raymerjacque Thanks! - Is there a doc somewhere that shows the parameters for all of the models, especially the newer ones and what any new parameter names might be and what they do?

ejkkan commented 1 year ago

I tried updating the sdk and then copying the request made from the Leonardo console(but changing the keys to match the sdk). The exact same request results in one image(from the console) that is created with the alchemy pipeline, and one image(via the api) that is not part of the alchemy pipeline.

{
      alchemy: true,
      contrastRatio: 0.5,
      expandedDomain: true,
      guidance_scale: 15,
      height: 768,
      highContrast: true,
      highResolution: false,
      imagePromptWeight: 0.45,
      imagePrompts: [],
      initStrength: 0.55,
      leonardoMagic: true,
      promptMagicVersion: 'v3',
      modelId: '291be633-cb24-434f-898f-e662799936ad',
      negative_prompt: '',
      nsfw: true,
      numImages: 1,
      num_inference_steps: 10,
      photoReal: false,
      poseToImage: false,
      poseToImageType: 'POSE',
      presetStyle: 'NONE',
      prompt:
        'stumbling upon a minuscule stone hidden in her path. Her elegant gown billows around her as she attempts to regain her poise, her jeweled tiara tilting slightly atop her head, all while maintaining her composure and grace despite this unforeseen mishap. An image of a princess looking like peach from super maria, pink princess dress',
      public: false,
      scheduler: 'LEONARDO',
      sdVersion: 'v1_5',
      tiling: false,
      weighting: 1,
      width: 512,
    }
ejkkan commented 1 year ago

@roschler I agree it would be nice to have model specs documented somewhere from Leonardo's side.

Not sure if it helps you, but I've got this setup that I've scrambled together. It's going to have to be updated as new models are added though.

const finetunedModelsIds = {
  dreamShaperV7: 'ac614f96-1082-45bf-be9d-757f2d31c174',
  dreamShaperV6: 'b7aa9939-abed-4d4e-96c4-140b8c65dd92',
  dreamShaperV5: 'd2fb9cf9-7999-4ae5-8bfe-f0df2d32abf8',
  leonardoDiffusion: 'b820ea11-02bf-4652-97ae-9ac0cc00593d',
  leonardoSignature: '291be633-cb24-434f-898f-e662799936ad',
  leonardoCreative: '6bef9f1b-29cb-40c7-b9df-32b51c1f67d3',
  leonardoSelect: 'cd2b2a15-9760-4174-a5ff-4d2925057376',
  threeDRender: 'd69c8273-6b17-4a30-a13e-d6637ae1c644',
}

const finetunedModelsDimensions = {
  dreamShaperV7: { width: 640, height: 832 },
  dreamShaperV6: { width: 640, height: 832 },
  dreamShaperV5: { width: 640, height: 832 },
  leonardoDiffusion: { width: 768, height: 768 },
  leonardoCreative: { width: 768, height: 768 },
  leonardoSelect: { width: 768, height: 768 },
  leonardoSignature: { width: 768, height: 768 },
  threeDRender: { width: 640, height: 832 },
}

export const finetunedModels = {
  dreamShaperV7: 'dreamShaperV7',
  leonardoDiffusion: 'leonardoDiffusion',
  dreamShaperV5: 'dreamShaperV5',
  leonardoCreative: 'leonardoCreative',
  leonardoSelect: 'leonardoSelect',
  leonardoSignature: 'leonardoSignature',
}

const presetStyles = {
  leonardo: 'LEONARDO',
  anime: 'ANIME',
  creative: 'CREATIVE',
  dynamic: 'DYNAMIC',
  general: 'GENERAL',
  illustration: 'ILLUSTRATION',
  photography: 'PHOTOGRAPHY',
  environment: 'ENVIRONMENT',
}

export type FineunedModelsTypes = typeof finetunedModels

export const getLeonardoConfig = () => {
  const { width, height } = finetunedModelsDimensions.dreamShaperV7 // finetunedModelsDimensions[model];
  const modelId = finetunedModelsIds.dreamShaperV7 // finetunedModelsIds[model];
  const useMagic = true
  const num_images = 1
  return {
    num_images,
    height: height,
    width: width,
    modelId,
    presetStyles: presetStyles.general,
    promptMagic: useMagic,
    negative_prompt: '...',
  }
}
raymerjacque commented 1 year ago

I tried updating the sdk and then copying the request made from the Leonardo console(but changing the keys to match the sdk). The exact same request results in one image(from the console) that is created with the alchemy pipeline, and one image(via the api) that is not part of the alchemy pipeline.

{
      alchemy: true,
      contrastRatio: 0.5,
      expandedDomain: true,
      guidance_scale: 15,
      height: 768,
      highContrast: true,
      highResolution: false,
      imagePromptWeight: 0.45,
      imagePrompts: [],
      initStrength: 0.55,
      leonardoMagic: true,
      promptMagicVersion: 'v3',
      modelId: '291be633-cb24-434f-898f-e662799936ad',
      negative_prompt: '',
      nsfw: true,
      numImages: 1,
      num_inference_steps: 10,
      photoReal: false,
      poseToImage: false,
      poseToImageType: 'POSE',
      presetStyle: 'NONE',
      prompt:
        'stumbling upon a minuscule stone hidden in her path. Her elegant gown billows around her as she attempts to regain her poise, her jeweled tiara tilting slightly atop her head, all while maintaining her composure and grace despite this unforeseen mishap. An image of a princess looking like peach from super maria, pink princess dress',
      public: false,
      scheduler: 'LEONARDO',
      sdVersion: 'v1_5',
      tiling: false,
      weighting: 1,
      width: 512,
    }

you missing promptmagic = true also when you enable Alchemy the preset style changed, Leonardo no longer applies.

        'promptMagic': True,  
        'highContrast': True, 
        "alchemy": True,
        "contrastRatio": 0.5,
        "expandedDomain": True,
        "highResolution": False,
        "presetStyle": "DYNAMIC",
        "promptMagicVersion": "v3",
        "init_strength": 0.55,  
ejkkan commented 1 year ago

@raymerjacque Good catch. I tried adding it and check that the rest of the params matches what you've showed us.

Using that setup created an image with these specs(i took them from the image info and formatted it as an object):

 {
  Resolution: '512 x 768px',
  Created: '26/08/23 at 3:48 PM',
  GuidanceScale: 7,
  StepCount: null, // '-' signifies no value, so I'm using null here
  Sampler: 'Leonardo',
  Seed: 380397568,
  Preset: 'Dynamic',
  PromptMagic: 'V2',
  PromptMagicStrength: 'No init image',
  HighContrast: 'Off'
};

Request:

// Leonardo sdk version: 1.51.0

{
      alchemy: true,
      contrastRatio: 0.5,
      expandedDomain: true,
      guidance_scale: 15,
      height: 768,
      highContrast: true,
      highResolution: false,
      imagePromptWeight: 0.45,
      imagePrompts: [],
      initStrength: 0.55,
      leonardoMagic: true,
      promptMagicVersion: 'v3',
      promptMagic: true,
      modelId: '291be633-cb24-434f-898f-e662799936ad',
      negative_prompt: '',
      nsfw: true,
      numImages: 1,
      num_inference_steps: 10,
      photoReal: false,
      poseToImage: false,
      poseToImageType: 'POSE',
      presetStyle: 'DYNAMIC',
      prompt:
        'stumbling upon a minuscule stone hidden in her path. Her elegant gown billows around her as she attempts to regain her poise, her jeweled tiara tilting slightly atop her head, all while maintaining her composure and grace despite this unforeseen mishap. An image of a princess looking like peach from super maria, pink princess dress',
      public: false,
      scheduler: 'LEONARDO',
      sdVersion: 'v1_5',
      tiling: false,
      weighting: 1,
      width: 512,
    }

 // Resulting image: https://cdn.leonardo.ai/users/a14b1360-c75a-4e44-8ad4-911dc658ca0f/generations/a83579f9-d121-4395-95f1-f54e797073c4/Leonardo_Signature_stumbling_upon_a_minuscule_stone_hidden_in_0.jpg
roschler commented 1 year ago

@ejkkan @raymerjacque Thanks, both of you! How are you two figuring this stuff out? Wow, I just stopped myself from making a bad pun about using alchemy to do it. ⭕

ejkkan commented 1 year ago

Do we have any news on this?

impactcolor commented 11 months ago

Hi all! Using "@leonardo-ai/sdk": "^1.55.0" I keep getting a 400 error using the same exact example provided on the docs for generating image. I'm only posting here because at least it's getting some traction. I'll also create a new issue but it doesn't seem like there's much activity.

sdk.generation.createGeneration({ alchemy: true, contrastRatio: 3834.41, controlNet: false, controlNetType: ControlnetType.Canny, expandedDomain: false, guidanceScale: 791725, height: 812169, highContrast: false, highResolution: false, imagePromptWeight: 5288.95, prompt: "Messi on the pitch playing soccer", initGenerationImageId: "recusandae", initImageId: "temporibus", initStrength: 710.36, modelId: "quis", negativePrompt: "veritatis", nsfw: false, numImages: 648172, numInferenceSteps: 20218, presetStyle: SdGenerationStyle.Leonardo, promptMagic: false, promptMagicVersion: "sapiente", public: false, scheduler: SdGenerationSchedulers.DpmSolver, sdVersion: SdVersions.V15, seed: 870013, tiling: false, unzoom: false, unzoomAmount: 8700.88, upscaleRatio: 9786.19, weighting: 4736.08, width: 799159, }).then((res: CreateGenerationResponse) => { if (res.statusCode == 200) { console.log('message went through'); console.log(res); } else { console.error(res); } });

raymerjacque commented 11 months ago

Hi all! Using "@leonardo-ai/sdk": "^1.55.0" I keep getting a 400 error using the same exact example provided on the docs for generating image. I'm only posting here because at least it's getting some traction. I'll also create a new issue but it doesn't seem like there's much activity.

sdk.generation.createGeneration({ alchemy: true, contrastRatio: 3834.41, controlNet: false, controlNetType: ControlnetType.Canny, expandedDomain: false, guidanceScale: 791725, height: 812169, highContrast: false, highResolution: false, imagePromptWeight: 5288.95, prompt: "Messi on the pitch playing soccer", initGenerationImageId: "recusandae", initImageId: "temporibus", initStrength: 710.36, modelId: "quis", negativePrompt: "veritatis", nsfw: false, numImages: 648172, numInferenceSteps: 20218, presetStyle: SdGenerationStyle.Leonardo, promptMagic: false, promptMagicVersion: "sapiente", public: false, scheduler: SdGenerationSchedulers.DpmSolver, sdVersion: SdVersions.V15, seed: 870013, tiling: false, unzoom: false, unzoomAmount: 8700.88, upscaleRatio: 9786.19, weighting: 4736.08, width: 799159, }).then((res: CreateGenerationResponse) => { if (res.statusCode == 200) { console.log('message went through'); console.log(res); } else { console.error(res); } });

Yea they really screwed over their user base by removing alchemy and refusing to add photoreal. Now you have to pay more for some bullsh1t enterprise API. I would highly recommend you join the Prodia project, it's a quarter of the price ( 5usd a month ) and they offer like a dozen models to choose from ( many of the same models Leonardo has ), and they have unlimited generations and everything is open and available.

roschler commented 11 months ago

@raymerjacque Ouch. sorry to hear this. Maybe with the advent of the Dalle-3 engine being available via the OpenAI API in October they'll change this.

impactcolor commented 11 months ago

@raymerjacque I get your frustration but I'm not sure that's totally accurate. The api is available on the $10 plan. The prodia project doesn't look too promising at least by it's website examples.

raymerjacque commented 11 months ago

@raymerjacque I get your frustration but I'm not sure that's totally accurate. The api is available on the $10 plan. The prodia project doesn't look too promising at least by it's website examples.

Its accurate. The basic API doesn't support prompt magic 3, alchemy or photoreal. You need the enterprise API for that. And prodia is great, don't bash something without trying it. They use a lot of the same models that Leonardo does, so why would you say it's not promising ?

ejkkan commented 11 months ago

And here I am on Enterprise and still not able to get alchemy to work 🙄

roschler commented 11 months ago

@raymerjacque Welp, that leaves me out, assuming Google Bard is correct (and sometimes it's really not!)

"Leonardo AI does not publicly disclose the pricing of its enterprise API. However, based on information from publicly available sources, it is estimated to cost between $5,000 and $10,000 per month."

@ejkkan Is Google Bard correct on its price estimate?

raymerjacque commented 11 months ago

generated_image-19.png

generated_image_0-1.jpg

I just generated these on prodia 5usd a month package... using their API. And they have a dozen models. I can post more images... it's really not bad for the price.

ejkkan commented 11 months ago

Oh, this was my bad.

I'm actually on Maestro. So I take back my comment regarding Enterprise. It's still missing in Mastro though as far as I'm concerned

impactcolor commented 11 months ago

@raymerjacque that's great, but any stable diffusion engine can do that. The main thing is the stye variances that others offer like midjourney and Leonardo. Also where are we getting "enterprise" plan from? Leonardo site doesn't have that on there. A $10 plan is what I have and I have access to the api.

raymerjacque commented 11 months ago

@raymerjacque that's great, but any stable diffusion engine can do that. The main thing is the stye variances that others offer like midjourney and Leonardo. Also where are we getting "enterprise" plan from? Leonardo site doesn't have that on there. A $10 plan is what I have and I have access to the api.

What do you think Leonardo runs ? SD and sdxl ... same as everyone else, they just add some variables to enhance the images, anyone can do that. The only people not running SD are midjourney and stablecog ( stablecog runs that dankinksi russian made model v1 and 2.2 ) . As I said before, prodia has many of the same models Leonardo has... same versions and some even newer builds.

impactcolor commented 11 months ago

@raymerjacque I'm not saying it doesn't run SD but it doesn't seem like it produces the same quality, again for $10 a month. The issue being discussed here is how to get Leonardo api running correctly no?

impactcolor commented 11 months ago

@raymerjacque what enterprise package are you referring to and where is the documenation that says alchemy is supported on that?

ejkkan commented 11 months ago

@impactcolor I think everyone's on board with access and using the API. This issue is about the API not being on par with their own UI, and so disregarding the users who want to use Leonardo as a third party

raymerjacque commented 11 months ago

@raymerjacque I'm not saying it doesn't run SD but it doesn't seem like it produces the same quality, again for $10 a month. The issue being discussed here is how to get Leonardo api running correctly no?

In that case the answer is simple. You can't the standard way, they removed it from the regular API... you can now ONLY get it via the enterprise API. The only other way is to make your own API. It's not to hard if you know coding.. but that is the only other way.

impactcolor commented 11 months ago

@raymerjacque again you keep referencing an enterprise api, but there's no documentation regarding an enterprise api.

raymerjacque commented 11 months ago

@raymerjacque again you keep referencing an enterprise api, but there's no documentation regarding an enterprise api.

It's not being advertised. You have to contact them in their discord channel and then pay thousands of dollars and they give you access to it.

roschler commented 11 months ago

Well that killed the Leonardo development for me, but I don't think they care, because if they are getting heavy funding from the Enterprise API they're not going to give two you-know-whats about the medium and small developers who are an unpredictable source of income to begin with.

I was about to add Leonardo API support to my virtual world builder app but Dalle-3 is coming. When it was just Dalle-2 then Leonardo was still a reasonable investment in time, even without those premium models, because Dalle-2 was so far behind in quality. But with Dalle-2 already supported my app, and Dalle-3 coming, why bother spending a hard few weeks integrating Leonard, especially since I would need to add a ton of UX elements for the plethora of options and choices that they have for image generation. I'll just wait a few weeks for Dalle-3 to come out and tinker with Prodia thanks to @raymerjacque's tip.

impactcolor commented 11 months ago

I'm on the discord channel where do they discuss giving you access to the alchemy feature through the api? @raymerjacque

raymerjacque commented 11 months ago

Well that killed the Leonardo development for me, but I don't think they care, because if they are getting heavy funding from the Enterprise API they're not going to give two you-know-whats about the medium and small developers who are an unpredictable source of income to begin with.

I was about to add Leonardo API support to my virtual world builder app but Dalle-3 is coming. When it was just Dalle-2 then Leonardo was still a reasonable investment in time, even without those premium models, because Dalle-2 was so far behind in quality. But with Dalle-2 already supported my app, and Dalle-3 coming, why bother spending a hard few weeks integrating Leonard, especially since I would need to add a ton of UX elements for the plethora of options and choices that they have for image generation. I'll just wait a few weeks for Dalle-3 to come out and tinker with Prodia thanks to @raymerjacque's tip.

  • Dalle-2

I run prodia, ideogram and some custom models.. if you want to check it out pop into my discord and generate a few images. See what the quality is like

Discord link :

https://discord.gg/yv6USvpWqD

impactcolor commented 11 months ago

@raymerjacque bro you're on here giving false information about things just to get people to your discord or to switch. At least be up front about it.

raymerjacque commented 11 months ago

@raymerjacque bro you're on here giving false information about things just to get people to your discord or to switch. At least be up front about it.

False information ? How ? What information is false exactly ?

impactcolor commented 11 months ago

I want to apologize, you are correct @raymerjacque it is enteprise api and it is a rip off. Sorry for jumping the gun.

roschler commented 11 months ago

This puts developers in a real unattractive position. Whatever app you create, by definition, will be inferior from what the average user can get from a low-tier paid account via the Leonardo AI web site. I am on the first paid tier and I have access to the premium models discussed here, especially PhotoReal. So my sales pitch is, "Come use my app and get a far lesser user experience than what you can get from the Leonard AI web site"? How does that work?

I think this new strategy will work very well for Leonardo AI in the short run to medium run, if they are getting a reasonable number of Enterprise customers. But it may backfire terribly in the long run. If OpenAI, Midjourney, or some other monster competitor comes out with a cheaper API, and that's something that Microsoft/OpenAI is known to do to crush the competition and they do it often, then the lack of a large community of small to medium size developers and the legion of apps they would build will not be there to shore up their bottom line and save them.

It will be interesting to see how this plays out.

PNRxA commented 11 months ago

Our API is being overhauled to a PAYG model, it is not just targeting enterprise, and it will be publicly available with Alchemy, PhotoReal, and prompt magic v3.

We are aiming for a release this week with all the details

PNRxA commented 11 months ago

Just a heads up this is now available through the API Access menu at the bottom of the navigation bar. You can also now supply a webhook URL and will not have to rely on polling an endpoint to find out when a generation is complete