sonnet 4.5

This commit is contained in:
sebseb7
2025-10-10 05:46:42 +02:00
parent f683f9d80a
commit 43b8760a6e
3 changed files with 4183 additions and 14 deletions

4104
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
{
"dependencies": {
"@anthropic-ai/bedrock-sdk": "^0.25.0",
"axios": "^1.6.2",
"body-parser": "^2.2.0",
"dotenv": "^16.3.1",

92
x.js
View File

@@ -11,6 +11,9 @@ const path = require('path');
// Use built-in fetch (Node.js 18+) or fallback to 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) ---
// 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
async function getCommitDiffFromGitea(giteaBaseUrl, repoOwner, repoName, commitHash) {
const giteaToken = process.env.GITEA_TOKEN;
@@ -154,19 +183,37 @@ async function summarizeMostRecentCommitDE(webhookPayload = null) {
const model = process.env.LLM_MODEL || (provider === 'openrouter' ? 'openrouter/anthropic/claude-3.5-sonnet' : 'gpt-4o-mini');
let baseUrl;
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';
apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
logMessage('LLM API key not configured; skipping executive summary', 'warn');
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;
if (!apiKey) {
logMessage('LLM API key not configured; skipping executive summary', 'warn');
return null;
}
}
// Require webhook payload - no fallback to local git
@@ -207,14 +254,31 @@ async function summarizeMostRecentCommitDE(webhookPayload = null) {
`${diff ? diff.slice(0, 120000) : '(kein Diff verfügbar)'}`;
try {
const summary = await callLLMOpenAICompatible({
baseUrl,
apiKey,
model,
system: systemWithDiff,
user: prompt.user,
timeoutMs: 20000
});
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,
apiKey,
model,
system: systemWithDiff,
user: prompt.user,
timeoutMs: 20000
});
}
if (!summary) return null;
return summary;
} catch (e) {