Skip to content

Commit 6a87fff

Browse files
committed
mistral
1 parent c33af3f commit 6a87fff

File tree

7 files changed

+64
-64
lines changed

7 files changed

+64
-64
lines changed

http-backend/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

http-backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@google/generative-ai": "^0.21.0",
1717
"@langchain/community": "^0.3.31",
1818
"@langchain/core": "^0.3.40",
19+
"@mistralai/mistralai": "^1.5.0",
1920
"@octokit/plugin-retry": "^7.1.4",
2021
"@octokit/plugin-throttling": "^9.4.0",
2122
"@prisma/client": "^6.4.0",

http-backend/src/router/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ router.post("/create", async (req,res): Promise<any> => {
6767
}
6868
})
6969

70-
// Enqueue the GitHub indexing job – this runs in the background.
70+
//Enqueue the GitHub indexing job – this runs in the background.
7171
await qstashClient.publishJSON({
7272
url: `https://pullscan.onrender.com/v1/api/background/index-github`,
7373
body: {

http-backend/src/utils/ai/gemni.ts

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {GoogleGenerativeAI} from "@google/generative-ai"
2-
import { Document } from "@langchain/core/documents"
32
import { commit_main_summary_prompt, pr_summary_prompt } from "../prompt"
4-
3+
import fs from 'fs'; // Add this import at the top
4+
import {summary_pr_mistral} from "./mistral"
55

66
export interface CodeChange {
77
filename: string;
@@ -27,67 +27,35 @@ export const aisummariseCommit = async (diff: string,commitMessage:string) => {
2727
}
2828

2929
export const aisummarisePR = async (codes:CodeChange[],pullReqTitle: string, pullReqMessage:string) => {
30-
const full_code:string = codes.map((code) => code.patch + code.filename).join('\n');
31-
32-
// const pr_prompt = pr_summary_prompt({
33-
// title:pullReqTitle,
34-
// description:pullReqMessage,
35-
// file_diff:full_code
36-
// })
37-
38-
// const prompt: MessageParam[] = [{
39-
// role: 'user',
40-
// content: `${pr_prompt}`
41-
// }]
42-
43-
// const main_summary = await generateCompletionClaude(prompt)
44-
45-
const main_summary = await await model.generateContent([
46-
pr_summary_prompt({
47-
title:pullReqTitle,
48-
description:pullReqMessage,
49-
file_diff:full_code
50-
})
51-
])
52-
53-
54-
return main_summary.response.text()
55-
}
56-
30+
const full_code:string = codes.map((code) => code.patch + code.filename).join('');
5731

32+
const system_prompt = pr_summary_prompt({
33+
title:pullReqTitle,
34+
description:pullReqMessage,
35+
file_diff:full_code
36+
})
37+
const prompt = 'Summerise this PR'
5838

59-
// This summarize code generate summary for the RAG
60-
export const summarizecode = async (doc:Document) => {
61-
console.log("getting summary for",doc.metadata.source);
62-
try{
63-
const code = doc.pageContent.slice(0,10000);
64-
const response = await model.generateContent([
65-
`You are an inteligen software engineer who specialize in onboarding junior software engineers on the project
66-
You are onboaring juniors software engineer and explaing to them the purpose of the ${doc.metadata.source} file
67-
68-
Here is the code:
69-
--------
70-
${code}
71-
--------
72-
Give a summary no more than 100 words of the code above`
73-
74-
])
75-
76-
return response.response.text()
77-
78-
}catch(error){
79-
return ''
80-
}
81-
82-
}
39+
const main = await summary_pr_mistral(system_prompt,prompt)
40+
return main
41+
42+
// fs.writeFileSync(`'full_code_${i}.txt'`, full_code, 'utf8'); // Add this line to save the code
43+
// i++;
44+
// console.log("Title:", pullReqTitle)
45+
// fs.writeFileSync(`'title_${i}.txt'`, pullReqTitle, 'utf8'); // Add this line to save the code
46+
47+
// console.log("Description:",pullReqMessage)
48+
// fs.writeFileSync(`'description_${i}.txt'`, pullReqMessage, 'utf8'); // Add this line to save the code
49+
// console.log('code',full_code)
8350

84-
export async function aigenerateEmbedding(summary:string) {
85-
const model = genAI.getGenerativeModel({
86-
model: "text-embedding-004"
87-
})
51+
// const main_summary = await model.generateContent([
52+
// pr_summary_prompt({
53+
// title:pullReqTitle,
54+
// description:pullReqMessage,
55+
// file_diff:full_code
56+
// })
57+
// ])
8858

89-
const result = await model.embedContent(summary)
90-
const embedding = result.embedding
91-
return embedding.values
92-
}
9359

60+
//return main_summary.response.text()
61+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Mistral } from '@mistralai/mistralai';
2+
3+
const apiKey = process.env.MISTRAL_API_KEY;
4+
5+
const client = new Mistral({apiKey: apiKey});
6+
7+
export const summary_pr_mistral = async function(system_prompt:string,prompt:string) {
8+
const chatResponse:any = await client.chat.complete({
9+
model: 'mistral-small-latest',
10+
messages: [{role: 'user', content: `${prompt}`},{role:'system',content:`${system_prompt}`}],
11+
});
12+
13+
//console.log('Chat:', chatResponse.choices[0].message.content);
14+
15+
return chatResponse?.choices[0]?.message?.content
16+
}
17+
18+
19+

http-backend/src/utils/github/pull-req.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,4 @@ async function summarizePR(githubUrl: string, pullReqHashes: string, pr_number:n
121121

122122
// }
123123

124-
// main()
124+
// main();

http-backend/tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"root":["./src/index.ts","./src/db/index.ts","./src/db/seed.ts","./src/queues/githubqueue.ts","./src/router/background.ts","./src/router/project.ts","./src/utils/prompt.ts","./src/utils/ai/claude.ts","./src/utils/ai/gemni.ts","./src/utils/ai/openai.ts","./src/utils/github/commit.ts","./src/utils/github/github-loader.ts","./src/utils/github/octakit.ts","./src/utils/github/pull-req.ts","./src/utils/langbase/memory.ts","./src/utils/langbase/pipe.ts","./src/utils/langbase/prompt.ts"],"version":"5.7.3"}
1+
{"root":["./src/index.ts","./src/db/index.ts","./src/db/seed.ts","./src/queues/githubqueue.ts","./src/router/background.ts","./src/router/project.ts","./src/utils/prompt.ts","./src/utils/ai/claude.ts","./src/utils/ai/gemni.ts","./src/utils/ai/mistral.ts","./src/utils/ai/openai.ts","./src/utils/github/commit.ts","./src/utils/github/github-loader.ts","./src/utils/github/octakit.ts","./src/utils/github/pull-req.ts","./src/utils/langbase/memory.ts","./src/utils/langbase/pipe.ts","./src/utils/langbase/prompt.ts"],"version":"5.7.3"}

0 commit comments

Comments
 (0)