11import { z } from "zod" ;
22import { JobBuilder } from "~/jobs/builder" ;
33import type {
4- ChatJobSchema ,
4+ ChatInput ,
5+ ChatOutput ,
56 ChatStreamOptions ,
67 Message ,
78 ResponseFormat ,
89} from "./schema" ;
910import type { ChatTool } from "./tool" ;
1011
11- type ChatJob = z . infer < typeof ChatJobSchema > ;
12-
13- export class ChatJobBuilder extends JobBuilder {
14- job : ChatJob ;
12+ export class ChatJobBuilder extends JobBuilder < ChatInput , ChatOutput > {
13+ input : ChatInput ;
1514
1615 constructor ( model : string ) {
1716 super ( ) ;
18- this . job = {
19- type : "chat" ,
17+ this . type = "chat" ;
18+ this . input = {
2019 model : model ,
2120 messages : [ ] ,
2221 } ;
2322 }
2423
2524 systemPrompt ( systemPrompt : string ) {
26- this . job . systemPrompt = systemPrompt ;
25+ this . input . systemPrompt = systemPrompt ;
2726 return this ;
2827 }
2928
3029 messages ( messages : Message [ ] ) {
31- this . job . messages = messages ;
30+ this . input . messages = messages ;
3231 return this ;
3332 }
3433
3534 temperature ( temperature : number ) {
36- this . job . temperature = temperature ;
35+ this . input . temperature = temperature ;
3736 return this ;
3837 }
3938
4039 maxTokens ( maxTokens : number ) {
41- this . job . maxTokens = maxTokens ;
40+ this . input . maxTokens = maxTokens ;
4241 return this ;
4342 }
4443
4544 topP ( topP : number ) {
46- this . job . topP = topP ;
45+ this . input . topP = topP ;
4746 return this ;
4847 }
4948
5049 topK ( topK : number ) {
51- this . job . topK = topK ;
50+ this . input . topK = topK ;
5251 return this ;
5352 }
5453
5554 tools ( tools : ChatTool [ ] ) {
56- this . job . tools = tools . map ( ( tool ) => tool . params ) ;
55+ this . input . tools = tools . map ( ( tool ) => tool . params ) ;
5756 return this ;
5857 }
5958
6059 tool ( tool : ChatTool ) {
61- if ( ! this . job . tools ) {
62- this . job . tools = [ ] ;
60+ if ( ! this . input . tools ) {
61+ this . input . tools = [ ] ;
6362 }
64- this . job . tools . push ( tool . params ) ;
63+ this . input . tools . push ( tool . params ) ;
6564 return this ;
6665 }
6766
6867 toolChoice ( toolChoice : string ) {
69- this . job . toolChoice = toolChoice ;
68+ this . input . toolChoice = toolChoice ;
7069 return this ;
7170 }
7271
7372 responseFormat ( responseFormat : ResponseFormat ) {
74- this . job . responseFormat = responseFormat ;
73+ this . input . responseFormat = responseFormat ;
7574 return this ;
7675 }
7776
7877 jsonSchema ( schema : z . ZodType , name : string , description ?: string ) {
79- this . job . jsonSchema = {
78+ this . input . jsonSchema = {
8079 name,
8180 description,
8281 schema,
@@ -86,17 +85,10 @@ export class ChatJobBuilder extends JobBuilder {
8685 }
8786
8887 stream ( streamOptions ?: ChatStreamOptions ) {
89- this . job . stream = true ;
88+ this . input . stream = true ;
9089 if ( streamOptions ) {
91- this . job . streamOptions = streamOptions ;
90+ this . input . streamOptions = streamOptions ;
9291 }
9392 return this ;
9493 }
95-
96- dump ( ) {
97- return {
98- ...super . dump ( ) ,
99- ...this . job ,
100- } ;
101- }
10294}
0 commit comments