feat: add AnthropicVertexClient for claude-* models
- @anthropic-ai/vertex-sdk: proper Anthropic Messages API on Vertex - AnthropicVertexClient: converts OAI message format ↔ Anthropic format, handles tool_use blocks, retries 429/503 with backoff - createLLM: routes anthropic/* and claude-* models through new client - Tier B/C default: claude-sonnet-4-6 via us-east5 Vertex endpoint - /generate endpoint: accepts region param for regional endpoint testing Made-with: Cursor
This commit is contained in:
@@ -550,18 +550,24 @@ app.post('/agent/approve', async (req: Request, res: Response) => {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
app.post('/generate', async (req: Request, res: Response) => {
|
||||
const { prompt, model } = req.body as { prompt?: string; model?: string };
|
||||
const { prompt, model, region } = req.body as { prompt?: string; model?: string; region?: string };
|
||||
if (!prompt) { res.status(400).json({ error: '"prompt" is required' }); return; }
|
||||
|
||||
// Allow overriding CLAUDE_REGION per-request for testing
|
||||
const prevRegion = process.env.CLAUDE_REGION;
|
||||
if (region) process.env.CLAUDE_REGION = region;
|
||||
|
||||
try {
|
||||
const llm = createLLM(model ?? 'A', { temperature: 0.3 });
|
||||
const messages: import('./llm').LLMMessage[] = [
|
||||
{ role: 'user', content: prompt }
|
||||
];
|
||||
const response = await llm.chat(messages, [], 8192);
|
||||
res.json({ reply: response.content ?? '' });
|
||||
res.json({ reply: response.content ?? '', model: llm.modelId });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err instanceof Error ? err.message : String(err) });
|
||||
res.status(500).json({ error: err instanceof Error ? err.message : String(err), model });
|
||||
} finally {
|
||||
if (region) process.env.CLAUDE_REGION = prevRegion ?? '';
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user