TypeChat icon indicating copy to clipboard operation
TypeChat copied to clipboard

error when using translate function

Open Githamza opened this issue 1 year ago • 0 comments
trafficstars

I'm using this Model

export interface QuestionsToAnswerToResponse {
  // the language of the improved reply
  questionsToAnswerTo:
    | UnknownText
    | [
        {
          // The question to ask the user to answer
          question: string;
          // The question type, default is text
          answerType: "text" | "number" | "date" | "radio" | "checkbox";
          // The question options if the question type is radio or checkbox otherwwise set to null
          answerOptions: string[] | null;
        }
      ];
}

export interface UnknownText {
  type: "unknown";
  text: string; // The text that wasn't understood
}
const model = createLanguageModel(process.env);
export const getQuestions = async (
  mails: string,
  context: Context
): Promise<Success<QuestionsToAnswerToResponse>> => {
  let schema;
  try {
    schema = fs.readFileSync(
      path.join(__dirname, "/questionsToanswerModel.ts"),
      "utf8"
    );
  } catch (error) {
    context.log("fileread", { error });
  }
  let translator;
  context.log("summariz");
  translator = createJsonTranslator<QuestionsToAnswerToResponse>(
    model,
    schema,
    "QuestionsToAnswerToResponse"
  );
  context.log("typechat");
  return new Promise(async (resolve, reject) => {
    let response: Success<QuestionsToAnswerToResponse>;
    try {
      response = await translator.translate(`${mails}`);
      context.log("response typechat", response);
    } catch (error) {
      context.log("response typechat error");
      context.log({ error });
      return reject(error);
    }
    if (!response.success) {
      context.log(response);
      return reject(response);
    }
    resolve(response);
  });
};

I'm getting this error when I use translate function :

"JSON validation failed: Type '{ question: string; answerType: string; answerOptions: null; }' is not assignable to type 'undefined'.\nType '{ question: string; answerType: string; answerOptions: null; }' is not assignable to type 'undefined'.\nType '{ question: string; answerType: string; answerOptions: null; }' is not assignable to type 'undefined'.\nType '{ question: string; answerType: string; answerOptions: null; }' is not assignable to type 'undefined'.\n{\n \"questionsToAnswerTo\": [\n {\n \"question\": \"What is the add-in name?\",\n \"answerType\": \"text\",\n \"answerOptions\": null\n },\n {\n \"question\": \"Where can the add-in be found?\",\n \"answerType\": \"text\",\n \"answerOptions\": null\n },\n {\n \"question\": \"What is the link to the support document?\",\n \"answerType\": \"text\",\n \"answerOptions\": null\n },\n {\n \"question\": \"What is the link to the privacy statement?\",\n \"answerType\": \"text\",\n \"answerOptions\": null\n },\n {\n \"question\": \"What are the links to Your Services & Add-ins, Microsoft AppSource, and Get Help?\",\n \"answerType\": \"text\",\n \"answerOptions\": null\n }\n ]\n}"

Githamza avatar Nov 24 '23 07:11 Githamza