Add claude module
This commit is contained in:
@@ -32,6 +32,7 @@ import { ContactModule } from './contact/contact.module';
|
||||
import { HoardingModule } from './hoarding/hoarding.module';
|
||||
import { NamesModule } from './names/names.module';
|
||||
import { AssemblyAiModule } from './assembly-ai/assembly-ai.module';
|
||||
import { ClaudeModule } from './claude/claude.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -110,6 +111,7 @@ import { AssemblyAiModule } from './assembly-ai/assembly-ai.module';
|
||||
HoardingModule,
|
||||
NamesModule,
|
||||
AssemblyAiModule,
|
||||
ClaudeModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [
|
||||
|
63
src/claude/claude.controller.ts
Normal file
63
src/claude/claude.controller.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import Anthropic from '@anthropic-ai/sdk';
|
||||
import { Body, Controller, Logger, Post, Res, Headers } from '@nestjs/common';
|
||||
import { ApiBody, ApiConsumes, ApiResponse } from '@nestjs/swagger';
|
||||
import { Response } from 'express';
|
||||
|
||||
@Controller('claude')
|
||||
export class ClaudeController {
|
||||
private readonly logger = new Logger(ClaudeController.name);
|
||||
private readonly claude: Anthropic;
|
||||
|
||||
constructor() {
|
||||
this.claude = new Anthropic({
|
||||
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||
});
|
||||
}
|
||||
|
||||
@Post('script-to-meeting-summary')
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Converts a script to a meeting summary',
|
||||
type: String,
|
||||
})
|
||||
@ApiBody({
|
||||
description: 'Meeting transcript in script format',
|
||||
type: String,
|
||||
})
|
||||
@ApiConsumes('text/plain')
|
||||
async scriptToMeetingSummary(
|
||||
@Body() body: string,
|
||||
@Res() res: Response,
|
||||
@Headers('x-api-key') apiKey: string,
|
||||
) {
|
||||
if (apiKey !== process.env.CLAUDE_ENDPOINT_KEY) {
|
||||
this.logger.warn('Unauthorized access attempt');
|
||||
return res.status(401).send('Unauthorized');
|
||||
}
|
||||
|
||||
const instructionPrefix = `You are being contacted by an API which is making this call.
|
||||
Do not respond with anything other than the text that should be returned to the user.
|
||||
The meeting transcript follows the line separating these instructions which is a line of = symbols.
|
||||
Return a two paragraph or less summary, bullet points of the topics, and bullet points of any action items.
|
||||
|
||||
==========
|
||||
`;
|
||||
|
||||
this.logger.log(`Received script to summarize: ${body.length} characters`);
|
||||
|
||||
const response = await this.claude.messages.create({
|
||||
model: 'claude-3-7-sonnet-20250219',
|
||||
messages: [
|
||||
{
|
||||
role: 'user',
|
||||
content: `${instructionPrefix}${body}`,
|
||||
},
|
||||
],
|
||||
max_tokens: 1000,
|
||||
});
|
||||
|
||||
return res
|
||||
.header('Content-Type', 'text/plain; charset=utf-8')
|
||||
.send((response.content[0] as any).text);
|
||||
}
|
||||
}
|
7
src/claude/claude.module.ts
Normal file
7
src/claude/claude.module.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ClaudeController } from './claude.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [ClaudeController]
|
||||
})
|
||||
export class ClaudeModule {}
|
Reference in New Issue
Block a user