MCPcopy Index your code
hub / github.com/NousResearch/Open-Reasoning-Tasks / jsonToTaskString

Function jsonToTaskString

parser.js:61–114  ·  view source on GitHub ↗
(taskObject)

Source from the content-addressed store, hash-verified

59}
60
61function jsonToTaskString(taskObject) {
62 let taskString = '';
63
64 // Helper function to add a section if it exists
65 function addSection(title, content, formatter = (x) => x) {
66 if (content) {
67 taskString += `## ${title}:\n${formatter(content)}\n\n`;
68 }
69 }
70
71 // Add task name
72 taskString += `# ${taskObject.name}\n\n`;
73
74 // Add description
75 addSection('Description', taskObject.description);
76
77 // Add modality
78 addSection('Modality', taskObject.modality);
79
80 // Add diagram if it exists
81 addSection('Diagram (Optional)', taskObject.diagram);
82
83 // Add citations if they exist
84 if (taskObject.citations && taskObject.citations.length > 0) {
85 addSection('Citations (Optional)', taskObject.citations, (citations) =>
86 citations.map(citation => `- ${citation}`).join('\n')
87 );
88 }
89
90 // Add examples
91 if (taskObject.examples && taskObject.examples.length > 0) {
92 taskString += '## Examples:\n\n';
93 taskObject.examples.forEach((example, index) => {
94 taskString += `### Example ${index + 1}:\n\n`;
95 example.forEach(turn => {
96 taskString += `Input:\n\n\`\`\`\n${turn.input}\n\`\`\`\n\n`;
97 taskString += `Output:\n\n\`\`\`\n${turn.output}\n\`\`\`\n\n`;
98 });
99 // Add separator after each example except the last one
100 if (index < taskObject.examples.length - 1) {
101 taskString += '---\n\n';
102 }
103 });
104 }
105
106 // Add tags
107 if (taskObject.tags && taskObject.tags.length > 0) {
108 addSection('Tags', taskObject.tags, (tags) =>
109 tags.map(tag => `- ${tag}`).join('\n')
110 );
111 }
112
113 return taskString.trim();
114}
115
116export { parseTaskToJSON, jsonToTaskString };

Callers 2

generate-json.jsFile · 0.90

Calls 1

addSectionFunction · 0.85

Tested by

no test coverage detected