Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for commit prefix #160

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow For Prefix: refactor(api.ts): extract message prefixing logic t…
…o a separate function to improve readability and maintainability

feat(api.ts): add prefix to the message returned by getOpenCommitLatestVersion function to improve semantics and consistency with other functions
  • Loading branch information
amitayk committed May 27, 2023
commit af6f99b640098569ac81fc16ed8a58f3149de95e
14 changes: 8 additions & 6 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -60,13 +60,9 @@ class OpenAi {
const { data } = await this.openAI.createChatCompletion(params);

const message = data.choices[0].message;
const fullMessage = stitchMessageWithPrefix(message?.content)

const prefix = generatePrefix();
const usePrefix = prefix != undefined && prefix?.trim() != ""

const finalMessage = (usePrefix ? prefix + ' ' : '') + (message?.content || '')

return finalMessage;
return fullMessage;

} catch (error) {
outro(`${chalk.red('✖')} ${JSON.stringify(params)}`);
@@ -91,6 +87,12 @@ class OpenAi {
};
}

function stitchMessageWithPrefix(message: string | undefined){
const prefix = generatePrefix();
const usePrefix = prefix != undefined && prefix?.trim() != ""
return (usePrefix ? prefix + ' ' : '') + (message || '')
}

export const getOpenCommitLatestVersion = async (): Promise<
string | undefined
> => {