From da505170d4d0bc7cb4104a2f7bcf930ea862db55 Mon Sep 17 00:00:00 2001
From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
Date: Mon, 7 Oct 2024 18:37:06 -0400
Subject: [PATCH] Fixes
---
src/api/providers/openrouter.ts | 14 +++++++++--
src/core/Cline.ts | 7 ++++++
src/core/prompts/responses.ts | 42 +++++++++++++++++----------------
3 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/src/api/providers/openrouter.ts b/src/api/providers/openrouter.ts
index 1213e5d..e3f7587 100644
--- a/src/api/providers/openrouter.ts
+++ b/src/api/providers/openrouter.ts
@@ -107,6 +107,13 @@ export class OpenRouterHandler implements ApiHandler {
text: delta.content,
}
}
+ if (chunk.usage) {
+ yield {
+ type: "usage",
+ inputTokens: chunk.usage.prompt_tokens || 0,
+ outputTokens: chunk.usage.completion_tokens || 0,
+ }
+ }
}
try {
@@ -121,10 +128,13 @@ export class OpenRouterHandler implements ApiHandler {
console.log("OpenRouter generation details:", response.data)
yield {
type: "usage",
- inputTokens: generation?.native_tokens_prompt || 0,
- outputTokens: generation?.native_tokens_completion || 0,
// cacheWriteTokens: 0,
// cacheReadTokens: 0,
+ // openrouter generation endpoint fails often, so we'll report tokens from stream as normal
+ // inputTokens: generation?.native_tokens_prompt || 0,
+ // outputTokens: generation?.native_tokens_completion || 0,
+ inputTokens: 0,
+ outputTokens: 0,
totalCost: generation?.total_cost || 0,
}
} catch (error) {
diff --git a/src/core/Cline.ts b/src/core/Cline.ts
index 6a66dff..a14a896 100644
--- a/src/core/Cline.ts
+++ b/src/core/Cline.ts
@@ -973,6 +973,13 @@ export class Cline {
newContent = newContent.split("\n").slice(0, -1).join("\n").trim()
}
+ if (
+ this.api.getModel().id.includes("llama") &&
+ (newContent.includes(">") || newContent.includes("<"))
+ ) {
+ newContent = newContent.replace(/>/g, ">").replace(/</g, "<")
+ }
+
const sharedMessageProps: ClineSayTool = {
tool: fileExists ? "editedExistingFile" : "newFileCreated",
path: getReadablePath(cwd, removeClosingTag("path", relPath)),
diff --git a/src/core/prompts/responses.ts b/src/core/prompts/responses.ts
index ea61553..543a6f3 100644
--- a/src/core/prompts/responses.ts
+++ b/src/core/prompts/responses.ts
@@ -13,25 +13,7 @@ export const formatResponse = {
noToolsUsed: () =>
`[ERROR] You did not use a tool in your previous response! Please retry with a tool use.
-# Instructions for Tool Use
-
-Tool uses are formatted using XML-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. Here's the structure:
-
-
-value1
-value2
-...
-
-
-For example:
-
-
-
-I have completed the task...
-
-
-
-Always adhere to this format for all tool uses to ensure proper parsing and execution.
+${toolUseInstructionsReminder}
# Next Steps
@@ -44,7 +26,7 @@ Otherwise, if you have not completed the task and do not need additional informa
`You seem to be having trouble proceeding. The user has provided the following feedback to help guide you:\n\n${feedback}\n`,
missingToolParameterError: (paramName: string) =>
- `Missing value for required parameter '${paramName}'. Please retry with complete response.`,
+ `Missing value for required parameter '${paramName}'. Please retry with complete response.\n\n${toolUseInstructionsReminder}`,
toolResult: (
text: string,
@@ -126,3 +108,23 @@ const formatImagesIntoBlocks = (images?: string[]): Anthropic.ImageBlockParam[]
})
: []
}
+
+const toolUseInstructionsReminder = `# Reminder: Instructions for Tool Use
+
+Tool uses are formatted using XML-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. Here's the structure:
+
+
+value1
+value2
+...
+
+
+For example:
+
+
+
+I have completed the task...
+
+
+
+Always adhere to this format for all tool uses to ensure proper parsing and execution.`