src/pull-requests/pull-request-description.service.ts
Methods |
|
constructor(openAiService: OpenAIWrappedService)
|
||||||
Parameters :
|
Async generateDescription | ||||||
generateDescription(options: GeneratePullRequestDescriptionDto)
|
||||||
Parameters :
Returns :
unknown
|
Private generatePrompt |
generatePrompt(language: string, maxLength: number, tone: string)
|
Returns :
any
|
import { Injectable } from "@nestjs/common";
import { OpenAIWrappedService } from "../openai-wrapped/openai-wrapped.service";
import { GeneratePullRequestDescriptionDto } from "./dtos/create-pull-request-description.dto";
@Injectable()
export class PullRequestDescriptionService {
constructor(private openAiService: OpenAIWrappedService) {}
private generatePrompt(language: string, maxLength: number, tone: string) {
return [
`Generate an apt github PR description written in present tense and ${tone} tone for the given code diff/commit-messages with the specifications mentioned below`,
`Description language: ${language}`,
`Description must be a maximum of ${maxLength} characters.`,
"Exclude anything unnecessary such as translation. Your entire response will be passed directly into a pull request description",
].join("\n");
}
async generateDescription(options: GeneratePullRequestDescriptionDto) {
const content = `${options.diff ? `Diff: ${options.diff}\n` : ""}${
options.commitMessages ? `\nCommit Messages: ${options.commitMessages.join(",")}` : ""
}`;
try {
const completion = this.openAiService.generateCompletion(
this.generatePrompt(options.language, options.descriptionLength, options.tone),
content,
options.temperature
);
return completion;
} catch (error: unknown) {
if (error instanceof Error) {
console.error("OpenAI error: ", error.message);
}
}
}
}