Several bugs fixed
This commit is contained in:
@@ -164,6 +164,13 @@ Don't narrate future actions ("Let me...") - just use the tools.
|
||||
// Otherwise, build the prompt: default + conditional sections + custom (if append mode)
|
||||
var prompt = defaultSystemPrompt
|
||||
|
||||
// Prepend model identity to prevent models trained on Claude data from misidentifying themselves.
|
||||
// Skip for direct Anthropic/OpenAI providers — those models know who they are.
|
||||
if let model = selectedModel,
|
||||
currentProvider != .anthropic && currentProvider != .openai {
|
||||
prompt = "You are \(model.name).\n\n" + prompt
|
||||
}
|
||||
|
||||
// Add tool-specific guidelines if MCP is enabled (tools are available)
|
||||
if mcpEnabled {
|
||||
prompt += toolUsageGuidelines
|
||||
@@ -435,6 +442,16 @@ Don't narrate future actions ("Let me...") - just use the tools.
|
||||
}
|
||||
|
||||
/// Infer which provider owns a given model ID based on naming conventions.
|
||||
/// Update the selected model and keep currentProvider + settings in sync.
|
||||
/// Call this whenever the user picks a model in the model selector.
|
||||
func selectModel(_ model: ModelInfo) {
|
||||
let newProvider = inferProvider(from: model.id) ?? currentProvider
|
||||
selectedModel = model
|
||||
currentProvider = newProvider
|
||||
settings.defaultModel = model.id
|
||||
settings.defaultProvider = newProvider
|
||||
}
|
||||
|
||||
private func inferProvider(from modelId: String) -> Settings.Provider? {
|
||||
// OpenRouter models always contain a "/" (e.g. "anthropic/claude-3-5-sonnet")
|
||||
if modelId.contains("/") { return .openrouter }
|
||||
@@ -1220,7 +1237,8 @@ Don't narrate future actions ("Let me...") - just use the tools.
|
||||
let startTime = Date()
|
||||
var wasCancelled = false
|
||||
do {
|
||||
let tools = mcp.getToolSchemas()
|
||||
// Include web_search tool when online mode is on (not needed for OpenRouter — it handles search via :online suffix)
|
||||
let tools = mcp.getToolSchemas(onlineMode: onlineMode && currentProvider != .openrouter)
|
||||
|
||||
// Apply :online suffix for OpenRouter when online mode is active
|
||||
var effectiveModelId = modelId
|
||||
@@ -1259,20 +1277,6 @@ Don't narrate future actions ("Let me...") - just use the tools.
|
||||
? messages.filter { $0.role != .system }
|
||||
: [messages.last(where: { $0.role == .user })].compactMap { $0 }
|
||||
|
||||
// Web search via our WebSearchService
|
||||
// Append results to last user message content (matching Python oAI approach)
|
||||
if onlineMode && currentProvider != .openrouter {
|
||||
if let lastUserIdx = messagesToSend.lastIndex(where: { $0.role == .user }) {
|
||||
Log.search.info("Running web search for tool-aware path (\(currentProvider.displayName))")
|
||||
let results = await WebSearchService.shared.search(query: messagesToSend[lastUserIdx].content)
|
||||
if !results.isEmpty {
|
||||
let searchContext = "\n\n\(WebSearchService.shared.formatResults(results))\n\nPlease use the above web search results to help answer the user's question."
|
||||
messagesToSend[lastUserIdx].content += searchContext
|
||||
Log.search.info("Injected \(results.count) search results into user message")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let systemPrompt: [String: Any] = [
|
||||
"role": "system",
|
||||
"content": systemContent
|
||||
|
||||
Reference in New Issue
Block a user