Skip to content

Commit 2ae3b0b

Browse files
init prd prompt (#47)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 19b25c5 commit 2ae3b0b

File tree

6 files changed

+152
-4
lines changed

6 files changed

+152
-4
lines changed

backend/src/build-system/hanlder-manager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ProjectInitHandler } from './node/project-init';
22
import { BuildHandler } from './types';
3+
import { PRDHandler } from './node/product_requirements_document/prd';
34

45
export class BuildHandlerManager {
56
private static instance: BuildHandlerManager;
@@ -10,7 +11,10 @@ export class BuildHandlerManager {
1011
}
1112

1213
private registerBuiltInHandlers() {
13-
const builtInHandlers: BuildHandler[] = [new ProjectInitHandler()];
14+
const builtInHandlers: BuildHandler[] = [
15+
new ProjectInitHandler(),
16+
new PRDHandler(),
17+
];
1418

1519
for (const handler of builtInHandlers) {
1620
this.handlers.set(handler.id, handler);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { BuildHandler, BuildResult } from 'src/build-system/types';
2+
import { BuilderContext } from 'src/build-system/context';
3+
import { prompts } from './prompt/prompt';
4+
import { ModelProvider } from 'src/common/model-provider';
5+
import { StreamStatus } from 'src/chat/chat.model';
6+
import * as fs from 'fs';
7+
import * as path from 'path';
8+
9+
export class PRDHandler implements BuildHandler {
10+
readonly id = 'op:PRD::STATE:GENERATE';
11+
12+
async run(context: BuilderContext): Promise<BuildResult> {
13+
console.log('Generating PRD...');
14+
15+
// Extract project data from the context
16+
const projectName =
17+
context.getData('projectName') || 'Default Project Name';
18+
const description = context.getData('description') || 'Default Description';
19+
const platform = context.getData('platform') || 'Default Platform';
20+
21+
// Generate the prompt dynamically
22+
const prompt = prompts.generatePRDPrompt(
23+
projectName,
24+
description,
25+
platform,
26+
);
27+
28+
// Send the prompt to the LLM server and process the response
29+
const prdContent = await this.generatePRDFromLLM(prompt);
30+
31+
// Save the PRD content to context for further use
32+
context.setData('prdDocument', prdContent);
33+
34+
return {
35+
success: true,
36+
data: prdContent,
37+
};
38+
}
39+
40+
private async generatePRDFromLLM(prompt: string): Promise<string> {
41+
const modelProvider = ModelProvider.getInstance();
42+
43+
const model = 'gpt-3.5-turbo';
44+
45+
// Call the chat method with the model specified
46+
const chatStream = modelProvider.chat(
47+
{
48+
content: prompt,
49+
},
50+
model,
51+
); // Pass the model here
52+
53+
const prdContent = modelProvider.chunkSync(chatStream);
54+
55+
console.log('Received full PRD content from LLM server.');
56+
return prdContent;
57+
}
58+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Define and export the system prompts object
2+
3+
export const prompts = {
4+
generatePRDPrompt: (
5+
projectName: string,
6+
description: string,
7+
platform: string,
8+
): string => {
9+
return `You are an expert Product Manager. Your job is to analyze and expand upon the details provided, generating a Full Product Requirement Document (PRD) based on the following inputs:
10+
- Project name: ${projectName}
11+
- Description: ${description}
12+
- Platform: ${platform}
13+
14+
Follow these guidelines to ensure clarity, thoroughness, and usability in the PRD, which will be directly utilized in development.
15+
### Instructions and Rules:
16+
17+
1, Your need to analysis the requirement for the project and covered all the things you can think about.
18+
2, You should focus on core features for the project
19+
3, ask yourself:
20+
- what are all expect features require for a {project name} and {Description}?
21+
- what are the user stories for the feature?
22+
- what are the details description for those features?
23+
- Am I cover all expect features ? if not then add new feature.
24+
- Are those covered all user expected features ? if not then add new feature.
25+
- what are the target audience for the project? Is all the features meet their expectation? if not then add new feature.
26+
- Ask your self what are the function requirement and none functional requirement for those features?
27+
- Are all features could be agree by others in the team? including product manager, developer....
28+
29+
### PRD Structure:
30+
31+
Start with the following structure. Do not include sections for Milestones, Deliverables, or Technical Requirements.
32+
33+
---
34+
35+
### Product Requirement Document
36+
37+
#### 1. Project Overview
38+
- **Project Name**:
39+
- **Description**: Provide a brief overview of the project’s objective and purpose.
40+
- **Platform**: Indicate the platform(s) (e.g., Web, Mobile).
41+
42+
#### 2. Goals and Objectives
43+
- Define the primary goals and purpose of the project.
44+
- Describe any key performance indicators or success criteria.
45+
46+
#### 3. Target Audience
47+
- Identify the intended users or customer segments.
48+
- Describe user needs, pain points, and how the product will address them.
49+
50+
#### 4. User Stories
51+
- List user stories that illustrate interactions for each main feature.
52+
- Make each story actionable, focusing on user goals.
53+
54+
#### 5. Features
55+
- Outline each feature required for the project.
56+
- Write the requirement for the feature
57+
58+
#### 6. Functional Requirements
59+
- Specify the functional requirements for each feature and sub-feature.
60+
- Use clear, concise statements outlining required functionality.
61+
62+
#### 7. Non-Functional Requirements
63+
- Describe performance, security, usability, and other quality-related requirements.
64+
65+
#### 8. Additional Analysis
66+
- Provide any further insights or considerations to ensure a holistic view of the project requirements.
67+
---
68+
69+
Your reply must start with : "\`\`\`ProductDoc" and end with "\`\`\`". Be thorough, and make sure each section is fully developed and ready for implementation.
70+
`;
71+
},
72+
};

backend/src/build-system/node/project-init.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export class ProjectInitHandler implements BuildHandler {
88
async run(context: BuilderContext): Promise<BuildResult> {
99
console.log('Setting up project...');
1010
const result = {
11-
projectName: 'example',
11+
projectName: 'online shoping',
12+
descreption: 'sell products',
13+
Platform: 'Web',
1214
path: '/path/to/project',
1315
};
1416
context.setData('projectConfig', result);

backend/src/chat/chat.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
import { CustomAsyncIterableIterator } from 'src/common/model-provider/types';
1414
import { ModelProvider } from 'src/common/model-provider';
1515

16-
1716
@Injectable()
1817
export class ChatProxyService {
1918
private readonly logger = new Logger('ChatProxyService');

backend/src/common/model-provider/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class ModelProvider {
5151

5252
chat(
5353
input: ChatInput | string,
54-
model?: string,
54+
model: string,
5555
chatId?: string,
5656
): CustomAsyncIterableIterator<ChatCompletionChunk> {
5757
const chatInput = this.normalizeChatInput(input);
@@ -199,6 +199,19 @@ export class ModelProvider {
199199
}
200200
}
201201

202+
async chunkSync(chatStream: AsyncIterableIterator<any>): Promise<string> {
203+
let aggregatedContent = '';
204+
for await (const chunk of chatStream) {
205+
if (chunk.status === StreamStatus.STREAMING) {
206+
aggregatedContent += chunk.choices
207+
.map((choice) => choice.delta?.content || '')
208+
.join('');
209+
}
210+
}
211+
this.logger.log('Aggregated content from chat stream:', aggregatedContent);
212+
return aggregatedContent;
213+
}
214+
202215
private startChat(input: ChatInput, model: string, chatId?: string) {
203216
const payload = this.createRequestPayload(input, model, chatId);
204217

0 commit comments

Comments
 (0)