Azure Module API Reference¶
This document provides a comprehensive API reference for all services in the Azure module.
AzureService¶
Constructor¶
Methods¶
completions¶
async completions(
messages: Array<{
role: 'system' | 'user' | 'assistant';
content: string;
}>,
options?: {
temperature?: number;
maxTokens?: number;
systemMessage?: string;
stream?: boolean;
}
): Promise<string>
Generates text completions using Azure OpenAI.
summarizeDocument¶
async summarizeDocument(
documentContent: string,
options?: {
maxLength?: number;
format?: 'paragraph' | 'bullets';
}
): Promise<string>
Generates a summary of document content.
answerQuestion¶
async answerQuestion(
question: string,
context: string,
options?: {
detailLevel?: 'concise' | 'detailed';
includeReferences?: boolean;
}
): Promise<{
answer: string;
references?: Array<{
text: string;
position: number;
}>;
}>
Answers a question based on provided context.
streamCompletion¶
async streamCompletion(
messages: Array<{
role: 'system' | 'user' | 'assistant';
content: string;
}>,
callback: (chunk: string, isComplete: boolean) => void,
options?: {
temperature?: number;
maxTokens?: number;
systemMessage?: string;
}
): Promise<void>
Streams completion responses in chunks.
BlobService¶
Constructor¶
Methods¶
uploadDocument¶
async uploadDocument(
file: Buffer | Readable,
metadata?: DocumentMetadata,
options?: {
filename?: string;
contentType?: string;
containerName?: string;
}
): Promise<{
id: string;
url: string;
metadata: DocumentMetadata;
contentType: string;
size: number;
}>
Uploads a document to Azure Blob Storage.
getDocument¶
async getDocument(
documentId: string,
options?: {
containerName?: string;
}
): Promise<{
content: Buffer;
metadata: DocumentMetadata;
contentType: string;
size: number;
}>
Retrieves a document from Azure Blob Storage.
getDocumentUrl¶
async getDocumentUrl(
documentId: string,
options?: {
containerName?: string;
expiresInMinutes?: number;
permissions?: 'read' | 'write' | 'delete' | 'all';
}
): Promise<string>
Generates a URL for accessing a document.
listDocuments¶
async listDocuments(
options?: {
containerName?: string;
prefix?: string;
maxResults?: number;
}
): Promise<{
id: string;
url: string;
metadata: DocumentMetadata;
contentType: string;
size: number;
lastModified: Date;
}[]>
Lists documents in a container.
deleteDocument¶
Deletes a document from Azure Blob Storage.
DocumentParseService¶
Constructor¶
Methods¶
parseDocument¶
async parseDocument(
documentId: string,
options?: {
modelId?: string;
containerName?: string;
includeRawResponse?: boolean;
}
): Promise<DocumentParseResult>
Parses a document using Azure Form Recognizer.
parseDocumentFromUrl¶
async parseDocumentFromUrl(
documentUrl: string,
options?: {
modelId?: string;
includeRawResponse?: boolean;
}
): Promise<DocumentParseResult>
Parses a document using a publicly accessible URL.
parseDocumentContent¶
async parseDocumentContent(
content: Buffer,
options?: {
filename?: string;
contentType?: string;
modelId?: string;
includeRawResponse?: boolean;
}
): Promise<DocumentParseResult>
Parses document content provided as a buffer.
extractTablesFromDocument¶
async extractTablesFromDocument(
documentId: string,
options?: {
containerName?: string;
format?: 'markdown' | 'csv' | 'json';
}
): Promise<{
tables: string[];
rawTables: ParsedTable[];
}>
Extracts tables from a document.
AzureSqlService¶
Constructor¶
Methods¶
query¶
async query<T = any>(
sql: string,
params: Record<string, any> = {},
options: {
transform?: (row: Record<string, any>) => T;
timeout?: number;
} = {}
): Promise<T[]>
Executes a SQL query and returns the results.
queryOne¶
async queryOne<T = any>(
sql: string,
params: Record<string, any> = {},
options: {
transform?: (row: Record<string, any>) => T;
timeout?: number;
} = {}
): Promise<T | null>
Executes a SQL query and returns the first result or null.
execute¶
async execute(
sql: string,
params: Record<string, any> = {},
options: { timeout?: number } = {}
): Promise<{ rowsAffected: number }>
Executes a SQL statement that doesn't return rows.
transaction¶
Executes operations within a transaction.
bulkInsert¶
async bulkInsert<T>(
tableName: string,
columns: Array<{
name: string;
type: string;
}>,
rows: T[],
options: {
batchSize?: number;
timeout?: number;
} = {}
): Promise<{ rowsAffected: number }>
Efficiently inserts multiple rows into a table.
Interfaces¶
DocumentMetadata¶
interface DocumentMetadata {
[key: string]: string | number | boolean | object | null | undefined;
title?: string;
description?: string;
type?: string;
tags?: string[];
userId?: string;
projectId?: string;
createdAt?: Date | string;
updatedAt?: Date | string;
}
DocumentParseResult¶
interface DocumentParseResult {
documentId: string;
content: string;
pages: ParsedPage[];
tables: ParsedTable[];
metadata: Record<string, any>;
rawResponse?: any;
}
ParsedPage¶
interface ParsedPage {
pageNumber: number;
width: number;
height: number;
unit: string;
text: string;
tables: number[];
elements: Array<{
type: 'paragraph' | 'title' | 'heading' | 'list' | 'table' | 'image';
content: string;
boundingBox?: [number, number, number, number];
}>;
}
ParsedTable¶
interface ParsedTable {
rowCount: number;
columnCount: number;
cells: Array<{
rowIndex: number;
columnIndex: number;
rowSpan: number;
columnSpan: number;
content: string;
isHeader: boolean;
}>;
}
Error Types¶
AzureOpenAIError¶
class AzureOpenAIError extends Error {
constructor(
message: string,
public code: string,
public status: number,
public details?: any
) {
super(message);
this.name = 'AzureOpenAIError';
}
}
AzureBlobStorageError¶
class AzureBlobStorageError extends Error {
constructor(
message: string,
public code: string,
public requestId?: string,
public details?: any
) {
super(message);
this.name = 'AzureBlobStorageError';
}
}
DocumentParseError¶
class DocumentParseError extends Error {
constructor(
message: string,
public code: string,
public documentId?: string,
public details?: any
) {
super(message);
this.name = 'DocumentParseError';
}
}