Invoke file ID
This commit is contained in:
@@ -72,7 +72,17 @@ export default async (req /*, context */) => {
|
|||||||
return new Response('Server is missing ANTHROPIC_API_KEY', { status: 500 })
|
return new Response('Server is missing ANTHROPIC_API_KEY', { status: 500 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY })
|
const client = new Anthropic({
|
||||||
|
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||||
|
// Required while the Files API is in beta.
|
||||||
|
defaultHeaders: { 'anthropic-beta': 'files-api-2025-04-14' },
|
||||||
|
})
|
||||||
|
|
||||||
|
// File uploaded to the Anthropic Console / Files API that the agent
|
||||||
|
// should consult on every call.
|
||||||
|
const KNOWLEDGE_FILE_ID =
|
||||||
|
process.env.ANTHROPIC_KNOWLEDGE_FILE_ID ||
|
||||||
|
'file_011Cawv1SPNaknuMmyDtM1S7'
|
||||||
|
|
||||||
const userMessage = `Here is a new public media station intake:
|
const userMessage = `Here is a new public media station intake:
|
||||||
|
|
||||||
@@ -93,7 +103,20 @@ Please draft the funding outlook brief described in your instructions.`
|
|||||||
model: MODEL,
|
model: MODEL,
|
||||||
max_tokens: 10000,
|
max_tokens: 10000,
|
||||||
system: SYSTEM_PROMPT,
|
system: SYSTEM_PROMPT,
|
||||||
messages: [{ role: 'user', content: userMessage }],
|
messages: [
|
||||||
|
{
|
||||||
|
role: 'user',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'document',
|
||||||
|
source: { type: 'file', file_id: KNOWLEDGE_FILE_ID },
|
||||||
|
// Lets the model cite the doc in answers.
|
||||||
|
citations: { enabled: true },
|
||||||
|
},
|
||||||
|
{ type: 'text', text: userMessage },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
if (AGENT_ID && AGENT_ID !== 'YOUR_AGENT_ID_HERE') {
|
if (AGENT_ID && AGENT_ID !== 'YOUR_AGENT_ID_HERE') {
|
||||||
streamArgs.agent_id = AGENT_ID
|
streamArgs.agent_id = AGENT_ID
|
||||||
|
|||||||
Reference in New Issue
Block a user