@codebam/cf-workers-telegram-bot 12.6.13 → 12.6.15

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.
Files changed (2) hide show
  1. package/dist/ai.js +17 -1
  2. package/package.json +1 -1
package/dist/ai.js CHANGED
@@ -66,6 +66,22 @@ input, config) {
66
66
  parameters: t.parameters,
67
67
  },
68
68
  }));
69
+ // Inject instructions if tools are provided
70
+ if (tools.length > 0) {
71
+ let systemMsg = messages.find((m) => m.role === 'system');
72
+ if (!systemMsg) {
73
+ systemMsg = { role: 'system', content: '' };
74
+ messages.unshift(systemMsg);
75
+ }
76
+ const toolInstructions = tools
77
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
+ .map((t) => {
79
+ return `- Name: ${t.name}\n Description: ${t.description}\n Parameters: ${JSON.stringify(t.parameters)}`;
80
+ })
81
+ .join('\n');
82
+ const promptInstruction = `\n\n[SYSTEM INSTRUCTION] You have access to the following tools:\n${toolInstructions}\n\nTo use a tool, you MUST output a tool call wrapped in XML format, like so:\n<tool_call>{"name": "search", "arguments": {"q": "query" }}</tool_call>\nor\n<tool_call>{"name": "fetch", "arguments": {"url": "https://example.com" }}</tool_call>\n\nMake sure the tool call is outputted EXACTLY as shown. The system will intercept this call, execute the tool, and return the output to you. Do not write code or direct the user to run code; call the tools yourself.`;
83
+ systemMsg.content = systemMsg.content + promptInstruction;
84
+ }
69
85
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
86
  const runModel = async (msgs, stream) => {
71
87
  if (isGemini) {
@@ -87,7 +103,7 @@ input, config) {
87
103
  }
88
104
  return await ai.run(model, { messages: msgs, tools: cfTools.length > 0 ? cfTools : undefined, stream });
89
105
  };
90
- if (cfTools.length === 0 || isGemini) {
106
+ if (cfTools.length === 0) {
91
107
  return await runModel(messages, config.streamFinalResponse);
92
108
  }
93
109
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebam/cf-workers-telegram-bot",
3
- "version": "12.6.13",
3
+ "version": "12.6.15",
4
4
  "description": "serverless telegram bot on cf workers",
5
5
  "main": "./dist/main.js",
6
6
  "module": "./dist/main.js",