MCPcopy
hub / github.com/mckaywrigley/ai-code-translator / createPrompt

Function createPrompt

utils/index.ts:8–72  ·  view source on GitHub ↗
(
  inputLanguage: string,
  outputLanguage: string,
  inputCode: string,
)

Source from the content-addressed store, hash-verified

6} from 'eventsource-parser';
7
8const createPrompt = (
9 inputLanguage: string,
10 outputLanguage: string,
11 inputCode: string,
12) => {
13 if (inputLanguage === 'Natural Language') {
14 return endent`
15 You are an expert programmer in all programming languages. Translate the natural language to "${outputLanguage}" code. Do not include \`\`\`.
16
17 Example translating from natural language to JavaScript:
18
19 Natural language:
20 Print the numbers 0 to 9.
21
22 JavaScript code:
23 for (let i = 0; i < 10; i++) {
24 console.log(i);
25 }
26
27 Natural language:
28 ${inputCode}
29
30 ${outputLanguage} code (no \`\`\`):
31 `;
32 } else if (outputLanguage === 'Natural Language') {
33 return endent`
34 You are an expert programmer in all programming languages. Translate the "${inputLanguage}" code to natural language in plain English that the average adult could understand. Respond as bullet points starting with -.
35
36 Example translating from JavaScript to natural language:
37
38 JavaScript code:
39 for (let i = 0; i < 10; i++) {
40 console.log(i);
41 }
42
43 Natural language:
44 Print the numbers 0 to 9.
45
46 ${inputLanguage} code:
47 ${inputCode}
48
49 Natural language:
50 `;
51 } else {
52 return endent`
53 You are an expert programmer in all programming languages. Translate the "${inputLanguage}" code to "${outputLanguage}" code. Do not include \`\`\`.
54
55 Example translating from JavaScript to Python:
56
57 JavaScript code:
58 for (let i = 0; i < 10; i++) {
59 console.log(i);
60 }
61
62 Python code:
63 for i in range(10):
64 print(i)
65

Callers 1

OpenAIStreamFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected