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

[Codegen/Typespec] Handling Base64 sources #2132

Open
Tracked by #2126
HarshaNalluru opened this issue Nov 17, 2023 · 0 comments
Open
Tracked by #2126

[Codegen/Typespec] Handling Base64 sources #2132

HarshaNalluru opened this issue Nov 17, 2023 · 0 comments
Assignees
Labels
P1 priority 1 RLC

Comments

@HarshaNalluru
Copy link
Member

Need to support NodeJS.ReadableStream | Blob | ArrayBuffer | ArrayBufferView in Typespec code generation for base64 sources

Document Intelligence

Typespec

@doc("Document analysis parameters.")
model AnalyzeDocumentRequest {
  @doc("Document URL to analyze.  Either urlSource or base64Source must be specified.")
  urlSource?: url;

  @doc("""
  Base64 encoding of the document to analyze.  Either urlSource or base64Source
  must be specified.
  """)
  base64Source?: bytes;
}

Source - https://github.com/Azure/azure-rest-api-specs/blob/eaf8b6f8e3ae429c8100471a9772a4bee9a5e472/specification/ai/DocumentIntelligence/models.tsp#L288C1-L298C2

Generated code

/** Document analysis parameters. */
export interface AnalyzeDocumentRequest {
  /** Document URL to analyze.  Either urlSource or base64Source must be specified. */
  urlSource?: string;
  /**
   * Base64 encoding of the document to analyze.  Either urlSource or base64Source
   * must be specified.
   */
  base64Source?: string;
}

User Sample

      const filePath = path.join(ASSET_PATH, "forms", "Invoice_1.pdf");
      const base64Source = fs.readFileSync(filePath, { encoding: "base64" });
      const initialResponse = await client
        .path("/documentModels/{modelId}:analyze", "prebuilt-layout")
        .post({
          contentType: "application/json",
          body: {
            base64Source,
          }
        });

Form Recognizer

In the older Form Recognizer library, we used to support..

/**
 * A request input that can be uploaded as binary data to the Form Recognizer service. Form Recognizer treats `string`
 * inputs as URLs, so to send a string as a _binary_ input, first convert the string to one of the following input
 * types.
 */
export type FormRecognizerRequestBody =
  | NodeJS.ReadableStream
  | Blob
  | ArrayBuffer
  | ArrayBufferView;

  public async beginAnalyzeDocument(
    modelId: string,
    document: FormRecognizerRequestBody,
    options?: AnalyzeDocumentOptions
  ): Promise<AnalysisPoller>;

  public async beginAnalyzeDocumentFromUrl(
    modelId: string,
    documentUrl: string,
    options?: AnalyzeDocumentOptions
  ): Promise<AnalysisPoller>;

User sample

        const filePath = path.join(ASSET_PATH, "forms", "Invoice_1.pdf");
        const stream = fs.createReadStream(filePath);
        const poller = await client.beginAnalyzeDocument(
          PrebuiltModels.Layout,
          stream,
          testPollingOptions
        );

Feature Request

The ask here is to support NodeJS.ReadableStream | Blob | ArrayBuffer | ArrayBufferView in Typespec code generation for base64 sources instead of asking users to provide base64 sources.

@HarshaNalluru HarshaNalluru changed the title [Typespec] Handling Base64 sources [Codegen/Typespec] Handling Base64 sources Nov 17, 2023
@qiaozha qiaozha self-assigned this Nov 22, 2023
@qiaozha qiaozha added P1 priority 1 RLC labels Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 priority 1 RLC
Projects
None yet
Development

No branches or pull requests

2 participants