microsoft / microsoft/TypeChat
error when using translate function
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 8.7k
- Forks
- 414
- Avg merge
- 3h 8m
- Merged PRs (30d)
- 3
Description
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}"
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the QuestionsToAnswerToResponse model in questionsToanswerModel.ts and the createJsonTranslator call that invokes translate. Reproduce the JSON validation failure using the supplied model and response, then trace how the union and array types are validated. Done means the reported valid response is accepted or the issue clearly documents the model constraint causing rejection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- ai
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100