Refactor CLI tool to improve logging output and user prompts. Update verbosity settings for better response detail and enhance function call logging. Streamline input handling for improved clarity in AI interactions.
This commit is contained in:
44
cli.js
44
cli.js
@@ -12,7 +12,7 @@ function renderUsage(usage) {
|
|||||||
const inputTokens = usage.input_tokens - usage.input_tokens_details.cached_tokens;
|
const inputTokens = usage.input_tokens - usage.input_tokens_details.cached_tokens;
|
||||||
const cacheTokens = usage.input_tokens_details.cached_tokens;
|
const cacheTokens = usage.input_tokens_details.cached_tokens;
|
||||||
const outputToken = usage.output_tokens;
|
const outputToken = usage.output_tokens;
|
||||||
console.log('renderUsage', inputTokens, cacheTokens, outputToken);
|
console.log(' Cost', inputTokens, cacheTokens, outputToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
function printIndented(indentNum, ...args) {
|
function printIndented(indentNum, ...args) {
|
||||||
@@ -46,7 +46,7 @@ async function loadTools() {
|
|||||||
return Object.fromEntries(toolEntries);
|
return Object.fromEntries(toolEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
streamOnce(new OpenAI({ apiKey: process.env.OPENAI_API_KEY }), 'Zeig mir die Dateiein in / und lege index.html an mit dummydaten, kurz');
|
streamOnce(new OpenAI({ apiKey: process.env.OPENAI_API_KEY }), 'Erstelle eine React Project für eine Abovverwaltung. Mui, Sqllite, Express, Nodejs, KEIN Typescript, Aber ESM import. webpack, kein vite.');
|
||||||
|
|
||||||
|
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
@@ -55,39 +55,23 @@ async function streamOnce(openai, userText) {
|
|||||||
let previousResponseId;
|
let previousResponseId;
|
||||||
|
|
||||||
let input = [
|
let input = [
|
||||||
{ "role": "developer", "content": [ {"type": "input_text","text": `You are an interactive CLI AI assistant. Follow the user's instructions.
|
{"role": "developer", "content": [ {"type": "input_text","text": `You are an interactive CLI AI assistant. Follow the user's instructions.` }] },
|
||||||
If a tool is available and relevant, plan to use it.
|
{"role": "user", "content": [ {"type": "input_text","text": userText } ]},
|
||||||
Be explicit when information is undefined.
|
|
||||||
Do not silently fall back: surface errors.
|
|
||||||
|
|
||||||
Prefer concise answers.
|
|
||||||
|
|
||||||
Developer rules:
|
|
||||||
- Null tells the truth. If data is missing/undefined, say so; do not invent values.
|
|
||||||
- In development, never hide errors; include warnings if using fallbacks.
|
|
||||||
|
|
||||||
Behavior:
|
|
||||||
- Answer succinctly.
|
|
||||||
- Ask for clarification when the user input is ambiguous.
|
|
||||||
- Output plain text suitable for a terminal.
|
|
||||||
` }] },
|
|
||||||
{"role": "user", "content": [ { "type": "input_text", "text": userText } ]},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
while(input.length > 0){
|
while(input.length > 0){
|
||||||
console.log('input:', input.length);
|
|
||||||
|
|
||||||
const call = {
|
const call = {
|
||||||
model: 'gpt-5-mini',
|
model: 'gpt-5-mini',
|
||||||
input: input,
|
input: input,
|
||||||
text: { format: { type: 'text' }, verbosity: 'low' },
|
text: { format: { type: 'text' }, verbosity: 'high' },
|
||||||
reasoning: { effort: 'low', summary: 'detailed' },
|
reasoning: { effort: 'low', summary: 'detailed' },
|
||||||
tools: Object.values(toolsByFile).map(t => t.def),
|
tools: Object.values(toolsByFile).map(t => t.def),
|
||||||
store: true,
|
store: true,
|
||||||
}
|
}
|
||||||
if(previousResponseId) call.previous_response_id = previousResponseId;
|
if(previousResponseId) call.previous_response_id = previousResponseId;
|
||||||
|
|
||||||
console.log("------NEW OPENAI CALL--------------"
|
console.log("\n\n\n\n\n------NEW OPENAI CALL-"+input.length+"-------------"
|
||||||
,"\n",counter++,"\n",'----INPUT-----------------'
|
,"\n",counter++,"\n",'----INPUT-----------------'
|
||||||
,"\n",call.input.map(i => JSON.stringify(i)),"\n",
|
,"\n",call.input.map(i => JSON.stringify(i)),"\n",
|
||||||
'--------CALL-------------',"\n");
|
'--------CALL-------------',"\n");
|
||||||
@@ -129,23 +113,21 @@ Behavior:
|
|||||||
} catch (e){
|
} catch (e){
|
||||||
console.error('Error parsing arguments:', e, event.item.arguments);
|
console.error('Error parsing arguments:', e, event.item.arguments);
|
||||||
}
|
}
|
||||||
console.log('function call:', id, name);
|
console.log(' function call:', id, name);
|
||||||
functionCalls.push({ id, name, args, promise: toolsByFile[name].run(args) });
|
functionCalls.push({ id, name, args, promise: toolsByFile[name].run(args) });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.on('response.completed', async (event) => {
|
stream.on('response.completed', async (event) => {
|
||||||
printIndented(10, 'response.completed',
|
printIndented(10,renderUsage(event.response.usage));
|
||||||
renderUsage(event.response.usage),
|
if (event.response.output.filter(i => i.type === 'message').length > 0) printIndented(10, "Textresult:",event.response.output.filter(i => i.type === 'message').map(i => i.content[0].text));
|
||||||
"Result:",event.response.output.filter(i => i.type === 'message').map(i => i.content[0].text)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await Array.fromAsync(stream);
|
await Array.fromAsync(stream);
|
||||||
input=[];
|
input=[];
|
||||||
|
|
||||||
for (const call of functionCalls) {
|
for (const call of functionCalls) {
|
||||||
try {
|
//try {
|
||||||
const result = await call.promise;
|
const result = await call.promise;
|
||||||
input.push({
|
input.push({
|
||||||
type: "function_call_output",
|
type: "function_call_output",
|
||||||
@@ -153,9 +135,9 @@ Behavior:
|
|||||||
output: JSON.stringify(result),
|
output: JSON.stringify(result),
|
||||||
})
|
})
|
||||||
printIndented(10,'function call result:',result);
|
printIndented(10,'function call result:',result);
|
||||||
} catch (err) {
|
//} catch (err) {
|
||||||
console.error('Error in function call:', call.name, err);
|
// console.error('Error in function call:', call.name, err);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user