Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions backend/ai_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ def __init__(self, api_key: str, model: str):
self.model = model

# Pre-build base API parameters
# Sonnet 5.5 rejects non-default temperature; "between_tools" is its lowest
# thinking setting (no extended thinking), closest to the previous behavior
self.base_params = {
"model": self.model,
"temperature": 0,
"max_tokens": 800
"max_tokens": 800,
"thinking": {"type": "between_tools"}
}

@staticmethod
def _extract_text(response) -> str:
"""Join text blocks; the response may also contain thinking blocks."""
return "".join(block.text for block in response.content if block.type == "text")

def generate_response(self, query: str,
conversation_history: Optional[str] = None,
Expand Down Expand Up @@ -84,7 +91,7 @@ def generate_response(self, query: str,
return self._handle_tool_execution(response, api_params, tool_manager)

# Return direct response
return response.content[0].text
return self._extract_text(response)

def _handle_tool_execution(self, initial_response, base_params: Dict[str, Any], tool_manager):
"""
Expand All @@ -101,8 +108,12 @@ def _handle_tool_execution(self, initial_response, base_params: Dict[str, Any],
# Start with existing messages
messages = base_params["messages"].copy()

# Add AI's tool use response
messages.append({"role": "assistant", "content": initial_response.content})
# Add AI's tool use response; thinking blocks are dropped because the final
# call omits tools, and replaying them after that change can be rejected
messages.append({
"role": "assistant",
"content": [block for block in initial_response.content if block.type != "thinking"]
})

# Execute all tool calls and collect results
tool_results = []
Expand Down Expand Up @@ -132,4 +143,4 @@ def _handle_tool_execution(self, initial_response, base_params: Dict[str, Any],

# Get final response
final_response = self.client.messages.create(**final_params)
return final_response.content[0].text
return self._extract_text(final_response)
2 changes: 1 addition & 1 deletion backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Config:
"""Configuration settings for the RAG system"""
# Anthropic API settings
ANTHROPIC_API_KEY: str = os.getenv("ANTHROPIC_API_KEY", "")
ANTHROPIC_MODEL: str = "claude-sonnet-4-20250514"
ANTHROPIC_MODEL: str = "claude-sonnet-5-5"

# Embedding model settings
EMBEDDING_MODEL: str = "all-MiniLM-L6-v2"
Expand Down