You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I am trying to configure my Next.js (<13 and using pages API) to utilize a local model. #310 and documents refer to using
env.allowRemoteModels = false
which returns an warning as the following.
Cannot assign to 'allowRemoteModels' because it is a read-only property.ts(2540)
I also see that with the current documentation of adding PiplineSingleton to global, global seems to have an error of Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.ts(7017),
is there a way to get around this like the prisma client?
let PipelineSingleton: any
if (process.env.NODE_ENV !== 'production') {
// When running in development mode, attach the pipeline to the
// global object so that it's preserved between hot reloads.
// For more information, see https://vercel.com/guides/nextjs-prisma-postgres
if (!global.PipelineSingleton) {
global.PipelineSingleton = P()
}
PipelineSingleton = global.PipelineSingleton
} else {
PipelineSingleton = P()
}
export default PipelineSingleton
Is there some kind of typing to get around these problems?
How to reproduce Steps or a minimal working example to reproduce the behavior
create a next app with this as a server utility, and calling it in API routes.
// let PipelineSingleton: any
import {
PreTrainedTokenizer,
Processor,
PreTrainedModel,
AutoTokenizer,
AutoProcessor,
AutoModel,
env,
} from '@xenova/transformers'
env.allowRemoteModels = false
const P = () =>
class PipelineSingleton {
private static task: string = 'zero-shot-image-classification'
private static modelID: string = 'Xenova/clip-vit-base-patch16'
private static tokenizer: PreTrainedTokenizer | null = null
private static processor: Processor | null = null
private static model: PreTrainedModel | null = null
public static async getInstance(progress_callback: (x: number) => void): Promise<{
tokenizer: PreTrainedTokenizer
processor: Processor
model: PreTrainedModel
}> {
if (this.tokenizer === null && this.processor === null && this.model === null) {
this.tokenizer = await AutoTokenizer.from_pretrained(this.modelID)
this.processor = await AutoProcessor.from_pretrained(this.modelID)
this.model = await AutoModel.from_pretrained(this.modelID)
}
return {
tokenizer: this.tokenizer!,
processor: this.processor!,
model: this.model!,
}
}
}
let PipelineSingleton: any
if (process.env.NODE_ENV !== 'production') {
// When running in development mode, attach the pipeline to the
// global object so that it's preserved between hot reloads.
// For more information, see https://vercel.com/guides/nextjs-prisma-postgres
if (!global.PipelineSingleton) {
global.PipelineSingleton = P()
}
PipelineSingleton = global.PipelineSingleton
} else {
PipelineSingleton = P()
}
export default PipelineSingleton
Expected behavior A clear and concise description of what you expected to happen.
Typing error goes away
Environment
Transformers.js version: 2.6.2
Operating system (if applicable): Mac
The text was updated successfully, but these errors were encountered:
@kyeshmz Regarding your problem on global, it is not related to this project.
A quick way to test is change your tsconfig.json, set "strict": false instead of "strict": true, the error should go away. This is how the prisma example you referred to in the comments work.
But, I do not encourage the above. A proper way to solve the problem can be something like this:
declare global {varPipelineSingleton: ReturnType<typeofP>}
Describe the bug
I am trying to configure my Next.js (<13 and using pages API) to utilize a local model.
#310 and documents refer to using
which returns an warning as the following.
I also see that with the current documentation of adding PiplineSingleton to global, global seems to have an error of
Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.ts(7017)
,is there a way to get around this like the prisma client?
Is there some kind of typing to get around these problems?
How to reproduce
Steps or a minimal working example to reproduce the behavior
create a next app with this as a server utility, and calling it in API routes.
Expected behavior
A clear and concise description of what you expected to happen.
Typing error goes away
Environment
The text was updated successfully, but these errors were encountered: