Skip to content

@huggingface/hub: how to use modelInfo with proper typing #996

@axel7083

Description

@axel7083

THe modelInfo method is allowing the caller to define which field will be provided, it has been added in #946

export async function modelInfo<
const T extends Exclude<(typeof MODEL_EXPANDABLE_KEYS)[number], (typeof MODEL_EXPANDABLE_KEYS)[number]> = never,
>(

Here is an example

$: const info = await modelInfo({
	name: "openai-community/gpt2",
});
$: console.log(info);
{
  id: '621ffdc036468d709f17434d',
  name: 'openai-community/gpt2',
  private: false,
  task: 'text-generation',
  downloads: 13764131,
  gated: false,
  likes: 2334,
  updatedAt: 2024-02-19T10:57:45.000Z
}

We can ask for additional fields, using the additionalFields. Here is an example

$: const info = await modelInfo({
	name: "openai-community/gpt2",
        additionalFields: ['author'],
});
$: console.log(info);
{
  // ... omitted 
  author: 'openai-community',
}

However I am not able to find proper typing for the method calling and return type.

The return type of modelInfo is the following

): Promise<ModelEntry & Pick<ApiModelInfo, T>> {

The additionalFields is the following

additionalFields?: T[];

But, I am getting an error when doing the following

const info = await modelInfo<'author'>({
	name: "openai-community/gpt2",
	additionalFields: ['author'],
});

TS2344: Type string does not satisfy the constraint never

I am also interesting in getting the full ApiModelInfo object, but I am not able to use the method with the right typing 🤔 .

cc @coyotte508 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions