sonnet 4.5
This commit is contained in:
4104
package-lock.json
generated
4104
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@anthropic-ai/bedrock-sdk": "^0.25.0",
|
||||||
"axios": "^1.6.2",
|
"axios": "^1.6.2",
|
||||||
"body-parser": "^2.2.0",
|
"body-parser": "^2.2.0",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
|
|||||||
78
x.js
78
x.js
@@ -11,6 +11,9 @@ const path = require('path');
|
|||||||
// Use built-in fetch (Node.js 18+) or fallback to node-fetch
|
// Use built-in fetch (Node.js 18+) or fallback to node-fetch
|
||||||
const fetch = globalThis.fetch || require('node-fetch');
|
const fetch = globalThis.fetch || require('node-fetch');
|
||||||
|
|
||||||
|
// AWS Bedrock SDK for Anthropic
|
||||||
|
const AnthropicBedrock = require("@anthropic-ai/bedrock-sdk");
|
||||||
|
|
||||||
// --- Helpers: Git log + LLM summarization for Executive Summary (DE) ---
|
// --- Helpers: Git log + LLM summarization for Executive Summary (DE) ---
|
||||||
|
|
||||||
// Promise-based exec wrapper with timeout
|
// Promise-based exec wrapper with timeout
|
||||||
@@ -109,6 +112,32 @@ async function callLLMOpenAICompatible({ baseUrl, apiKey, model, system, user, t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AWS Bedrock client for Anthropic
|
||||||
|
async function callLLMBedrock({ awsAccessKey, awsSecretKey, awsRegion, model, system, user, timeoutMs = 20000 }) {
|
||||||
|
try {
|
||||||
|
const abclient = new AnthropicBedrock({
|
||||||
|
awsAccessKey,
|
||||||
|
awsSecretKey,
|
||||||
|
awsRegion
|
||||||
|
});
|
||||||
|
|
||||||
|
// Bedrock API uses a different format - system is a separate parameter
|
||||||
|
const response = await abclient.messages.create({
|
||||||
|
model,
|
||||||
|
system: system,
|
||||||
|
messages: [
|
||||||
|
{ role: 'user', content: user }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
// Extract text content from response (similar behavior to OpenAI-compatible)
|
||||||
|
const text = response.content?.[0]?.text?.trim();
|
||||||
|
return text || '';
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(`Bedrock API error: ${e.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get commit diff from Gitea API
|
// Get commit diff from Gitea API
|
||||||
async function getCommitDiffFromGitea(giteaBaseUrl, repoOwner, repoName, commitHash) {
|
async function getCommitDiffFromGitea(giteaBaseUrl, repoOwner, repoName, commitHash) {
|
||||||
const giteaToken = process.env.GITEA_TOKEN;
|
const giteaToken = process.env.GITEA_TOKEN;
|
||||||
@@ -154,20 +183,38 @@ async function summarizeMostRecentCommitDE(webhookPayload = null) {
|
|||||||
const model = process.env.LLM_MODEL || (provider === 'openrouter' ? 'openrouter/anthropic/claude-3.5-sonnet' : 'gpt-4o-mini');
|
const model = process.env.LLM_MODEL || (provider === 'openrouter' ? 'openrouter/anthropic/claude-3.5-sonnet' : 'gpt-4o-mini');
|
||||||
let baseUrl;
|
let baseUrl;
|
||||||
let apiKey;
|
let apiKey;
|
||||||
|
let awsAccessKey;
|
||||||
|
let awsSecretKey;
|
||||||
|
let awsRegion;
|
||||||
|
|
||||||
if (provider === 'openai') {
|
if (provider === 'bedrock') {
|
||||||
|
// AWS Bedrock configuration
|
||||||
|
awsAccessKey = process.env.AWS_ACCESS_KEY;
|
||||||
|
awsSecretKey = process.env.AWS_SECRET_KEY;
|
||||||
|
awsRegion = process.env.AWS_REGION || 'eu-central-1';
|
||||||
|
|
||||||
|
if (!awsAccessKey || !awsSecretKey) {
|
||||||
|
logMessage('AWS credentials not configured; skipping executive summary', 'warn');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else if (provider === 'openai') {
|
||||||
baseUrl = process.env.OPENAI_BASE_URL || 'https://api.openai.com';
|
baseUrl = process.env.OPENAI_BASE_URL || 'https://api.openai.com';
|
||||||
apiKey = process.env.OPENAI_API_KEY;
|
apiKey = process.env.OPENAI_API_KEY;
|
||||||
} else {
|
|
||||||
// default openrouter
|
|
||||||
baseUrl = process.env.OPENROUTER_BASE_URL || 'https://openrouter.ai/api';
|
|
||||||
apiKey = process.env.OPENROUTER_API_KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
logMessage('LLM API key not configured; skipping executive summary', 'warn');
|
logMessage('LLM API key not configured; skipping executive summary', 'warn');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// default openrouter
|
||||||
|
baseUrl = process.env.OPENROUTER_BASE_URL || 'https://openrouter.ai/api';
|
||||||
|
apiKey = process.env.OPENROUTER_API_KEY;
|
||||||
|
|
||||||
|
if (!apiKey) {
|
||||||
|
logMessage('LLM API key not configured; skipping executive summary', 'warn');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Require webhook payload - no fallback to local git
|
// Require webhook payload - no fallback to local git
|
||||||
if (!webhookPayload || !webhookPayload.commits || webhookPayload.commits.length === 0) {
|
if (!webhookPayload || !webhookPayload.commits || webhookPayload.commits.length === 0) {
|
||||||
@@ -207,7 +254,22 @@ async function summarizeMostRecentCommitDE(webhookPayload = null) {
|
|||||||
`${diff ? diff.slice(0, 120000) : '(kein Diff verfügbar)'}`;
|
`${diff ? diff.slice(0, 120000) : '(kein Diff verfügbar)'}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const summary = await callLLMOpenAICompatible({
|
let summary;
|
||||||
|
|
||||||
|
if (provider === 'bedrock') {
|
||||||
|
// Use Bedrock API
|
||||||
|
summary = await callLLMBedrock({
|
||||||
|
awsAccessKey,
|
||||||
|
awsSecretKey,
|
||||||
|
awsRegion,
|
||||||
|
model,
|
||||||
|
system: systemWithDiff,
|
||||||
|
user: prompt.user,
|
||||||
|
timeoutMs: 20000
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Use OpenAI-compatible API (openai, openrouter, etc.)
|
||||||
|
summary = await callLLMOpenAICompatible({
|
||||||
baseUrl,
|
baseUrl,
|
||||||
apiKey,
|
apiKey,
|
||||||
model,
|
model,
|
||||||
@@ -215,6 +277,8 @@ async function summarizeMostRecentCommitDE(webhookPayload = null) {
|
|||||||
user: prompt.user,
|
user: prompt.user,
|
||||||
timeoutMs: 20000
|
timeoutMs: 20000
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!summary) return null;
|
if (!summary) return null;
|
||||||
return summary;
|
return summary;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user