update readme
This commit is contained in:
parent
1ba81df52e
commit
956674e0ae
2 changed files with 43 additions and 16 deletions
|
|
@ -147,10 +147,19 @@ results = await client.search.query(
|
||||||
## Documents
|
## Documents
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Ingest a file
|
# Ingest a file (waits for completion by default)
|
||||||
result = await client.documents.ingest(file_path="./report.pdf")
|
result = await client.documents.ingest(file_path="./report.pdf")
|
||||||
print(f"Document ID: {result.document_id}")
|
print(f"Status: {result.status}")
|
||||||
print(f"Chunks: {result.chunks}")
|
print(f"Successful files: {result.successful_files}")
|
||||||
|
|
||||||
|
# Ingest without waiting (returns immediately with task_id)
|
||||||
|
result = await client.documents.ingest(file_path="./report.pdf", wait=False)
|
||||||
|
print(f"Task ID: {result.task_id}")
|
||||||
|
|
||||||
|
# Poll for completion manually
|
||||||
|
final_status = await client.documents.wait_for_task(result.task_id)
|
||||||
|
print(f"Status: {final_status.status}")
|
||||||
|
print(f"Successful files: {final_status.successful_files}")
|
||||||
|
|
||||||
# Ingest from file object
|
# Ingest from file object
|
||||||
with open("./report.pdf", "rb") as f:
|
with open("./report.pdf", "rb") as f:
|
||||||
|
|
@ -158,7 +167,7 @@ with open("./report.pdf", "rb") as f:
|
||||||
|
|
||||||
# Delete a document
|
# Delete a document
|
||||||
result = await client.documents.delete("report.pdf")
|
result = await client.documents.delete("report.pdf")
|
||||||
print(f"Deleted {result.deleted_chunks} chunks")
|
print(f"Success: {result.success}")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Settings
|
## Settings
|
||||||
|
|
|
||||||
|
|
@ -84,14 +84,14 @@ for await (const event of await client.chat.create({
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Streaming with `stream()` (Disposable pattern)
|
### Streaming with `stream()`
|
||||||
|
|
||||||
Provides additional helpers for convenience:
|
Provides additional helpers for convenience:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// Full event iteration with Disposable pattern
|
// Full event iteration
|
||||||
{
|
const stream = await client.chat.stream({ message: "Explain RAG" });
|
||||||
using stream = await client.chat.stream({ message: "Explain RAG" });
|
try {
|
||||||
for await (const event of stream) {
|
for await (const event of stream) {
|
||||||
if (event.type === "content") {
|
if (event.type === "content") {
|
||||||
process.stdout.write(event.delta);
|
process.stdout.write(event.delta);
|
||||||
|
|
@ -102,21 +102,27 @@ Provides additional helpers for convenience:
|
||||||
console.log(`\nChat ID: ${stream.chatId}`);
|
console.log(`\nChat ID: ${stream.chatId}`);
|
||||||
console.log(`Full text: ${stream.text}`);
|
console.log(`Full text: ${stream.text}`);
|
||||||
console.log(`Sources: ${stream.sources}`);
|
console.log(`Sources: ${stream.sources}`);
|
||||||
|
} finally {
|
||||||
|
stream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just text deltas
|
// Just text deltas
|
||||||
{
|
const stream = await client.chat.stream({ message: "Explain RAG" });
|
||||||
using stream = await client.chat.stream({ message: "Explain RAG" });
|
try {
|
||||||
for await (const text of stream.textStream) {
|
for await (const text of stream.textStream) {
|
||||||
process.stdout.write(text);
|
process.stdout.write(text);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
stream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get final text directly
|
// Get final text directly
|
||||||
{
|
const stream = await client.chat.stream({ message: "Explain RAG" });
|
||||||
using stream = await client.chat.stream({ message: "Explain RAG" });
|
try {
|
||||||
const text = await stream.finalText();
|
const text = await stream.finalText();
|
||||||
console.log(text);
|
console.log(text);
|
||||||
|
} finally {
|
||||||
|
stream.close();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -163,12 +169,24 @@ const results = await client.search.query("API documentation", {
|
||||||
## Documents
|
## Documents
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// Ingest a file (Node.js)
|
// Ingest a file (waits for completion by default)
|
||||||
const result = await client.documents.ingest({
|
const result = await client.documents.ingest({
|
||||||
filePath: "./report.pdf",
|
filePath: "./report.pdf",
|
||||||
});
|
});
|
||||||
console.log(`Document ID: ${result.document_id}`);
|
console.log(`Status: ${result.status}`);
|
||||||
console.log(`Chunks: ${result.chunks}`);
|
console.log(`Successful files: ${result.successful_files}`);
|
||||||
|
|
||||||
|
// Ingest without waiting (returns immediately with task_id)
|
||||||
|
const result = await client.documents.ingest({
|
||||||
|
filePath: "./report.pdf",
|
||||||
|
wait: false,
|
||||||
|
});
|
||||||
|
console.log(`Task ID: ${result.task_id}`);
|
||||||
|
|
||||||
|
// Poll for completion manually
|
||||||
|
const finalStatus = await client.documents.waitForTask(result.task_id);
|
||||||
|
console.log(`Status: ${finalStatus.status}`);
|
||||||
|
console.log(`Successful files: ${finalStatus.successful_files}`);
|
||||||
|
|
||||||
// Ingest from File object (browser)
|
// Ingest from File object (browser)
|
||||||
const file = new File([...], "report.pdf");
|
const file = new File([...], "report.pdf");
|
||||||
|
|
@ -179,7 +197,7 @@ const result = await client.documents.ingest({
|
||||||
|
|
||||||
// Delete a document
|
// Delete a document
|
||||||
const result = await client.documents.delete("report.pdf");
|
const result = await client.documents.delete("report.pdf");
|
||||||
console.log(`Deleted ${result.deleted_chunks} chunks`);
|
console.log(`Success: ${result.success}`);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Settings
|
## Settings
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue