Skip to content

Commit c692f18

Browse files
committed
move to zodios
1 parent 3b1a6d5 commit c692f18

File tree

10 files changed

+1491
-1320
lines changed

10 files changed

+1491
-1320
lines changed

package-lock.json

Lines changed: 309 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"prompt-testing"
2121
],
2222
"scripts": {
23-
"build": "run-p build:* && npm run openapi",
23+
"build": "run-p build:*",
2424
"build:main": "tsc -p tsconfig.json",
2525
"build:module": "tsc -p tsconfig.module.json",
2626
"fix": "run-s fix:*",
@@ -38,10 +38,7 @@
3838
"version": "standard-version",
3939
"reset-hard": "git clean -dfx && git reset --hard && npm i",
4040
"prepare-release": "run-s reset-hard test doc:html version doc:publish",
41-
"openapi": "run-s openapi:*",
42-
"openapi:typegen": "npx openapicmd typegen https://api.promptfoundry.ai/sdk/openapi > src/types/openapi.d.ts",
43-
"openapi:typegen:main": "npx openapicmd typegen https://api.promptfoundry.ai/sdk/openapi > ./build/main/types/openapi.d.ts",
44-
"openapi:typegen:module": "npx openapicmd typegen https://api.promptfoundry.ai/sdk/openapi > ./build/module/types/openapi.d.ts"
41+
"openapi": "openapi-zod-client https://api.promptfoundry.ai/sdk/openapi -o ./src/openapi/client.ts --export-types --export-schemas && npm run prettier"
4542
},
4643
"engines": {
4744
"node": ">=10"
@@ -60,7 +57,7 @@
6057
"gh-pages": "^6.1.1",
6158
"jest": "^29.7.0",
6259
"npm-run-all": "^4.1.5",
63-
"open-cli": "^8.0.0",
60+
"openapi-zod-client": "^1.18.1",
6461
"prettier": "^3.2.5",
6562
"prettier-plugin-properties": "^0.3.0",
6663
"standard-version": "^9.5.0",
@@ -69,6 +66,12 @@
6966
"typedoc": "^0.25.13",
7067
"typescript": "^5.4.5"
7168
},
69+
"dependencies": {
70+
"@zodios/core": "^10.9.6",
71+
"axios": "^1.7.2",
72+
"openai": "^4.47.1",
73+
"zod": "^3.23.8"
74+
},
7275
"files": [
7376
"build/main",
7477
"build/module",
@@ -84,10 +87,5 @@
8487
"commitizen": {
8588
"path": "cz-conventional-changelog"
8689
}
87-
},
88-
"dependencies": {
89-
"axios": "^1.7.2",
90-
"openai": "^4.47.1",
91-
"openapi-client-axios": "^7.5.4"
9290
}
9391
}

src/ApiClient.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Client.ts

Lines changed: 181 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
import { ChatCompletionCreateParamsNonStreaming } from 'openai/resources'
22

3-
import APIClient from './ApiClient'
43
import { getMissingPromptVariables, renderPromptWithVariables, validatePromptVariables } from './helpers'
54
import { 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

817
export 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
}

src/__tests__/ApiClient.test.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)