Skip to content

Commit

Permalink
La inn valg om kortsvar og la inn konsulentens navn (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
haakoaho authored Nov 28, 2023
1 parent f3991d4 commit feede6c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 15 deletions.
40 changes: 34 additions & 6 deletions app/api/chewbacca/generateRequirementResponse/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const POST = async (
req: NextRequest,
res: NextResponse,
): Promise<Response> => {
const { employeeAlias, requirement } = await req.json();
const { employeeAlias, requirement, name, concise } = await req.json();

const session = (await getServerSession(authOptions)) as CustomSession;
if (
Expand All @@ -63,7 +63,13 @@ export const POST = async (
return new Response(JSON.stringify({}), { status: 400 });
}

const result = await generateRequirementResponse(rc, token, employeeAlias);
const result = await generateRequirementResponse(
rc,
token,
employeeAlias,
name,
concise,
);

return new Response(JSON.stringify(result), { status: 200 });
};
Expand Down Expand Up @@ -109,6 +115,11 @@ async function generateKeywordsFromRequirements(
competencies: string[],
): Promise<RequirementCompetency> {
const example: ChatCompletionRequestMessage[] = [
{
role: "system",
content:
"Det du skriver, skal brukes i et skript. Ikke diverger fra output-format. Bare bruk ord fra Nøkkelordliste i svaret.",
},
{
role: "user",
content:
Expand Down Expand Up @@ -146,6 +157,8 @@ async function generateRequirementResponse(
requirement: RequirementCompetency,
token: string,
employeeAlias: string,
name: string,
concise: boolean,
): Promise<RequirementResponse> {
const projectExperienceResponse = await findRelevantProjectForCompetencies(
token,
Expand All @@ -166,25 +179,40 @@ async function generateRequirementResponse(
projects: [],
};
}
const prompt: string = `bruk tabellen under og svar på kravet.
const prompt: string = `bruk tabellen under og svar på hvordan ${name} møter kravet
Prosjekt med prosjektnavn og kundenavn når du referer til prosjekt.
Bruk sitater som er relevant for kravet i teksten.
Du kan ikke forvente at leser kjenner til tabellen.
Du skal lage en sammenhengende tekst og ikke en tabell.
Argumenter best mulig hvordan prosjektene svarer mot kravet.
Ikke ta med informasjon som ikke er relevant for kravet.
krav : ${
requirement.requirement
} tabell med utvalgte prosjekt: prosjektnavn,kundenavn,beskrivelse,rolle\n ${relevantProjects
} tabell med utvalgte prosjekt: prosjektnavn,kundenavn,beskrivelse,rollene til ${name}\n ${relevantProjects
?.map(projectExperienceToText)
.join("\n")}`;
console.log(prompt);
const response = await requestOpenai(
let response = await requestOpenai(
[{ role: "user", content: prompt }],
"variant-rocks-turbo-16k",
2000,
0.75,
);
if (concise) {
response = await requestOpenai(
[
{
role: "user",
content: `Ta utgangspunkt i følgende tekst "${response}"
Kjøper er bare interessert i hvordan ${name} svarer mot kravet ${requirement.requirement}
For å styrke argumentet ditt så må du bare bruke relevant tekst i ditt argument.
`,
},
],
"variant-rocks",
2000,
0,
);
}
return {
requirement: requirement.requirement,
response: response,
Expand Down
14 changes: 10 additions & 4 deletions app/api/chewbacca/generateSummaryOfQualifications/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ export const POST = async (
req: NextRequest,
res: NextResponse,
): Promise<Response> => {
const { requirementResponses, summaryText } = await req.json();
const { requirementResponses, summaryText, name } = await req.json();

const result =
(await generateSummaryOfQualifications(
requirementResponses,
summaryText,
name,
)) ?? "";

return new Response(JSON.stringify(result), { status: 200 });
Expand All @@ -22,20 +23,23 @@ export const POST = async (
async function generateSummaryOfQualifications(
requirementResponses: RequirementResponse[],
summaryText: string | undefined,
name: string,
): Promise<string | undefined> {
return await generateSummaryFromRequirementResponses(
requirementResponses,
summaryText,
name,
);
}

function findSummaryPrompt(
requirementResponses: RequirementResponse[],
summaryText: string | undefined,
name: string,
) {
const table = requirementResponsesToTable(requirementResponses);
if (summaryText) {
return `Vi har nå fått en krav-begrunnelse tabell ${table}.
return `Vi har nå fått en krav-begrunnelse tabellen som ${name} må oppfylle ${table}.
Her er det gamle sammendraget ${summaryText}.
Skriv om sammendraget slik at den svarer på alle krav
med begrunnelesen i tabellen. Bruk alt i tabellen og sammendraget.
Expand All @@ -49,9 +53,10 @@ function findSummaryPrompt(
Du kan ikke regne med at brukeren har lest krav-begrunnelse tabellen.
`;
}
return `Her er krav-begrunnelse tabellen. Lag et sammendrag av konsulentens
return `Her er krav-begrunnelse tabellen. Lag et sammendrag av ${name} sin
erfaring som svarer på kravene. Sammendraget bør være langt.
Husk å referer til navn på prosjekt, kunde og års erfaring for hvert krav i sammendraget.
Sammendraget må flyte naturlig og sammenhengende så den scorer høyt i salg.
Husk å inkludere alle rader ifra tabellen i svaret.
Det kan hende at samme prosjekt er brukt i de ulike begrunnelsene.
Ikke bruk noe som ikke står i tabllen i ditt sammendrag.
Expand All @@ -62,8 +67,9 @@ function findSummaryPrompt(
async function generateSummaryFromRequirementResponses(
requirementResponses: RequirementResponse[],
summaryText: string | undefined,
name: string,
): Promise<string> {
const prompt = findSummaryPrompt(requirementResponses, summaryText);
const prompt = findSummaryPrompt(requirementResponses, summaryText, name);
const summary = await requestOpenai(
[{ role: "user", content: prompt }],
"variant-rocks-turbo-16k",
Expand Down
1 change: 1 addition & 0 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ const cn = {
ChooseEmployee: "Choose employee",
SelectPlaceholder: "What employee do you want to get the CV for?",
Requirements: "Requirements",
ConciseOption: "Answer requirements concisely",
RequirementsPlaceholder:
"The candidate must have experience with X\nThe candidate must have experience with Y\nExperience with Z is a plus",
Summary: "Summary",
Expand Down
1 change: 1 addition & 0 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ const en: LocaleType = {
ChooseEmployee: "Choose employee",
SelectPlaceholder: "What employee do you want to get the CV for?",
Requirements: "Requirements",
ConciseOption: "Answer requirements concisely",
RequirementsPlaceholder:
"The candidate must have experience with X\nThe candidate must have experience with Y\nExperience with Z is a plus",
Summary: "Summary",
Expand Down
1 change: 1 addition & 0 deletions app/locales/no.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const no: PartialLocaleType = {
MoreToCome: " (mer kommer!)",
},
ChooseEmployee: "Velg ansatt",
ConciseOption: "Svar kortfattet på krav",
SelectPlaceholder: "Hvilken ansatt vil du hente CV-en til?",
Requirements: "Krav til kompetanse",
RequirementsPlaceholder:
Expand Down
28 changes: 23 additions & 5 deletions app/salesGPT/components/salesGPT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function _SalesGPT() {

const [showCVSummary, setShowCVSummary] = useState(false);
const [showRequirementsList, setShowRequirementsList] = useState(false);
const [concise, setConcise] = useState(false);

function handleSelectEmployee(newValue: EmployeeItem | undefined): void {
setSelectedEmployee(newValue);
Expand Down Expand Up @@ -112,14 +113,15 @@ function _SalesGPT() {
requirements: string[],
): Promise<RequirementResponse[]> => {
const requirementPromises = requirements.map(async (requirement) => {
const name = getFirstName(selectedEmployee?.name ?? "");
const response = await fetch(
"/api/chewbacca/generateRequirementResponse",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ employeeAlias, requirement }),
body: JSON.stringify({ employeeAlias, requirement, name, concise }),
},
);
const data = await response.json();
Expand All @@ -130,6 +132,10 @@ function _SalesGPT() {
return requirementResponses;
};

function getFirstName(name: string): string {
return name.split(" ")[0];
}

const runSummaryAnalysis = async (
employeeAlias: string,
requirements: string[],
Expand All @@ -138,14 +144,15 @@ function _SalesGPT() {
await fetchRequirements(employeeAlias, requirements)
.then(async (requirementResponses) => {
setRequirementResponse(requirementResponses);
const name = getFirstName(selectedEmployee?.name ?? "");
const response = await fetch(
"/api/chewbacca/generateSummaryOfQualifications",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ requirementResponses, summaryText }),
body: JSON.stringify({ requirementResponses, summaryText, name }),
},
);
const data = await response.json();
Expand Down Expand Up @@ -217,9 +224,9 @@ function _SalesGPT() {
useChatStore.getState().currentSession().messages = [
{
role: "user",
content: `Bruk prosjektene til å lage et sammendrag av erfaringene til ${selectedEmployee?.name} ${projects
.map(projectExperienceToText)
.join("\n")}`,
content: `Bruk prosjektene til å lage et sammendrag av erfaringene til ${selectedEmployee?.name}
prosjektnavn,kundenavn,beskrivelse,rolle\n
${projects.map(projectExperienceToText).join("\n")}`,
id: `${id++}`,
date: new Date().toDateString(),
},
Expand Down Expand Up @@ -292,6 +299,17 @@ function _SalesGPT() {
onChange={(event) => setSummaryText(event.target.value)}
></textarea>
</div>
<div className={styles["input-field"]}>
<label htmlFor="concise-answer">
{Locale.SalesGPT.ConciseOption}
</label>
<input
type="checkbox"
id="concise-answer"
checked={concise}
onChange={(event) => setConcise(event.target.checked)}
/>
</div>
<div className={styles["analyse-button-container"]}>
<IconButton
key="analyse"
Expand Down

0 comments on commit feede6c

Please sign in to comment.