import os
from datagrid_ai import Datagrid
client = Datagrid(api_key=os.environ.get("DATAGRID_API_KEY"))
# Step 1: Upload a file
with open("report.pdf", "rb") as file:
uploaded_file = client.files.create(file=file)
# Step 2: Include the file in a conversation
response = client.converse(
prompt=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "Summarize this document"},
{"type": "input_file", "file_id": uploaded_file.id}
]
}
]
)
print(response.content[0].text)
import Datagrid from 'datagrid-ai';
import fs from 'fs';
const client = new Datagrid({
apiKey: process.env['DATAGRID_API_KEY']
});
// Step 1: Upload a file
const uploadedFile = await client.files.create({
file: fs.createReadStream('report.pdf')
});
// Step 2: Include the file in a conversation
const response = await client.converse({
prompt: [
{
role: 'user',
content: [
{ type: 'input_text', text: 'Summarize this document' },
{ type: 'input_file', file_id: uploadedFile.id }
]
}
]
});
console.log(response.content[0].text);