Skip to content

Commit ee05619

Browse files
authored
Merge pull request #61 from JigsawStack/update/prompt-engine
added prompt engine back in
2 parents 88337b8 + 812cd98 commit ee05619

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

src/core.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BaseConfig } from "../types";
33
import AudioApis from "./audio/audio";
44
import Classification from "./classification/index";
55
import General from "./general";
6+
import PromptEngine from "./prompt_engine";
67
import { RequestClient } from "./request";
78
import { File } from "./store/file";
89
import Validate from "./validate";
@@ -29,6 +30,7 @@ export const JigsawStack = (config?: BaseConfig) => {
2930
const audio = new AudioApis(client);
3031
const file = new File(client);
3132
const validate = new Validate(client);
33+
const promptengine = new PromptEngine(client);
3234
const store = {
3335
upload: file.upload,
3436
retrieve: file.retrieve,
@@ -59,6 +61,7 @@ export const JigsawStack = (config?: BaseConfig) => {
5961
},
6062
store,
6163
validate,
64+
prompt_engine: promptengine,
6265
classification: classification.classify,
6366
};
6467
};

src/prompt_engine/index.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Stream } from "../lib/streaming";
2+
import { RequestClient } from "../request";
3+
import {
4+
PromptCreateParams,
5+
PromptExecuteParams,
6+
PromptGetResponse,
7+
PromptListParams,
8+
PromptListResponse,
9+
PromptRunParams,
10+
RunPromptDirectResponse,
11+
RunPromptResponse,
12+
RunPromptResponseStream,
13+
} from "./interfaces";
14+
15+
class PromptEngine {
16+
constructor(private readonly client: RequestClient) {}
17+
create = async (params: PromptCreateParams): Promise<{ prompt_engine_id: string }> => {
18+
return await this.client.fetchJSS("/prompt_engine", "POST", params);
19+
};
20+
21+
run_prompt_direct(params: PromptRunParams & { stream: true }): Promise<RunPromptResponseStream<string>>;
22+
run_prompt_direct(params: PromptRunParams & { stream?: false }): Promise<RunPromptDirectResponse>;
23+
async run_prompt_direct(params: PromptRunParams): Promise<RunPromptDirectResponse | RunPromptResponseStream<string>> {
24+
const resp = await this.client.fetchJSS(`/prompt_engine/run`, "POST", params);
25+
if (!params.stream) {
26+
return resp as RunPromptDirectResponse;
27+
}
28+
return Stream.fromReadableStream<string>(resp.body) as RunPromptResponseStream<string>;
29+
}
30+
get = async (id: string): Promise<PromptGetResponse> => {
31+
return await this.client.fetchJSS(`/prompt_engine/${id}`, "GET", {});
32+
};
33+
list = async (params: PromptListParams = { limit: 20, page: 0 }): Promise<PromptListResponse> => {
34+
return await this.client.fetchJSS("/prompt_engine", "GET", {}, params);
35+
};
36+
delete = async (id: string): Promise<{ prompt_engine_id: string }> => {
37+
return await this.client.fetchJSS(`/prompt_engine/${id}`, "DELETE", {});
38+
};
39+
run(params: PromptExecuteParams & { stream: true }): Promise<RunPromptResponseStream<string>>;
40+
run(params: PromptExecuteParams & { stream?: false }): Promise<RunPromptResponse>;
41+
async run(params: PromptExecuteParams): Promise<RunPromptResponseStream<string> | RunPromptResponse> {
42+
const resp = await this.client.fetchJSS(`/prompt_engine/${params.id}`, "POST", params);
43+
if (!params.stream) {
44+
return resp as RunPromptResponse;
45+
}
46+
return Stream.fromReadableStream<string>(resp.body) as RunPromptResponseStream<string>;
47+
}
48+
}
49+
50+
export default PromptEngine;

src/prompt_engine/interfaces.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Stream } from "../lib/streaming";
2+
3+
export interface PromptCreateParams {
4+
prompt: string;
5+
return_prompt?: string | Array<Record<string, any>> | Record<string, any>;
6+
inputs?: Array<{
7+
key: string;
8+
optional?: boolean;
9+
initial_value?: string;
10+
}>;
11+
use_internet?: boolean;
12+
optimize_prompt?: boolean;
13+
prompt_guard?: Array<
14+
| "defamation"
15+
| "specialized_advice"
16+
| "privacy"
17+
| "intellectual_property"
18+
| "indiscriminate_weapons"
19+
| "hate"
20+
| "sexual_content"
21+
| "elections"
22+
| "code_interpreter_abuse"
23+
>;
24+
}
25+
26+
export interface PromptRunParams extends Omit<PromptCreateParams, "optimize_prompt"> {
27+
input_values?: Record<string, any>;
28+
stream?: boolean;
29+
}
30+
31+
export interface PromptExecuteParams {
32+
id: string;
33+
input_values?: Record<string, any>;
34+
stream?: boolean;
35+
}
36+
37+
export interface PromptListParams {
38+
page?: number;
39+
limit?: number;
40+
}
41+
42+
export interface PromptResult {
43+
id: string;
44+
prompt: string;
45+
inputs: Array<{
46+
key: string;
47+
optional: boolean;
48+
}>;
49+
return_prompt: string;
50+
created_at: string;
51+
}
52+
53+
export interface PromptGetResponse extends PromptResult {
54+
success: boolean;
55+
}
56+
57+
export interface PromptListResponse extends PromptResult {
58+
prompt_engines: PromptResult[];
59+
}
60+
61+
export interface RunPromptResponse {
62+
result: any;
63+
success: boolean;
64+
message?: string;
65+
}
66+
67+
export interface RunPromptResponseStream<T> extends Stream<T> {}
68+
69+
export interface RunPromptDirectResponse extends RunPromptResponse {}

0 commit comments

Comments
 (0)