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:
sebseb7
2025-08-11 20:04:51 +02:00
parent 31b8b5c719
commit c61c088785

44
cli.js
View File

@@ -12,7 +12,7 @@ function renderUsage(usage) {
const inputTokens = usage.input_tokens - usage.input_tokens_details.cached_tokens;
const cacheTokens = usage.input_tokens_details.cached_tokens;
const outputToken = usage.output_tokens;
console.log('renderUsage', inputTokens, cacheTokens, outputToken);
console.log(' Cost', inputTokens, cacheTokens, outputToken);
}
function printIndented(indentNum, ...args) {
@@ -46,7 +46,7 @@ async function loadTools() {
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;
@@ -55,39 +55,23 @@ async function streamOnce(openai, userText) {
let previousResponseId;
let input = [
{ "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.
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 } ]},
{"role": "developer", "content": [ {"type": "input_text","text": `You are an interactive CLI AI assistant. Follow the user's instructions.` }] },
{"role": "user", "content": [ {"type": "input_text","text": userText } ]},
]
while(input.length > 0){
console.log('input:', input.length);
const call = {
model: 'gpt-5-mini',
input: input,
text: { format: { type: 'text' }, verbosity: 'low' },
text: { format: { type: 'text' }, verbosity: 'high' },
reasoning: { effort: 'low', summary: 'detailed' },
tools: Object.values(toolsByFile).map(t => t.def),
store: true,
}
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",call.input.map(i => JSON.stringify(i)),"\n",
'--------CALL-------------',"\n");
@@ -129,23 +113,21 @@ Behavior:
} catch (e){
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) });
}
});
stream.on('response.completed', async (event) => {
printIndented(10, 'response.completed',
renderUsage(event.response.usage),
"Result:",event.response.output.filter(i => i.type === 'message').map(i => i.content[0].text)
);
printIndented(10,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));
});
await Array.fromAsync(stream);
input=[];
for (const call of functionCalls) {
try {
//try {
const result = await call.promise;
input.push({
type: "function_call_output",
@@ -153,9 +135,9 @@ Behavior:
output: JSON.stringify(result),
})
printIndented(10,'function call result:',result);
} catch (err) {
console.error('Error in function call:', call.name, err);
}
//} catch (err) {
// console.error('Error in function call:', call.name, err);
//}
}
}