Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when using translate function #143

Open
Githamza opened this issue Nov 24, 2023 · 0 comments
Open

error when using translate function #143

Githamza opened this issue Nov 24, 2023 · 0 comments

Comments

@Githamza
Copy link

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}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant