Skip to content

Commit

Permalink
fix(DevTools): chat api
Browse files Browse the repository at this point in the history
chat api
  • Loading branch information
snomiao committed Nov 12, 2023
1 parent 26cc65e commit e4310d0
Showing 1 changed file with 2 additions and 72 deletions.
74 changes: 2 additions & 72 deletions DevTools/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async function scanClipboardFile() {
// await completion(prompt, question);
// }
//
const completion2 = async (content = "") => {
async function completion2(content = "") {
ac?.abort?.();
ac = new AbortController();
const signal = ac.signal;
Expand All @@ -209,74 +209,4 @@ const completion2 = async (content = "") => {
}
},
});
// .pipeThrough(new TextDecoderStream())
// .pipeThrough(
// new TransformStream({
// transform(chunk, controller) {
// [...chunk.matchAll(/^ ({.*)/gm)]
// .map((m) => m?.[1] ?? "{}")
// .flatMap((e) => JSON.parse(e)?.choices ?? [])
// .map((c) => c.delta?.content ?? "")
// .map((token) => controller.enqueue(token));
// },
// }),
// );
};
// async function completion(indicator: string, content: any) {
// const r = await ai.createChatCompletion(
// {
// model: "gpt-4",
// messages: indicator
// ? [
// // { role: "system", content: 'You are ai assistant that helps' },
// {
// role: "user",
// content: indicator,
// },
// { role: "assistant", content: "yes" },
// { role: "user", content },
// ]
// : [{ role: "user", content }],
// stream: true,
// },
// {
// responseType: "stream",
// },
// );

// let resp = "";
// await Readable.toWeb(r.data as Readable)
// .pipeThrough(new TextDecoderStream())
// .pipeThrough(
// new TransformStream({
// transform(chunk, controller) {
// [...chunk.matchAll(/^data: ({.*)/gm)]
// .map((m) => m?.[1] ?? "{}")
// .flatMap((e) => JSON.parse(e)?.choices ?? [])
// .map((c) => c.delta?.content ?? "")
// .map((token) => controller.enqueue(token));
// },
// }),
// )
// .pipeTo(
// new WritableStream({
// start: () => {
// console.clear();
// },
// write: (chunk) => {
// process.stdout.write(chunk);
// resp += chunk;
// },
// close: () => {
// process.stdout.write("\n");
// },
// }),
// );
// const respond = resp.replace(
// /^```(?:typescript)?([\s\S]*)```$/,
// (_, $1) => $1,
// );
// await writeFile(clipOutFile, respond);
// await clipboard.write(respond);
// console.log("✅ clipboard written");
// }
}

0 comments on commit e4310d0

Please sign in to comment.