gave chat web search ability, made 100vh when open
This commit is contained in:
parent
5c1e3fd17a
commit
e330dc6950
3 changed files with 27 additions and 8 deletions
|
|
@ -26,7 +26,8 @@ app.post('/api/claude', async (req, res) => {
|
|||
const requestBody = {
|
||||
model: model,
|
||||
max_tokens: maxTokens,
|
||||
messages: messages
|
||||
messages: messages,
|
||||
...(req.body.tools && { tools: req.body.tools })
|
||||
};
|
||||
|
||||
debugLog('Request body:', JSON.stringify(requestBody, null, 2));
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ function ChatInterface({ briefing, sourceData }) {
|
|||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: isExpanded ? '40vh' : '64px',
|
||||
height: isExpanded ? '100vh' : '64px',
|
||||
transition: 'height 0.3s ease',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import { condenseSourcesForClaude } from './sourceParser';
|
|||
* @param {Array} messages - Optional message history
|
||||
* @returns {Promise<string>} Claude's response
|
||||
*/
|
||||
async function callClaude(prompt, messages = []) {
|
||||
async function callClaude(prompt, messages = [], tools = null) {
|
||||
const apiKey = import.meta.env.REACT_APP_ANTHROPIC_API_KEY;
|
||||
|
||||
if (!apiKey || apiKey === 'sk-ant-your-key-here') {
|
||||
|
|
@ -35,7 +35,8 @@ async function callClaude(prompt, messages = []) {
|
|||
messages: [
|
||||
...messages,
|
||||
{ role: 'user', content: prompt }
|
||||
]
|
||||
],
|
||||
...(tools && { tools })
|
||||
};
|
||||
|
||||
debugLog('Sending request to proxy...');
|
||||
|
|
@ -60,11 +61,19 @@ async function callClaude(prompt, messages = []) {
|
|||
|
||||
const data = await response.json();
|
||||
debugLog('Response data structure:', Object.keys(data));
|
||||
debugLog('Response content:', data.content?.[0]?.text?.substring(0, 200) + '...');
|
||||
debugLog('Response content blocks:', data.content?.length);
|
||||
debugLog('Usage data:', data.usage);
|
||||
|
||||
// Find the text block — when web search is used there may be tool_use/tool_result
|
||||
// blocks before the final text block
|
||||
const textBlock = data.content?.find(block => block.type === 'text');
|
||||
if (!textBlock) {
|
||||
throw new Error('No text content in Claude response');
|
||||
}
|
||||
debugLog('Response text:', textBlock.text?.substring(0, 200) + '...');
|
||||
|
||||
return {
|
||||
text: data.content[0].text,
|
||||
text: textBlock.text,
|
||||
usage: data.usage // { input_tokens, output_tokens }
|
||||
};
|
||||
} catch (error) {
|
||||
|
|
@ -271,9 +280,18 @@ and other information displayed in their dashboard. Be conversational and helpfu
|
|||
|
||||
contextPrompt += `\n\nUser's message: ${message}`;
|
||||
|
||||
// Enable Anthropic's built-in web search tool so Claude can look things up
|
||||
const chatTools = [
|
||||
{
|
||||
type: 'web_search_20250305',
|
||||
name: 'web_search',
|
||||
max_uses: 5
|
||||
}
|
||||
];
|
||||
|
||||
try {
|
||||
const result = await callClaude(contextPrompt, messages);
|
||||
return result.text; // For chat, just return text for now
|
||||
const result = await callClaude(contextPrompt, messages, chatTools);
|
||||
return result.text;
|
||||
} catch (error) {
|
||||
console.error('Error in chat:', error);
|
||||
return `I apologize, but I encountered an error: ${error.message}. Please try again.`;
|
||||
|
|
|
|||
Loading…
Reference in a new issue