瀏覽代碼

codegen type safety

Mish Ushakov 2 月之前
父節點
當前提交
972a9f48bb
共有 2 個文件被更改,包括 8 次插入3 次删除
  1. 6 1
      src/index.ts
  2. 2 2
      src/models.ts

+ 6 - 1
src/index.ts

@@ -18,6 +18,11 @@ export type ScraperLLMOptions = {
   output?: 'array'
 }
 
+export type ScraperGenerateOptions = Omit<
+  ScraperLLMOptions,
+  'output' | 'mode'
+>
+
 export type ScraperRunOptions = ScraperLLMOptions & PreProcessOptions
 
 export default class LLMScraper {
@@ -54,7 +59,7 @@ export default class LLMScraper {
   async generate<T>(
     page: Page,
     schema: z.Schema<T, z.ZodTypeDef, any> | Schema<T>,
-    options?: ScraperLLMOptions
+    options?: ScraperGenerateOptions
   ) {
     const preprocessed = await preprocess(page, {
       format: 'raw_html',

+ 2 - 2
src/models.ts

@@ -7,7 +7,7 @@ import {
   Schema,
 } from 'ai'
 import { z } from 'zod'
-import { ScraperLLMOptions } from './index.js'
+import { ScraperLLMOptions, ScraperGenerateOptions } from './index.js'
 import { PreProcessResult } from './preprocess.js'
 import { zodToJsonSchema } from 'zod-to-json-schema'
 
@@ -96,7 +96,7 @@ export async function generateAISDKCode<T>(
   model: LanguageModelV1,
   page: PreProcessResult,
   schema: z.Schema<T, z.ZodTypeDef, any> | Schema<T>,
-  options?: ScraperLLMOptions
+  options?: ScraperGenerateOptions
 ) {
   const parsedSchema =
     schema instanceof z.ZodType ? zodToJsonSchema(schema) : schema