wuhp commited on
Commit
f1ab822
·
verified ·
1 Parent(s): 0dde195

Update services/geminiService.ts

Browse files
Files changed (1) hide show
  1. services/geminiService.ts +13 -2
services/geminiService.ts CHANGED
@@ -1,3 +1,4 @@
 
1
  import { GoogleGenAI } from "@google/genai";
2
  import { Node, Edge } from 'reactflow';
3
  import { NodeData, LayerType } from '../types';
@@ -44,8 +45,11 @@ const buildRawPrompt = (nodes: Node<NodeData>[], edges: Edge[]): string => {
44
  if (typeof v === 'object' && v !== null) {
45
  return `${k}=${JSON.stringify(v)}`;
46
  }
 
 
47
  return `${k}=${v}`;
48
  })
 
49
  .join(', ');
50
 
51
  rawSpec += `- [ID: ${node.id}] TYPE: ${node.data.type} | LABEL: ${node.data.label}\n`;
@@ -56,6 +60,12 @@ const buildRawPrompt = (nodes: Node<NodeData>[], edges: Edge[]): string => {
56
  // Specific instruction for Custom Layers
57
  if (node.data.type === LayerType.CUSTOM) {
58
  rawSpec += ` CUSTOM_NOTE: Instantiate using class '${node.data.params.class_name}' with args '${node.data.params.args}'.\n`;
 
 
 
 
 
 
59
  }
60
  });
61
 
@@ -100,8 +110,9 @@ export const generateRefinedPrompt = async (nodes: Node<NodeData>[], edges: Edge
100
  - Explicitly describe merge points (e.g. "Node X receives inputs from A and B. Handle this merge...").
101
  - Note specific handling for complex layers like CrossAttention (needs Query + Key/Value) or SAM Decoders.
102
  5. Create a section "Implementation Requirements" with standard PyTorch best practices (nn.Module, forward method, correct shapes).
103
- 6. Do NOT write the Python code yourself. Write the PROMPT that asks for the code.
104
- 7. Ensure the tone is technical and precise.
 
105
 
106
  Return ONLY the generated prompt text.
107
  `;
 
1
+
2
  import { GoogleGenAI } from "@google/genai";
3
  import { Node, Edge } from 'reactflow';
4
  import { NodeData, LayerType } from '../types';
 
45
  if (typeof v === 'object' && v !== null) {
46
  return `${k}=${JSON.stringify(v)}`;
47
  }
48
+ // Don't clutter standard output with huge code blocks, handle separately
49
+ if (k === 'definition_code' || k === 'imports') return null;
50
  return `${k}=${v}`;
51
  })
52
+ .filter(p => p !== null)
53
  .join(', ');
54
 
55
  rawSpec += `- [ID: ${node.id}] TYPE: ${node.data.type} | LABEL: ${node.data.label}\n`;
 
60
  // Specific instruction for Custom Layers
61
  if (node.data.type === LayerType.CUSTOM) {
62
  rawSpec += ` CUSTOM_NOTE: Instantiate using class '${node.data.params.class_name}' with args '${node.data.params.args}'.\n`;
63
+ if (node.data.params.imports) {
64
+ rawSpec += ` CUSTOM_IMPORTS: ${node.data.params.imports}\n`;
65
+ }
66
+ if (node.data.params.definition_code) {
67
+ rawSpec += ` CUSTOM_CODE_DEFINITION:\n${node.data.params.definition_code}\n`;
68
+ }
69
  }
70
  });
71
 
 
110
  - Explicitly describe merge points (e.g. "Node X receives inputs from A and B. Handle this merge...").
111
  - Note specific handling for complex layers like CrossAttention (needs Query + Key/Value) or SAM Decoders.
112
  5. Create a section "Implementation Requirements" with standard PyTorch best practices (nn.Module, forward method, correct shapes).
113
+ 6. If CUSTOM_CODE_DEFINITION or CUSTOM_IMPORTS are present, explicitly instruct the coder to include them verbatim or use them as reference.
114
+ 7. Do NOT write the Python code yourself. Write the PROMPT that asks for the code.
115
+ 8. Ensure the tone is technical and precise.
116
 
117
  Return ONLY the generated prompt text.
118
  `;