11import { ChatCompletionCreateParamsNonStreaming } from 'openai/resources'
22
3- import APIClient from './ApiClient'
43import { getMissingPromptVariables , renderPromptWithVariables , validatePromptVariables } from './helpers'
54import { mapPromptToOpenAIConfig } from './helpers/openAi'
6- import { PromptConfiguration } from './types'
5+ import { api , createApiClient } from './openapi/client'
6+ import {
7+ Evaluation ,
8+ EvaluationBody ,
9+ EvaluationGroup ,
10+ EvaluationGroupBody ,
11+ PromptConfiguration ,
12+ PromptConfigurationBody ,
13+ PromptTool ,
14+ PromptToolBody
15+ } from './types'
716
817export default class PromptFoundry {
9- private client : APIClient
18+ private client : typeof api
19+
20+ private apiKey : string
1021
1122 constructor ( { apiKey } : { apiKey : string } ) {
1223 // @ts -expect-error - protect against missing apiKey for js consumers
1324 if ( apiKey === '' || apiKey === undefined || apiKey === null || apiKey === 0 ) {
1425 throw new Error ( 'Prompt Foundry API Key is required!' )
1526 }
1627
17- this . client = new APIClient ( {
18- baseURL : 'https://api.promptfoundry.ai/sdk/v1' ,
19- apiToken : apiKey
20- } )
28+ this . apiKey = apiKey
29+
30+ this . client = createApiClient ( 'https://api.promptfoundry.ai/sdk/v1' )
2131 }
2232
2333 public async getRawPrompt ( { id } : { id : string } ) : Promise < PromptConfiguration > {
24- return this . client . get < PromptConfiguration > ( `/prompts/ ${ id } ` )
34+ return this . client . getPrompt ( { params : { promptId : id } , headers : { 'X-API-KEY' : this . apiKey } } )
2535 }
2636
2737 public async getPrompt ( { id, variables } : { id : string ; variables : Record < string , string > } ) : Promise < PromptConfiguration > {
@@ -45,4 +55,167 @@ export default class PromptFoundry {
4555
4656 return mapPromptToOpenAIConfig ( updatedWithVariables )
4757 }
58+
59+ public createPrompt ( data : PromptConfigurationBody ) : Promise < PromptConfiguration > {
60+ return this . client . createPrompt ( data , {
61+ headers : {
62+ 'X-API-KEY' : this . apiKey
63+ }
64+ } )
65+ }
66+
67+ public updatePrompt ( { id } : { id : string } , data : PromptConfigurationBody ) : Promise < PromptConfiguration > {
68+ return this . client . updatePrompt ( data , {
69+ params : { promptId : id } ,
70+ headers : {
71+ 'X-API-KEY' : this . apiKey
72+ }
73+ } )
74+ }
75+
76+ public async deletePrompt ( { id } : { id : string } ) : Promise < null > {
77+ await this . client . deletePrompt ( undefined , {
78+ params : { promptId : id } ,
79+ headers : {
80+ 'X-API-KEY' : this . apiKey
81+ }
82+ } )
83+
84+ return null
85+ }
86+
87+ public createTool ( data : PromptToolBody ) : Promise < PromptTool > {
88+ return this . client . createTool ( data , {
89+ headers : {
90+ 'X-API-KEY' : this . apiKey
91+ }
92+ } )
93+ }
94+
95+ public updateTool ( { id } : { id : string } , data : PromptToolBody ) : Promise < PromptTool > {
96+ return this . client . updateTool ( data , {
97+ params : { toolId : id } ,
98+ headers : {
99+ 'X-API-KEY' : this . apiKey
100+ }
101+ } )
102+ }
103+
104+ public async deleteTool ( { id } : { id : string } ) : Promise < null > {
105+ await this . client . deleteTool ( undefined , {
106+ params : { toolId : id } ,
107+ headers : {
108+ 'X-API-KEY' : this . apiKey
109+ }
110+ } )
111+
112+ return null
113+ }
114+
115+ public getTool ( { id } : { id : string } ) : Promise < PromptTool > {
116+ return this . client . getTool ( {
117+ params : { toolId : id } ,
118+ headers : {
119+ 'X-API-KEY' : this . apiKey
120+ }
121+ } )
122+ }
123+
124+ public getTools ( ) : Promise < PromptTool [ ] > {
125+ return this . client . getTools ( {
126+ headers : {
127+ 'X-API-KEY' : this . apiKey
128+ }
129+ } )
130+ }
131+
132+ public createEvaluationGroup ( data : EvaluationGroupBody ) : Promise < EvaluationGroup > {
133+ return this . client . createEvaluationGroup ( data , {
134+ headers : {
135+ 'X-API-KEY' : this . apiKey
136+ }
137+ } )
138+ }
139+
140+ public updateEvaluationGroup ( { id } : { id : string } , data : EvaluationGroupBody ) : Promise < EvaluationGroup > {
141+ return this . client . updateEvaluationGroup ( data , {
142+ params : { evaluationGroupId : id } ,
143+ headers : {
144+ 'X-API-KEY' : this . apiKey
145+ }
146+ } )
147+ }
148+
149+ public async deleteEvaluationGroup ( { id } : { id : string } ) : Promise < null > {
150+ await this . client . deleteEvaluationGroup ( undefined , {
151+ params : { evaluationGroupId : id } ,
152+ headers : {
153+ 'X-API-KEY' : this . apiKey
154+ }
155+ } )
156+
157+ return null
158+ }
159+
160+ public getEvaluationGroup ( { id } : { id : string } ) : Promise < EvaluationGroup > {
161+ return this . client . getEvaluationGroup ( {
162+ params : { evaluationGroupId : id } ,
163+ headers : {
164+ 'X-API-KEY' : this . apiKey
165+ }
166+ } )
167+ }
168+
169+ public getEvaluationGroups ( ) : Promise < EvaluationGroup [ ] > {
170+ return this . client . getEvaluationGroups ( {
171+ headers : {
172+ 'X-API-KEY' : this . apiKey
173+ }
174+ } )
175+ }
176+
177+ public createEvaluation ( data : EvaluationBody ) : Promise < Evaluation > {
178+ return this . client . createEvaluation ( data , {
179+ headers : {
180+ 'X-API-KEY' : this . apiKey
181+ }
182+ } )
183+ }
184+
185+ public updateEvaluation ( { id, data } : { id : string ; data : EvaluationBody } ) : Promise < Evaluation > {
186+ return this . client . updateEvaluation ( data , {
187+ params : { evaluationId : id } ,
188+ headers : {
189+ 'X-API-KEY' : this . apiKey
190+ }
191+ } )
192+ }
193+
194+ public async deleteEvaluation ( { id } : { id : string } ) : Promise < null > {
195+ await this . client . deleteEvaluation ( undefined , {
196+ params : { evaluationId : id } ,
197+ headers : {
198+ 'X-API-KEY' : this . apiKey
199+ }
200+ } )
201+
202+ return null
203+ }
204+
205+ public getEvaluation ( { id } : { id : string } ) : Promise < Evaluation > {
206+ return this . client . getEvaluation ( {
207+ params : { evaluationId : id } ,
208+ headers : {
209+ 'X-API-KEY' : this . apiKey
210+ }
211+ } )
212+ }
213+
214+ public getEvaluations ( ) : Promise < Evaluation [ ] > {
215+ return this . client . getEvaluations ( {
216+ headers : {
217+ 'X-API-KEY' : this . apiKey
218+ }
219+ } )
220+ }
48221}
0 commit comments