@banaxi/banana-code 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +2 -2
- package/src/providers/ollamaCloud.js +43 -14
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -67,7 +67,7 @@ async function handleSlashCommand(command) {
|
|
|
67
67
|
providerInstance = createProvider();
|
|
68
68
|
console.log(chalk.green(`Switched provider to ${newProv} (${config.model}).`));
|
|
69
69
|
} else {
|
|
70
|
-
console.log(chalk.yellow(`Usage: /provider <gemini|claude|openai|ollama_cloud|ollama>`));
|
|
70
|
+
console.log(chalk.yellow(`Usage: /provider <gemini|claude|openai|mistral|ollama_cloud|ollama>`));
|
|
71
71
|
}
|
|
72
72
|
break;
|
|
73
73
|
case '/model':
|
|
@@ -386,7 +386,7 @@ async function handleSlashCommand(command) {
|
|
|
386
386
|
case '/help':
|
|
387
387
|
console.log(chalk.yellow(`
|
|
388
388
|
Available commands:
|
|
389
|
-
/provider <name> - Switch AI provider (gemini, claude, openai, ollama_cloud, ollama)
|
|
389
|
+
/provider <name> - Switch AI provider (gemini, claude, openai, mistral, ollama_cloud, ollama)
|
|
390
390
|
/model [name] - Switch model within current provider (opens menu if name omitted)
|
|
391
391
|
/chats - List persistent chat sessions
|
|
392
392
|
/clear - Clear chat history
|
|
@@ -47,7 +47,7 @@ export class OllamaCloudProvider {
|
|
|
47
47
|
model: this.modelName,
|
|
48
48
|
messages: this.messages,
|
|
49
49
|
tools: this.tools.length > 0 ? this.tools : undefined,
|
|
50
|
-
stream:
|
|
50
|
+
stream: true
|
|
51
51
|
})
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -57,28 +57,57 @@ export class OllamaCloudProvider {
|
|
|
57
57
|
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
const
|
|
61
|
-
|
|
60
|
+
const reader = response.body.getReader();
|
|
61
|
+
const decoder = new TextDecoder();
|
|
62
|
+
let currentChunkResponse = '';
|
|
63
|
+
let lastMessageObj = null;
|
|
64
|
+
|
|
65
|
+
while (true) {
|
|
66
|
+
const { done, value } = await reader.read();
|
|
67
|
+
if (done) break;
|
|
68
|
+
|
|
69
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
70
|
+
const lines = chunk.split('\n').filter(l => l.trim() !== '');
|
|
71
|
+
|
|
72
|
+
for (const line of lines) {
|
|
73
|
+
try {
|
|
74
|
+
const data = JSON.parse(line);
|
|
75
|
+
if (data.message) {
|
|
76
|
+
lastMessageObj = data.message;
|
|
77
|
+
if (data.message.content) {
|
|
78
|
+
const content = data.message.content;
|
|
79
|
+
if (spinner.isSpinning && !this.config.useMarkedTerminal) spinner.stop();
|
|
80
|
+
if (!this.config.useMarkedTerminal) {
|
|
81
|
+
process.stdout.write(chalk.cyan(content));
|
|
82
|
+
}
|
|
83
|
+
currentChunkResponse += content;
|
|
84
|
+
finalResponse += content;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch (e) {
|
|
88
|
+
// Ignore partial JSON chunks
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
62
92
|
|
|
63
|
-
|
|
93
|
+
if (spinner.isSpinning) spinner.stop();
|
|
64
94
|
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
finalResponse += messageObj.content;
|
|
95
|
+
if (currentChunkResponse && this.config.useMarkedTerminal) {
|
|
96
|
+
printMarkdown(currentChunkResponse);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!lastMessageObj) {
|
|
100
|
+
throw new Error("Empty response from Ollama Cloud");
|
|
72
101
|
}
|
|
73
102
|
|
|
74
|
-
this.messages.push(
|
|
103
|
+
this.messages.push(lastMessageObj);
|
|
75
104
|
|
|
76
|
-
if (!
|
|
105
|
+
if (!lastMessageObj.tool_calls || lastMessageObj.tool_calls.length === 0) {
|
|
77
106
|
console.log();
|
|
78
107
|
break;
|
|
79
108
|
}
|
|
80
109
|
|
|
81
|
-
for (const call of
|
|
110
|
+
for (const call of lastMessageObj.tool_calls) {
|
|
82
111
|
const fn = call.function;
|
|
83
112
|
console.log(chalk.yellow(`\n[Banana Calling Tool: ${fn.name}]`));
|
|
84
113
|
|