deepinfra / deepinfra-node

Official TypeScript wrapper for DeepInfra Inference API
https://deepinfra.com/
MIT License
6 stars 0 forks source link

BaseModels instead of Specific Models #17

Closed ichernev closed 3 months ago

ichernev commented 3 months ago

Currently the library provides a custom class for a lot of (if not all) models shipped in deepinfra, which requires a lot of maintenance, because new models come and go. Also, if you want to use a particular model, you have to know the name of the class to import -- even though the full name is meta-llama/Llama-2-70b-chat-hf the library exports it as Llama2_7B.

I think it is better to orient the API around model categories (i.e text-generation, image-generation) and then pass the particular model name as an argument (the OpenAI API works the same way):

import {TextGeneration} from 'deepinfra-api';

const tg = new TextGeneration("meta-llama/Llama-2-70b-chat-hf", MY_TOKEN);
const res = await tg.generate({"input": "Hello"});

This way you can change the model name, without touching anything else.

The code above is almost possible now with 2 caveats:

I think if we do all of the above, a lot of boilerplate code will go away (i.e no need to have a file + class + test for each model, only for each type).

NOTE: All of the above is slightly complicated by COG based models, only SDXL and clip-features ATM, I don't think new ones will be added, actually the opposite. For them we need a special class, because they are their own type (i.e their own non-shared-with-others API/interface). Those two we have to have custom classes for.

So to summarize, I suggest:

@ovuruska any thoughts?

ovuruska commented 3 months ago

It makes perfect sense. This implementation comes up with a major update, so it should be tagged as 2.x.x