-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from vlm-run/sh/add_zod
fix: tests and upgrade version to 0.2.4
- Loading branch information
Showing
5 changed files
with
149 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "vlmrun", | ||
"version": "0.2.3", | ||
"version": "0.2.5", | ||
"description": "The official TypeScript library for the VlmRun API", | ||
"author": "VlmRun <[email protected]>", | ||
"main": "dist/index.js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,3 +190,5 @@ export interface VlmRunError extends Error { | |
code?: string; | ||
cause?: Error; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { config } from "dotenv"; | ||
|
||
import { VlmRun } from "../../../src/index"; | ||
import { GenerationConfig } from "../../../src/index"; | ||
import { z } from "zod"; | ||
|
||
jest.setTimeout(60000); | ||
|
||
describe("Integration: Predictions", () => { | ||
describe("Integration: File Predictions", () => { | ||
let client: VlmRun; | ||
|
||
beforeAll(() => { | ||
|
@@ -18,130 +17,6 @@ describe("Integration: Predictions", () => { | |
}); | ||
}); | ||
|
||
describe("ImagePredictions", () => { | ||
it("should generate image predictions with default options", async () => { | ||
const testImagePath = "tests/integration/assets/invoice.jpg"; | ||
|
||
const result = await client.image.generate({ | ||
images: [testImagePath], | ||
model: "vlm-1", | ||
domain: "document.invoice", | ||
}); | ||
|
||
expect(result).toHaveProperty("id"); | ||
expect(result.status).toBe("completed"); | ||
expect(result.response.invoice_id).toContain("9999999"); | ||
expect(result.response.invoice_issue_date).toBe("2023-11-11"); | ||
|
||
expect(result.response.customer).toBe("Fred Davis"); | ||
expect(result.response.customer_email).toBe("[email protected]"); | ||
expect(result.response.customer_phone).toContain("4567"); | ||
expect(result.response.customer_billing_address.street).toContain( | ||
"1335 Martin Luther King Jr Ave" | ||
); | ||
expect(result.response.customer_billing_address.city).toBe("Dunedin"); | ||
expect(result.response.customer_billing_address.state).toBe("FL"); | ||
expect(result.response.customer_billing_address.postal_code).toContain( | ||
"34698" | ||
); | ||
expect(result.response.customer_shipping_address.street).toContain( | ||
"249 Windward Passage" | ||
); | ||
expect(result.response.customer_shipping_address.city).toContain( | ||
"Clearwater" | ||
); | ||
expect(result.response.customer_shipping_address.state).toContain("FL"); | ||
expect(result.response.customer_shipping_address.postal_code).toContain( | ||
"33767" | ||
); | ||
expect(result.response.items.length).toBe(3); | ||
|
||
expect(result.response.subtotal).toBe(400); | ||
expect(result.response.total).toBe(400); | ||
}); | ||
|
||
it("should generate image predictions from path with zod schema", async () => { | ||
const testImagePath = "tests/integration/assets/invoice.jpg"; | ||
|
||
const schema = z.object({ | ||
invoice_id: z.string(), | ||
invoice_issue_date: z.string(), | ||
customer: z.string(), | ||
customer_email: z.string(), | ||
customer_phone: z.string(), | ||
total: z.number(), | ||
}); | ||
|
||
const result = await client.image.generate({ | ||
images: [testImagePath], | ||
model: "vlm-1", | ||
domain: "document.invoice", | ||
config: { | ||
responseModel: schema, | ||
}, | ||
}); | ||
|
||
const response = result.response as z.infer<typeof schema>; | ||
expect(response.invoice_id).toBe("9999999"); | ||
expect(response.total).toBe(400); | ||
}); | ||
|
||
it("should generate image predictions from url with zod schema", async () => { | ||
const imageUrl = | ||
"https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.invoice/invoice_1.jpg"; | ||
|
||
const schema = z.object({ | ||
invoice_id: z.string(), | ||
total: z.number(), | ||
}); | ||
|
||
const result = await client.image.generate({ | ||
images: [imageUrl], | ||
model: "vlm-1", | ||
domain: "document.invoice", | ||
config: { | ||
responseModel: schema, | ||
}, | ||
}); | ||
|
||
const response = result.response as z.infer<typeof schema>; | ||
expect(response.invoice_id).toBe("9999999"); | ||
expect(response.total).toBe(400); | ||
}); | ||
|
||
it("should generate image predictions with custom options", async () => { | ||
const testImagePath = "tests/integration/assets/invoice.jpg"; | ||
|
||
const result = await client.image.generate({ | ||
images: [testImagePath], | ||
model: "vlm-1", | ||
domain: "document.invoice", | ||
config: { | ||
jsonSchema: { | ||
type: "object", | ||
properties: { | ||
invoice_number: { type: "string" }, | ||
total_amount: { type: "number" }, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(result).toHaveProperty("id"); | ||
expect(result.status).toBe("completed"); | ||
expect(result.response.invoice_number).toContain("9999999"); | ||
expect(result.response.total_amount).toBe(400); | ||
|
||
expect(result.response).not.toHaveProperty("invoice_issue_date"); | ||
expect(result.response).not.toHaveProperty("customer"); | ||
expect(result.response).not.toHaveProperty("customer_email"); | ||
expect(result.response).not.toHaveProperty("customer_phone"); | ||
expect(result.response).not.toHaveProperty("customer_billing_address"); | ||
expect(result.response).not.toHaveProperty("customer_shipping_address"); | ||
expect(result.response).not.toHaveProperty("items"); | ||
}); | ||
}); | ||
|
||
describe("DocumentPredictions", () => { | ||
const testFilePath = "tests/integration/assets/google_invoice.pdf"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { config } from "dotenv"; | ||
|
||
import { VlmRun } from "../../../src/index"; | ||
import { z } from "zod"; | ||
|
||
jest.setTimeout(60000); | ||
|
||
describe("Integration: Image Predictions", () => { | ||
let client: VlmRun; | ||
|
||
beforeAll(() => { | ||
config({ path: ".env.test" }); | ||
|
||
client = new VlmRun({ | ||
apiKey: process.env.TEST_API_KEY as string, | ||
baseURL: process.env.TEST_BASE_URL as string, | ||
}); | ||
}); | ||
|
||
describe("ImagePredictions", () => { | ||
it("should generate image predictions with default options", async () => { | ||
const testImagePath = "tests/integration/assets/invoice.jpg"; | ||
|
||
const result = await client.image.generate({ | ||
images: [testImagePath], | ||
model: "vlm-1", | ||
domain: "document.invoice", | ||
}); | ||
|
||
expect(result).toHaveProperty("id"); | ||
expect(result.status).toBe("completed"); | ||
expect(result.response.invoice_id).toContain("9999999"); | ||
expect(result.response.invoice_issue_date).toBe("2023-11-11"); | ||
|
||
expect(result.response.customer).toBe("Fred Davis"); | ||
expect(result.response.customer_email).toBe("[email protected]"); | ||
expect(result.response.customer_phone).toContain("4567"); | ||
expect(result.response.customer_billing_address.street).toContain( | ||
"1335 Martin Luther King Jr Ave" | ||
); | ||
expect(result.response.customer_billing_address.city).toBe("Dunedin"); | ||
expect(result.response.customer_billing_address.state).toBe("FL"); | ||
expect(result.response.customer_billing_address.postal_code).toContain( | ||
"34698" | ||
); | ||
expect(result.response.customer_shipping_address.street).toContain( | ||
"249 Windward Passage" | ||
); | ||
expect(result.response.customer_shipping_address.city).toContain( | ||
"Clearwater" | ||
); | ||
expect(result.response.customer_shipping_address.state).toContain("FL"); | ||
expect(result.response.customer_shipping_address.postal_code).toContain( | ||
"33767" | ||
); | ||
expect(result.response.items.length).toBe(3); | ||
|
||
expect(result.response.subtotal).toBe(400); | ||
expect(result.response.total).toBe(400); | ||
}); | ||
|
||
it("should generate image predictions from path with zod schema", async () => { | ||
const testImagePath = "tests/integration/assets/invoice.jpg"; | ||
|
||
const schema = z.object({ | ||
invoice_id: z.string(), | ||
invoice_issue_date: z.string(), | ||
customer: z.string(), | ||
customer_email: z.string(), | ||
customer_phone: z.string(), | ||
total: z.number(), | ||
}); | ||
|
||
const result = await client.image.generate({ | ||
images: [testImagePath], | ||
model: "vlm-1", | ||
domain: "document.invoice", | ||
config: { | ||
responseModel: schema, | ||
}, | ||
}); | ||
|
||
const response = result.response as z.infer<typeof schema>; | ||
expect(response.invoice_id).toBe("9999999"); | ||
expect(response.total).toBe(400); | ||
}); | ||
|
||
it("should generate image predictions from url with zod schema", async () => { | ||
const imageUrl = | ||
"https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.invoice/invoice_1.jpg"; | ||
|
||
const schema = z.object({ | ||
invoice_id: z.string(), | ||
total: z.number(), | ||
}); | ||
|
||
const result = await client.image.generate({ | ||
images: [imageUrl], | ||
model: "vlm-1", | ||
domain: "document.invoice", | ||
config: { | ||
responseModel: schema, | ||
}, | ||
}); | ||
|
||
const response = result.response as z.infer<typeof schema>; | ||
expect(response.invoice_id).toBe("9999999"); | ||
expect(response.total).toBe(400); | ||
}); | ||
|
||
it("should generate image predictions with custom options", async () => { | ||
const testImagePath = "tests/integration/assets/invoice.jpg"; | ||
|
||
const result = await client.image.generate({ | ||
images: [testImagePath], | ||
model: "vlm-1", | ||
domain: "document.invoice", | ||
config: { | ||
jsonSchema: { | ||
type: "object", | ||
properties: { | ||
invoice_number: { type: "string" }, | ||
total_amount: { type: "number" }, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(result).toHaveProperty("id"); | ||
expect(result.status).toBe("completed"); | ||
expect(result.response.invoice_number).toContain("9999999"); | ||
expect(result.response.total_amount).toBe(400); | ||
|
||
expect(result.response).not.toHaveProperty("invoice_issue_date"); | ||
expect(result.response).not.toHaveProperty("customer"); | ||
expect(result.response).not.toHaveProperty("customer_email"); | ||
expect(result.response).not.toHaveProperty("customer_phone"); | ||
expect(result.response).not.toHaveProperty("customer_billing_address"); | ||
expect(result.response).not.toHaveProperty("customer_shipping_address"); | ||
expect(result.response).not.toHaveProperty("items"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters