vercel / modelfusion

The TypeScript library for building AI applications.
https://modelfusion.dev
MIT License
1.01k stars 76 forks source link

TypeValidationError - Seems like if there are issue with OpenAI, it is still trying to call chat completion and giving type error #344

Open lcsvcn opened 4 weeks ago

lcsvcn commented 4 weeks ago

Type validation failed: Value: {"error":{"message":"The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error.","type":"server...

Error at text-chunk: Type validation failed: Value: {"error":{"message":"The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error.","type":"server_error","param":null,"code":null}}.
Error message: [
  {
    "code": "invalid_type",
    "expected": "string",
    "received": "undefined",
    "path": [
      "object"
    ],
    "message": "Required"
  },
  {
    "code": "invalid_type",
    "expected": "string",
    "received": "undefined",
    "path": [
      "id"
    ],
    "message": "Required"
  },
  {
    "code": "invalid_type",
    "expected": "array",
    "received": "undefined",
    "path": [
      "choices"
    ],
    "message": "Required"
  },
  {
    "code": "invalid_type",
    "expected": "number",
    "received": "undefined",
    "path": [
      "created"
    ],
    "message": "Required"
  }
]

The part of code that is being reported to have that issue on Sentry:

modelfusion/packages/modelfusion/dist/index.cjs in safeValidateTypes at line 1046:14

try {
    const validationResult = schema.validate(value);
    if (validationResult.success) {
      return validationResult;
    }
    return {
      success: false,
      error: new TypeValidationError({
        value,
        cause: validationResult.error  // THIS LINE THAT GIVES ERROR
      })
    };
  } catch (error) {
    return {
      success: false,

This is how I am calling in my code:

     const textStream = await streamText({
        model: openai.ChatTextGenerator({
          model: model,
          temperature: temperature,
          maxGenerationTokens: maxGenerationTokens,
        }),

        //@ts-ignore
        prompt: promptChat,
      })

I am using gpt4o model (supported in my PR), temperature 0.7, maxGenerationTokens 500