Skip to content

Commit

Permalink
Fix ai resume review (fixes #391) (#392)
Browse files Browse the repository at this point in the history
* Fix ai resume review (fixes #391)

* Improve error handling

* Allow `Error`s to be passed into Logger.log
  • Loading branch information
vcarl authored Jul 18, 2024
1 parent 8c78bd4 commit 7898ffe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"node-cron": "3.0.3",
"node-fetch": "2.6.12",
"open-graph-scraper": "6.5.2",
"openai": "4.49.1",
"openai": "4.52.7",
"pdf2pic": "3.1.1",
"query-string": "7.1.3",
"uuid": "9.0.1"
Expand Down
3 changes: 2 additions & 1 deletion src/features/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const loggers: LoggerMap = new Map([["stdout", stdoutLog]]);
export const logger = {
add: ({ id, logger }: LoggerObj) => loggers.set(id, logger),
remove: (loggerId: LoggerObj["id"]) => loggers.delete(loggerId),
log: (type: string, text: string, logName: LoggerKey = "botLog") => {
log: (type: string, log: string | Error, logName: LoggerKey = "botLog") => {
const defaultLogger = loggers.get("stdout");
const logger = loggers.get(logName);

Expand All @@ -51,6 +51,7 @@ export const logger = {
return;
}

const text = log instanceof Error ? `${log.message} ${log.stack}` : log;
defaultLogger(type, text);
logger(type, text);
},
Expand Down
20 changes: 15 additions & 5 deletions src/features/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ export const resumeResources = async (bot: Client) => {
},
{
role: "user",
content: firstMessage.content,
attachments: [{ file_id: file.id }],
content: firstMessage.content || "Here is my resume",
attachments: [
{
file_id: file.id,
tools: [{ type: "file_search" }],
},
],
},
],
}),
Expand Down Expand Up @@ -179,10 +184,15 @@ export const resumeResources = async (bot: Client) => {
});
} catch (e) {
// recover
console.log(e);
deferred.edit("Oops, something went wrong talking to the AI.");
if (e instanceof Error) {
logger.log("RESUME", e);
}
return;
} finally {
// Ensure files are cleaned up
await openai.files.del(file.id);
}
// Ensure files are cleaned up
await openai.files.del(file.id);

// defer: offer fixed interaction buttons to send more prompts
return;
Expand Down

0 comments on commit 7898ffe

Please sign in to comment.