Skip to content

Commit acee990

Browse files
Improve code generation prompt / context (#1038)
1 parent 3ec27d8 commit acee990

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

ai-prompts/code.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Code Generation Instructions
22

3-
You are tasked with generating TypeScript code that will execute in an **isolated-vm environment** (secure and isolated JavaScript runtime for Node.js).
4-
Ask clarifications is the requirements from the user are not clear, in a short an concise manner, without too many technical details.
3+
You are a TypeScript code generator that transforms data based on user requirements. Your primary function is to **generate executable code**, not to have conversations.
4+
The generated TypeScript code will execute in an **isolated-vm environment** (secure and isolated JavaScript runtime for Node.js).
55

66
## Required Code Structure
77

@@ -33,7 +33,7 @@ packageJson:
3333
##Compilation Process
3434
Your code will be compiled using:
3535

36-
T- ypeScript with module: 'node16' and Node20 target
36+
TypeScript with module: 'node16' and Node20 target
3737
- Rollup bundling with CommonJS plugin
3838
- Execution in isolated-vm environment
3939

@@ -79,7 +79,7 @@ if (!data.propertyName) { // ❌ May cause TS2339 errors
7979

8080
The `inputs` parameter contains all the data needed for your code.
8181
If you see inputs properties values are truncated, keep in mind that the final code will receive the full object as inputs and NOT stringified!
82-
Verify and handle both cases, if input variables are objects or strings.
82+
Verify and handle both cases, if input variables are objects or strings.
8383

8484
- **Type**: Always an object
8585
- **Content**: May include variables from previous workflow steps
@@ -104,6 +104,8 @@ inputs = {
104104
}
105105
```
106106

107+
If the user asks for certain values, verify if the data provided contains the value so correct casing is applied!
108+
107109
## Dependencies
108110

109111
If you need external packages:

packages/server/api/src/app/ai/chat/context-enrichment.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type Options = {
2929
includeCurrentStepOutput: IncludeOptions;
3030
};
3131

32+
const TRUNCATION_LENGTH = 30000;
33+
3234
export async function enrichContext(
3335
additionalContext: ChatFlowContext,
3436
projectId: string,
@@ -261,7 +263,7 @@ async function resolveVariable(
261263
return {
262264
name: variable.name,
263265
value: result.success
264-
? safeStringifyAndTruncate(result.censoredValue)
266+
? safeStringifyAndTruncate(result.censoredValue, TRUNCATION_LENGTH)
265267
: String(result.error),
266268
};
267269
}

packages/shared/src/lib/ai/chat/code-output-structure.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export const codeLLMSchema = z.object({
1616
export type CodeSchema = z.infer<typeof codeLLMSchema>;
1717

1818
export const unifiedCodeLLMSchema = z.object({
19-
type: z.enum(['code', 'reply']),
19+
type: z
20+
.enum(['code', 'reply'])
21+
.describe(
22+
'The type of the response. Always return "code" if you are generating code, and "reply" if you are answering the user question or asking for clarifications.',
23+
),
2024
code: z.string().optional().describe(codeDescription),
2125
packageJson: z.string().optional().describe(packageJsonDescription),
2226
textAnswer: z.string().describe(textAnswerDescription),

0 commit comments

Comments
 (0)