Skip to content

Commit cc1dfbc

Browse files
committedMay 3, 2023
feat: adjust prompter
1 parent 933f2cd commit cc1dfbc

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed
 

‎src/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export class Agent<
5454
if (options.after) {
5555
this.after = options.after;
5656
}
57+
58+
if (options.finally) {
59+
this.finally = options.finally;
60+
}
5761
}
5862

5963
/**
@@ -80,8 +84,11 @@ export class Agent<
8084
})
8185
);
8286
const modifiedMessage = await this.after(message);
87+
console.log("modifiedMessage");
88+
console.log(modifiedMessage);
8389

84-
return this.#store.set(modifiedMessage);
90+
const messageId = await this.#store.set(modifiedMessage);
91+
return this.finally(messageId, modifiedMessage);
8592
}
8693

8794
/**

‎src/openai/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export class GPTModelAdapter<Options extends GPTOptions> implements ModelAdapter
2626
* @param {OpenAIApi} openai - A configured openai API instance.
2727
*/
2828
constructor(options: Options, openai: OpenAIApi) {
29+
console.log("systemInstruction");
30+
console.log(options.systemInstruction);
2931
this.#options = options;
3032
this.#openai = openai;
3133
this.history = [];
@@ -71,6 +73,8 @@ export class GPTModelAdapter<Options extends GPTOptions> implements ModelAdapter
7173
});
7274

7375
const { content } = completion.data.choices[0].message;
76+
console.log("RAW");
77+
console.log(content);
7478
const jsonString = extractCode(content);
7579
this.addMessageToHistory({ role: "assistant", content: jsonString });
7680
return JSON.parse(jsonString);

‎src/utils.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ export function minify(strings: TemplateStringsArray, ...values: string[]) {
107107
return output.replace(/^\s+/gm, "").trim();
108108
}
109109

110+
export function maybePeriod(text: string) {
111+
if (
112+
text.endsWith(".") ||
113+
text.endsWith("!") ||
114+
text.endsWith("?") ||
115+
text.endsWith(":") ||
116+
text.endsWith(";")
117+
) {
118+
return "";
119+
}
120+
121+
return ". ";
122+
}
123+
110124
/**
111125
* Creates an instruction string for the AI agent.
112126
*
@@ -117,11 +131,12 @@ export function minify(strings: TemplateStringsArray, ...values: string[]) {
117131
*/
118132
export function createInstruction(role: string, tasks: string, format: Record<string, unknown>) {
119133
return minify`
120-
You are a ${role}.
121-
Your tasks: ${tasks}.
134+
You are a ${role}${maybePeriod(role)}
135+
Your tasks: ${tasks}${maybePeriod(tasks)}
122136
You NEVER explain or add notes.
123-
You ONLY communicate **valid JSON**.
124-
**You answer ONLY!!! as valid JSON in this Format:**
137+
ALL content will be inserted in JSON.
138+
You EXCLUSIVELY communicate **valid JSON**.
139+
**You answer EXCLUSIVELY!!! as valid JSON in this Format**:
125140
${""}
126141
\`\`\`json
127142
${JSON.stringify(format)}

0 commit comments

Comments
 (0)
Please sign in to comment.