lakshmisravya123 commited on
Commit
5cc521b
·
1 Parent(s): dad7400

Upgrade: EQ scoring, real-time coaching, detailed performance reports

Browse files
backend/services/ai.js.bak ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const GROQ_API_KEY = process.env.GROQ_API_KEY;
2
+ const OLLAMA_URL = process.env.OLLAMA_URL || 'http://localhost:11434';
3
+ const GROQ_MODEL = process.env.GROQ_MODEL || 'llama-3.3-70b-versatile';
4
+ const OLLAMA_MODEL = process.env.OLLAMA_MODEL || 'llama3.2:3b';
5
+
6
+ async function callAI(prompt) {
7
+ if (GROQ_API_KEY) {
8
+ const res = await fetch('https://api.groq.com/openai/v1/chat/completions', {
9
+ method: 'POST',
10
+ headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${GROQ_API_KEY}` },
11
+ body: JSON.stringify({ model: GROQ_MODEL, messages: [{ role: 'user', content: prompt }], temperature: 0.7 }),
12
+ });
13
+ if (res.ok) { const data = await res.json(); return data.choices[0].message.content; }
14
+ console.warn('Groq failed, falling back to Ollama...');
15
+ }
16
+ const res = await fetch(`${OLLAMA_URL}/api/generate`, {
17
+ method: 'POST',
18
+ headers: { 'Content-Type': 'application/json' },
19
+ body: JSON.stringify({ model: OLLAMA_MODEL, prompt, stream: false }),
20
+ });
21
+ if (!res.ok) throw new Error('Both Groq and Ollama failed.');
22
+ return (await res.json()).response;
23
+ }
24
+
25
+ function parseJSON(text) {
26
+ try { return JSON.parse(text.trim()); }
27
+ catch { const m = text.match(/\{[\s\S]*\}/); if (m) return JSON.parse(m[0]); throw new Error('Failed to parse AI response'); }
28
+ }
29
+
30
+ async function startNegotiation(role, company, currentSalary, targetSalary, difficulty) {
31
+ const diffStyle = { easy: 'Be somewhat flexible, offer small pushback', medium: 'Be professional but firm, use standard negotiation tactics', hard: 'Be very tough, use aggressive tactics like anchoring low, creating urgency, questioning worth' };
32
+ const text = await callAI(`You are a hiring manager at ${company || 'a tech company'} interviewing a candidate for a ${role} position.
33
+ DIFFICULTY: ${difficulty} - ${diffStyle[difficulty] || diffStyle.medium}
34
+
35
+ The candidate's current salary is $${currentSalary || 'unknown'} and they want $${targetSalary}.
36
+ Your initial budget is $${Math.round(targetSalary * 0.85)} but you can go up to $${Math.round(targetSalary * 0.95)} max.
37
+
38
+ Start the negotiation. Make an opening statement and initial offer. Return ONLY valid JSON:
39
+ {"hiringManagerName":"<a realistic name>","openingStatement":"<2-3 sentences opening the salary discussion>","initialOffer":${Math.round(targetSalary * 0.82)},"roundNumber":1}
40
+
41
+ Return ONLY JSON, no markdown.`);
42
+ return parseJSON(text);
43
+ }
44
+
45
+ async function negotiationRound(context, candidateResponse) {
46
+ const text = await callAI(`You are ${context.hiringManagerName}, a hiring manager negotiating salary.
47
+ CONTEXT: Role: ${context.role}, Company: ${context.company}
48
+ DIFFICULTY: ${context.difficulty}
49
+ BUDGET: Your max is $${context.maxBudget}. Current offer: $${context.currentOffer}.
50
+ HISTORY:
51
+ ${context.history.map(h => `${h.role}: ${h.text}`).join('\n')}
52
+
53
+ CANDIDATE JUST SAID: "${candidateResponse}"
54
+
55
+ Respond as the hiring manager. Use real negotiation tactics. Return ONLY valid JSON:
56
+ {"response":"<your 2-4 sentence response>","newOffer":${context.currentOffer},"tactic":"<name the tactic you used: anchoring|urgency|questioning|concession|silence|package-deal|final-offer>","isAccepting":false,"isFinalOffer":false}
57
+
58
+ Adjust newOffer based on the negotiation flow. Only go up incrementally. If candidate is very persuasive, concede a bit more. If weak argument, hold firm.
59
+ Return ONLY JSON, no markdown.`);
60
+ return parseJSON(text);
61
+ }
62
+
63
+ async function generateReport(context) {
64
+ const text = await callAI(`You are a negotiation coach analyzing a salary negotiation practice session.
65
+
66
+ ROLE: ${context.role} at ${context.company}
67
+ TARGET: $${context.targetSalary}
68
+ FINAL OFFER: $${context.finalOffer}
69
+ ROUNDS: ${context.rounds}
70
+
71
+ FULL TRANSCRIPT:
72
+ ${context.history.map(h => `${h.role}: ${h.text}`).join('\n')}
73
+
74
+ Return ONLY valid JSON:
75
+ {
76
+ "overallScore":<1-100>,
77
+ "finalSalary":${context.finalOffer},
78
+ "targetSalary":${context.targetSalary},
79
+ "percentOfTarget":${Math.round((context.finalOffer / context.targetSalary) * 100)},
80
+ "verdict":"<Master Negotiator|Strong Negotiator|Decent|Needs Practice|Pushover>",
81
+ "summary":"<3-4 sentence assessment>",
82
+ "tacticsUsed":["<tactic the candidate used>"],
83
+ "missedOpportunities":["<what they could have done better>"],
84
+ "strengths":["<s1>","<s2>"],
85
+ "improvements":["<i1>","<i2>","<i3>"],
86
+ "tips":["<tip1>","<tip2>","<tip3>"]
87
+ }
88
+ Return ONLY JSON.`);
89
+ return parseJSON(text);
90
+ }
91
+
92
+ module.exports = { startNegotiation, negotiationRound, generateReport };
frontend/src/App.jsx.new ADDED
@@ -0,0 +1 @@
 
 
1
+ test