microsoft / TypeChat

TypeChat is a library that makes it easy to build natural language interfaces using types.
https://microsoft.github.io/TypeChat/
MIT License
8.06k stars 379 forks source link

JSON validation failed: File '/schema.ts' is not a module.\n'Object' only refers to a type, but is being used as a value here.\nCannot find name 'exports' #77

Open Githamza opened 11 months ago

Githamza commented 11 months ago

I'm using this function to get summary

export const  getSummary = async (mails:string) =>{
return new Promise(async (resolve,reject)=> {

       const response= await  translator.translate(mails);
       if (!response.success) {
           console.log(response);
           return reject(response);
    }
    const summarizedMail = response.data;
    console.log(JSON.stringify(summarizedMail,undefined, 2));
    if (summarizedMail.summaryObject.type==="unknown") {
        console.log("I didn't understand the following:");
            console.log(summarizedMail.summaryObject.text);

    }
    resolve(response)
})

Here's the schema file

export interface SummarizedMailItems {
    type:'mailSummary',
    summarizationLanguage: 'arabic' | 'english' | 'french' | 'spanish'
    summaryParagraph:string ,
    summaryBulletpoints: [string,string,string]

}

export interface UnknownText {
    type:'unknown',
    text: string; // The text that wasn't understood
}

export type SummarizedMail = {
    summaryObject: SummarizedMailItems | UnknownText;
};

I'm getting this error


{
  success: false,
  message: "JSON validation failed: File '/schema.ts' is not a module.\n'Object' only refers to a type, but is being used as a value here.\nCannot find name 'exports'.\n{\n  \"paragraphSummary\": \"..........",
}```
weykon commented 11 months ago

try add "module": "commonjs" in your tsconfig.json file ?

Githamza commented 11 months ago

it's already there

I'm getting also this error today :

"Response is not JSON:\nI'm sorry, but as an AI language model, I cannot provide a revised JSON object for this scenario as the error message suggests that the issue is with the TypeScript module and not the JSON object itself. It seems like there is an issue with the module definition or import statements in the code. Please review the code and ensure that the module is properly defined and imported."
LennonReid commented 11 months ago

It seems like the definition of the type is wrong.

export interface SummarizedMailItems { type:'mailSummary', summarizationLanguage: 'arabic' | 'english' | 'french' | 'spanish' summaryParagraph:string , summaryBulletpoints: [string,string,string]

} It should be export interface SummarizedMailItems { type:'mailSummary'; summarizationLanguage: 'arabic' | 'english' | 'french' | 'Spanish; summaryParagraph:string ; summaryBulletpoints: [string,string,string];

} Use a semicolon instead of a comma.

Githamza commented 11 months ago

I get always the error I notice that inside the error the response contains the right json but I don't understand why I get the json validation failure { success: false, message: "JSON validation failed: File '/schema.ts' is not a module.\n'Object' only refers to a type, but is being used as a value here.\nCannot find name 'exports'.\n{\n \"paragraphSummary\": \"Discover trends in your work habits with Microsoft Viva Insights. Get insights on your work habits in areas such as focus, well-being, network, and collaboration. Protect your privacy with Viva Insights. Understand and improve your professional habits by reflecting on your work methodology. Click on Viva Insights in the Outlook ribbon to view your tasks and more.\",\n \"bulletPointsSummary\": [\n \"27 days without interruption of quiet hours\",\n \"0% of significant collaboration outside of working hours\",\n \"100% of available time for individual work in a normal week\"\n ]\n}", }

Edit : I notice that it's an old schema that I defined at the beggining

BryceEWatson commented 11 months ago

I'm getting this as well, trying to see what's wrong with the response vs. the TypeScript. It would be helpful if this error message gave more details about what was failing validation.

Githamza commented 11 months ago

@BryceEWatson I have found the origin : the project was compiling ts files to js , so typechat didn't found the schema ts file. ensure that the ts model path is good when your projet compiles too

Another solution is may be to use fs library to programmatically create typescript file add add inside your interfaces

DanielRosenwasser commented 11 months ago

Yes, it's a bit of a gotcha - you need to copy over your TypeScript schema files or run your TypeScript source in-place with a tool like ts-node.

joe-soboleski-visiontree commented 11 months ago

@Githamza / @DanielRosenwasser Im still running into this issue, can you explain a little bit more what you mean by your solution? Im a little confused about what the schema.ts file is and what changes you made so that it could still find it?