Compare commits

..

6 Commits

Author SHA1 Message Date
github-actions[bot] 519254efbe chore: version packages (#999)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-11-04 14:18:27 -05:00
Adrian Lyjak 6ab56b79f3 fix version breaking (#998) 2025-11-04 14:14:38 -05:00
Adrian Lyjak e020e3e2b1 Remove organization id from classify (#997) 2025-11-04 14:05:19 -05:00
Adrian Lyjak f293547910 destructured keyword params for classify (#996) 2025-11-04 14:04:41 -05:00
github-actions[bot] 662bc37462 chore: version packages (#995) 2025-11-03 20:15:50 -06:00
Neeraj Pradhan 9f1ef4ef1f Bump to version 0.6.78 (#994) 2025-11-03 20:11:18 -06:00
25 changed files with 3606 additions and 185 deletions
+1 -1
View File
@@ -12,7 +12,7 @@
"@tanstack/react-router": "^1.133.22",
"@tanstack/react-router-devtools": "^1.133.22",
"@tanstack/react-start": "^1.133.22",
"llama-cloud-services": "^0.3.10",
"llama-cloud-services": "file:../../ts/llama_cloud_services",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"tailwind-merge": "^2.6.0",
@@ -15,7 +15,7 @@ export const Route = createFileRoute('/api/classify')({
const rawRes = await classifier.classify(
classificationRules,
parsingConfig,
[new Uint8Array(buff)],
{ fileContents: [new Uint8Array(buff)] },
)
const results = rawRes.items
let classification = ""
+1 -1
View File
@@ -19,7 +19,7 @@
"lint-staged": {
"ts/llama_cloud_services/src/**/*.{ts,tsx,js,jsx}": [
"pnpm --filter llama-cloud-services exec eslint --fix",
"pnpm --filter llama-cloud-services exec prettier --write"
"pnpm --filter llama-cloud-services exec prettier --write src/ tests/"
]
},
"packageManager": "pnpm@10.11.1+sha512.e519b9f7639869dc8d5c3c5dfef73b3f091094b0a006d7317353c72b124e80e1afd429732e28705ad6bfa1ee879c1fce46c128ccebd3192101f43dd67c667912"
+3368 -19
View File
File diff suppressed because it is too large Load Diff
+12
View File
@@ -1,5 +1,17 @@
# llama-cloud-services-py
## 0.6.79
### Patch Changes
- e020e3e: Remove unneeded organization_id param from beta classifier client
## 0.6.78
### Patch Changes
- 9f1ef4e: Fix extract
## 0.6.77
### Patch Changes
@@ -39,7 +39,6 @@ class ClassifyClient:
Args:
client: The LlamaCloud client to use.
project_id: The project ID to use.
organization_id: The organization ID to use.
polling_interval: The interval to poll for job completion in seconds.
polling_timeout: The timeout for the job to complete in seconds.
"""
@@ -48,15 +47,13 @@ class ClassifyClient:
self,
client: AsyncLlamaCloud,
project_id: Optional[str] = None,
organization_id: Optional[str] = None,
polling_interval: float = 1.0,
polling_timeout: float = POLLING_TIMEOUT_SECONDS,
):
self.client = client
self.project_id = project_id
self.organization_id = organization_id
self.polling_interval = polling_interval
self.file_client = FileClient(client, project_id, organization_id)
self.file_client = FileClient(client, project_id)
self.polling_timeout = polling_timeout
@classmethod
@@ -64,7 +61,6 @@ class ClassifyClient:
cls,
api_key: str,
project_id: Optional[str] = None,
organization_id: Optional[str] = None,
base_url: Optional[str] = None,
) -> "ClassifyClient":
"""
@@ -74,7 +70,6 @@ class ClassifyClient:
return cls(
client,
project_id,
organization_id,
)
async def acreate_classify_job(
@@ -101,7 +96,6 @@ class ClassifyClient:
file_ids=file_ids,
parsing_configuration=parsing_configuration or OMIT,
project_id=self.project_id,
organization_id=self.organization_id,
)
def create_classify_job(
@@ -152,7 +146,6 @@ class ClassifyClient:
results = await self.client.classifier.get_classification_job_results(
classify_job_with_status.id,
project_id=self.project_id,
organization_id=self.organization_id,
)
return results
@@ -359,7 +352,7 @@ class ClassifyClient:
The classify job with status.
"""
job = await self.client.classifier.get_classify_job(
job_id, project_id=self.project_id, organization_id=self.organization_id
job_id, project_id=self.project_id
)
start_time = time.time()
while not is_terminal_status(job.status):
@@ -370,6 +363,6 @@ class ClassifyClient:
)
await asyncio.sleep(self.polling_interval)
job = await self.client.classifier.get_classify_job(
job_id, project_id=self.project_id, organization_id=self.organization_id
job_id, project_id=self.project_id
)
return job
+6 -6
View File
@@ -333,7 +333,7 @@ class LlamaCloudIndex(BaseManagedIndex):
if file_ids:
self._wait_for_resources(
file_ids,
lambda fid: self._client.pipelines.get_pipeline_file_status(
lambda fid: self._client.pipeline_files.get_pipeline_file_status(
pipeline_id=self.pipeline.id, file_id=fid
),
resource_name="file",
@@ -420,7 +420,7 @@ class LlamaCloudIndex(BaseManagedIndex):
if file_ids:
await self._await_for_resources(
file_ids,
lambda fid: self._aclient.pipelines.get_pipeline_file_status(
lambda fid: self._aclient.pipeline_files.get_pipeline_file_status(
pipeline_id=self.pipeline.id, file_id=fid
),
resource_name="file",
@@ -919,7 +919,7 @@ class LlamaCloudIndex(BaseManagedIndex):
# Add file to pipeline
pipeline_file_create = PipelineFileCreate(file_id=file.id)
self._client.pipelines.add_files_to_pipeline_api(
self._client.pipeline_files.add_files_to_pipeline_api(
pipeline_id=self.pipeline.id, request=[pipeline_file_create]
)
@@ -946,7 +946,7 @@ class LlamaCloudIndex(BaseManagedIndex):
# Add file to pipeline
pipeline_file_create = PipelineFileCreate(file_id=file.id)
await self._aclient.pipelines.add_files_to_pipeline_api(
await self._aclient.pipeline_files.add_files_to_pipeline_api(
pipeline_id=self.pipeline.id, request=[pipeline_file_create]
)
@@ -984,7 +984,7 @@ class LlamaCloudIndex(BaseManagedIndex):
# Add file to pipeline
pipeline_file_create = PipelineFileCreate(file_id=file.id)
self._client.pipelines.add_files_to_pipeline_api(
self._client.pipeline_files.add_files_to_pipeline_api(
pipeline_id=self.pipeline.id, request=[pipeline_file_create]
)
@@ -1021,7 +1021,7 @@ class LlamaCloudIndex(BaseManagedIndex):
# Add file to pipeline
pipeline_file_create = PipelineFileCreate(file_id=file.id)
await self._aclient.pipelines.add_files_to_pipeline_api(
await self._aclient.pipeline_files.add_files_to_pipeline_api(
pipeline_id=self.pipeline.id, request=[pipeline_file_create]
)
+15
View File
@@ -1,5 +1,20 @@
# llama_parse
## 0.6.79
### Patch Changes
- Updated dependencies [e020e3e]
- llama-cloud-services-py@0.6.79
## 0.6.78
### Patch Changes
- 9f1ef4e: Fix extract
- Updated dependencies [9f1ef4e]
- llama-cloud-services-py@0.6.78
## 0.6.77
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "llama_parse",
"version": "0.6.77",
"version": "0.6.79",
"description": "",
"main": "index.js",
"private": false,
+2 -2
View File
@@ -11,13 +11,13 @@ dev = [
[project]
name = "llama-parse"
version = "0.6.77"
version = "0.6.79"
description = "Parse files into RAG-Optimized formats."
authors = [{name = "Logan Markewich", email = "logan@llamaindex.ai"}]
requires-python = ">=3.9,<4.0"
readme = "README.md"
license = "MIT"
dependencies = ["llama-cloud-services>=0.6.77"]
dependencies = ["llama-cloud-services>=0.6.79"]
[project.scripts]
llama-parse = "llama_parse.cli.main:parse"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "llama-cloud-services-py",
"version": "0.6.77",
"version": "0.6.79",
"private": false,
"license": "MIT",
"scripts": {},
+2 -2
View File
@@ -19,7 +19,7 @@ dev = [
[project]
name = "llama-cloud-services"
version = "0.6.77"
version = "0.6.79"
description = "Tailored SDK clients for LlamaCloud services."
authors = [{name = "Logan Markewich", email = "logan@runllama.ai"}]
requires-python = ">=3.9,<4.0"
@@ -27,7 +27,7 @@ readme = "README.md"
license = "MIT"
dependencies = [
"llama-index-core>=0.12.0",
"llama-cloud==0.1.43",
"llama-cloud==0.1.44",
"pydantic>=2.8,!=2.10",
"click>=8.1.7,<9",
"python-dotenv>=1.0.1,<2",
-3
View File
@@ -44,7 +44,6 @@ def classify_client(
return ClassifyClient(
async_llama_cloud_client,
project_id=project.id,
organization_id=project.organization_id,
polling_interval=1,
)
@@ -56,7 +55,6 @@ def file_client(
return FileClient(
async_llama_cloud_client,
project_id=project.id,
organization_id=project.organization_id,
use_presigned_url=False,
)
@@ -148,7 +146,6 @@ async def test_classify_file_ids_from_api_key(
api_key=e2e_test_settings.LLAMA_CLOUD_API_KEY.get_secret_value(),
base_url=e2e_test_settings.LLAMA_CLOUD_BASE_URL,
project_id=pdf_file.project_id,
organization_id=e2e_test_settings.LLAMA_CLOUD_ORGANIZATION_ID,
)
# Classify the uploaded files
+2
View File
@@ -58,6 +58,8 @@ def get_test_cases():
settings = [
ExtractConfig(extraction_mode=ExtractMode.FAST),
ExtractConfig(extraction_mode=ExtractMode.BALANCED),
ExtractConfig(extraction_mode=ExtractMode.MULTIMODAL),
ExtractConfig(extraction_mode=ExtractMode.PREMIUM),
]
for input_file in sorted(input_files):
+2 -2
View File
@@ -44,7 +44,7 @@ def index_name() -> Generator[str, None, None]:
client = LlamaCloud(token=api_key, base_url=base_url)
pipeline = client.pipelines.search_pipelines(project_name=name)
if pipeline:
client.pipelines.delete(pipeline_id=pipeline[0].id)
client.pipelines.delete_pipeline(pipeline_id=pipeline[0].id)
@pytest.fixture()
@@ -83,7 +83,7 @@ def _setup_index_with_file(
# add file to pipeline
pipeline_file_create = PipelineFileCreate(file_id=file.id)
client.pipelines.add_files_to_pipeline_api(
client.pipeline_files.add_files_to_pipeline_api(
pipeline_id=pipeline.id, request=[pipeline_file_create]
)
@@ -2,6 +2,7 @@ from datetime import datetime
import json
from pathlib import Path
from typing import Any, Dict, Optional
import uuid
import pytest
from llama_cloud import ExtractRun, File
@@ -434,6 +435,7 @@ def create_extract_run(
"extraction_agent_id": "extraction-agent-123",
"config": {},
"status": "SUCCESS",
"project_id": str(uuid.uuid4()),
"from_ui": False,
}
)
+1
View File
@@ -112,5 +112,6 @@
"num_output_tokens": 3440
}
},
"project_id": "77bdc79f-fb69-49ae-a783-fcc573eec7ce",
"from_ui": false
}
Generated
+6 -6
View File
@@ -1,5 +1,5 @@
version = 1
revision = 2
revision = 3
requires-python = ">=3.9, <4.0"
resolution-markers = [
"python_full_version >= '3.14'",
@@ -1582,21 +1582,21 @@ wheels = [
[[package]]
name = "llama-cloud"
version = "0.1.43"
version = "0.1.44"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "certifi" },
{ name = "httpx" },
{ name = "pydantic" },
]
sdist = { url = "https://files.pythonhosted.org/packages/9b/33/33a8bd3a617c071caf450ca2627969f8b28272d0692f122997c10a32247e/llama_cloud-0.1.43.tar.gz", hash = "sha256:00429f05aea515449d90cde91ef3ed3687fcd93e46f6246d08cbea02f9b397a9", size = 112992, upload-time = "2025-10-02T21:55:38.355Z" }
sdist = { url = "https://files.pythonhosted.org/packages/54/eb/16e31fb0fc4df91b08fa19cc3f28ac6e3c7d4df0bcbb71dd2bf596e9586f/llama_cloud-0.1.44.tar.gz", hash = "sha256:276a2b4f94463da037431ca3063331b3b6be398bbfb003113ee76b7c2a873b53", size = 120502, upload-time = "2025-11-04T00:51:58.578Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/2b/54/559a67542396d5660a71115b29e0160e9dd784e570e1f4ef55ad22bf5b39/llama_cloud-0.1.43-py3-none-any.whl", hash = "sha256:540605d4dd13c6536a3b75cd4d04b211f29b16d17faee9381e3793a651f1dec1", size = 311460, upload-time = "2025-10-02T21:55:37.282Z" },
{ url = "https://files.pythonhosted.org/packages/69/0a/fabe54c21d5927d626550cb9560a20e51e42468355f5f0fb300f84806e28/llama_cloud-0.1.44-py3-none-any.whl", hash = "sha256:dfdcc4932353711fc8639f14261cbb54a88139b7790ebdd3ed4fde29bbbc0b88", size = 332779, upload-time = "2025-11-04T00:51:57.371Z" },
]
[[package]]
name = "llama-cloud-services"
version = "0.6.76"
version = "0.6.77"
source = { editable = "." }
dependencies = [
{ name = "click", version = "8.1.8", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
@@ -1631,7 +1631,7 @@ dev = [
requires-dist = [
{ name = "click", specifier = ">=8.1.7,<9" },
{ name = "eval-type-backport", marker = "python_full_version < '3.10'", specifier = ">=0.2.0,<0.3" },
{ name = "llama-cloud", specifier = "==0.1.43" },
{ name = "llama-cloud", specifier = "==0.1.44" },
{ name = "llama-index-core", specifier = ">=0.12.0" },
{ name = "packaging", specifier = ">=23.0" },
{ name = "platformdirs", specifier = ">=4.3.7,<5" },
+6
View File
@@ -1,5 +1,11 @@
# llama-cloud-services
## 0.4.0
### Minor Changes
- f293547: Switch to keyword arguments rather than positional args
## 0.3.10
### Patch Changes
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "llama-cloud-services",
"version": "0.3.10",
"version": "0.4.0",
"type": "module",
"license": "MIT",
"scripts": {
@@ -9,8 +9,8 @@
"build": "pnpm run generate && bunchee",
"dev": "bunchee --watch",
"lint": "eslint src/ --ignore-pattern client/*.ts --no-warn-ignored",
"format": "prettier --write ./src/",
"format:check": "prettier --check ./src/",
"format": "prettier --write ./src/ tests/",
"format:check": "prettier --check ./src/ tests/",
"test": "vitest run --testTimeout=60000",
"test:watch": "vitest --watch",
"test:ui": "vitest --ui",
+27 -21
View File
@@ -36,34 +36,40 @@ export class LlamaClassify {
async classify(
rules: ClassifierRule[],
parsingConfiguration: ClassifyParsingConfiguration,
fileContents:
| Buffer<ArrayBufferLike>[]
| File[]
| Uint8Array<ArrayBuffer>[]
| string[]
| undefined = undefined,
filePaths: string[] | undefined = undefined,
projectId: string | null = null,
organizationId: string | null = null,
pollingInterval: number = 1,
maxPollingIterations: number = 1800,
maxRetriesOnError: number = 10,
retryInterval: number = 0.5,
): Promise<ClassifyJobResults> {
const result = await classify(
rules,
parsingConfiguration,
configuration: ClassifyParsingConfiguration,
{
fileContents,
filePaths,
projectId,
organizationId,
this.client,
pollingInterval = 1,
maxPollingIterations = 1800,
maxRetriesOnError = 10,
retryInterval = 0.5,
}: {
fileContents?:
| Buffer<ArrayBufferLike>[]
| File[]
| Uint8Array<ArrayBuffer>[]
| string[]
| undefined;
filePaths?: string[] | undefined;
projectId?: string;
pollingInterval?: number;
maxPollingIterations?: number;
maxRetriesOnError?: number;
retryInterval?: number;
},
): Promise<ClassifyJobResults> {
const result = await classify(rules, configuration, {
fileContents,
filePaths,
projectId: projectId ?? undefined,
client: this.client,
pollingInterval,
maxPollingIterations,
maxRetriesOnError,
retryInterval,
);
});
return result;
}
}
+87 -69
View File
@@ -19,16 +19,23 @@ import { sleep } from "./utils";
import { uploadFile } from "./fileUpload";
import { File } from "buffer";
async function createClassifyJob(
fileIds: string[],
rules: ClassifierRule[],
parsingConfiguration: ClassifyParsingConfiguration,
organizationId: null | string,
projectId: null | string,
client: Client | undefined,
maxRetriesOnError: number = 10,
retryInterval: number = 0.5,
): Promise<string> {
async function createClassifyJob({
fileIds,
rules,
parsingConfiguration,
projectId,
client,
maxRetriesOnError = 10,
retryInterval = 0.5,
}: {
fileIds: string[];
rules: ClassifierRule[];
parsingConfiguration: ClassifyParsingConfiguration;
projectId?: string | undefined;
client?: Client | undefined;
maxRetriesOnError?: number;
retryInterval?: number;
}): Promise<string> {
const rawData = {
file_ids: fileIds,
rules: rules,
@@ -38,7 +45,6 @@ async function createClassifyJob(
body: rawData,
query: {
project_id: projectId,
organization_id: organizationId,
},
} as CreateClassifyJobApiV1ClassifierJobsPostData;
const options = data as Options<CreateClassifyJobApiV1ClassifierJobsPostData>;
@@ -75,12 +81,17 @@ async function createClassifyJob(
}
}
async function pollForJobCompletion(
jobId: string,
interval: number = 1,
maxIterations: number = 1800,
client: Client | undefined = undefined,
): Promise<boolean> {
async function pollForJobCompletion({
jobId,
interval = 1,
maxIterations = 1800,
client,
}: {
jobId: string;
interval?: number;
maxIterations?: number;
client?: Client | undefined;
}): Promise<boolean> {
let status: StatusEnum | undefined = undefined;
const jobData = {
path: { classify_job_id: jobId },
@@ -114,17 +125,22 @@ async function pollForJobCompletion(
}
}
async function getJobResult(
jobId: string,
client: Client | undefined = undefined,
projectId: string | null = null,
organizationId: string | null = null,
maxRetriesOnError: number = 10,
retryInterval: number = 0.5,
): Promise<ClassifyJobResults> {
async function getJobResult({
jobId,
client,
projectId,
maxRetriesOnError = 10,
retryInterval = 0.5,
}: {
jobId: string;
client?: Client | undefined;
projectId?: string | undefined;
maxRetriesOnError?: number;
retryInterval?: number;
}): Promise<ClassifyJobResults> {
const jobData = {
path: { classify_job_id: jobId },
query: { organization_id: organizationId, project_id: projectId },
query: { project_id: projectId },
} as GetClassificationJobResultsApiV1ClassifierJobsClassifyJobIdResultsGetData;
const jobOptions =
jobData as Options<GetClassificationJobResultsApiV1ClassifierJobsClassifyJobIdResultsGetData>;
@@ -166,20 +182,30 @@ async function getJobResult(
export async function classify(
rules: ClassifierRule[],
parsingConfiguration: ClassifyParsingConfiguration,
fileContents:
| Buffer<ArrayBufferLike>[]
| File[]
| Uint8Array<ArrayBuffer>[]
| string[]
| undefined = undefined,
filePaths: string[] | undefined = undefined,
projectId: string | null = null,
organizationId: string | null = null,
client: Client | undefined = undefined,
pollingInterval: number = 1,
maxPollingIterations: number = 1800,
maxRetriesOnError: number = 10,
retryInterval: number = 0.5,
{
fileContents,
filePaths,
projectId,
client,
pollingInterval = 1,
maxPollingIterations = 1800,
maxRetriesOnError = 10,
retryInterval = 0.5,
}: {
fileContents?:
| Buffer<ArrayBufferLike>[]
| File[]
| Uint8Array<ArrayBuffer>[]
| string[]
| undefined;
filePaths?: string[] | undefined;
projectId?: string | undefined;
client?: Client | undefined;
pollingInterval?: number;
maxPollingIterations?: number;
maxRetriesOnError?: number;
retryInterval?: number;
},
): Promise<ClassifyJobResults> {
const fileIds: string[] = [];
if (!filePaths && !fileContents) {
@@ -191,16 +217,13 @@ export async function classify(
if (filePaths) {
const uploadPromises = filePaths.map(async (name) => {
try {
const fileId = await uploadFile(
name,
undefined,
undefined,
projectId,
organizationId,
client,
const fileId = await uploadFile({
filePath: name,
maxRetriesOnError,
retryInterval,
);
retryInterval: retryInterval,
project_id: projectId,
client: client,
});
if (fileId) {
return fileId;
} else {
@@ -220,16 +243,13 @@ export async function classify(
if (fileContents) {
const uploadPromises = fileContents.map(async (content) => {
try {
const fileId = await uploadFile(
undefined,
content,
undefined,
projectId,
organizationId,
client,
const fileId = await uploadFile({
fileContent: content,
...(projectId ? { project_id: projectId } : {}),
...(client ? { client: client } : {}),
maxRetriesOnError,
retryInterval,
);
});
if (fileId) {
return fileId;
} else {
@@ -252,33 +272,31 @@ export async function classify(
);
}
const jobId = await createClassifyJob(
const jobId = await createClassifyJob({
fileIds,
rules,
parsingConfiguration,
organizationId,
projectId,
client,
...(projectId ? { projectId: projectId } : {}),
...(client ? { client: client } : {}),
maxRetriesOnError,
retryInterval,
);
const success = await pollForJobCompletion(
});
const success = await pollForJobCompletion({
jobId,
pollingInterval,
maxPollingIterations,
interval: pollingInterval,
maxIterations: maxPollingIterations,
client,
);
});
if (!success) {
throw new Error("Your job is taking longer than 10 minutes, timing out...");
} else {
return (await getJobResult(
return (await getJobResult({
jobId,
client,
projectId,
organizationId,
maxRetriesOnError,
retryInterval,
)) as ClassifyJobResults;
})) as ClassifyJobResults;
}
}
+8 -8
View File
@@ -378,16 +378,16 @@ export async function extract(
maxRetriesOnError: number = 10,
retryInterval: number = 0.5,
): Promise<ExtractResult | undefined> {
const fileId = (await uploadFile(
const fileId = (await uploadFile({
filePath,
fileContent,
fileName,
project_id,
organization_id,
project_id: project_id ?? undefined,
organization_id: organization_id ?? undefined,
client,
maxRetriesOnError,
retryInterval,
)) as string;
})) as string;
const extractJobCreate = {
extraction_agent_id: agentId,
file_id: fileId,
@@ -457,16 +457,16 @@ export async function extractStateless(
maxRetriesOnError: number = 10,
retryInterval: number = 0.5,
): Promise<ExtractResult | undefined> {
const fileId = (await uploadFile(
const fileId = (await uploadFile({
filePath,
fileContent,
fileName,
project_id,
organization_id,
project_id: project_id ?? undefined,
organization_id: organization_id ?? undefined,
client,
maxRetriesOnError,
retryInterval,
)) as string;
})) as string;
const extractStatetelessCreate = {
data_schema: dataSchema,
file_id: fileId,
+23 -12
View File
@@ -23,21 +23,30 @@ function textToFile(text: string, fileName: string | null = null) {
);
}
export async function uploadFile(
filePath: string | undefined = undefined,
fileContent:
export async function uploadFile({
filePath,
fileContent,
fileName,
project_id,
organization_id,
client,
maxRetriesOnError = 10,
retryInterval = 0.5,
}: {
filePath?: string | undefined;
fileContent?:
| Buffer<ArrayBufferLike>
| File
| Uint8Array<ArrayBuffer>
| string
| undefined = undefined,
fileName: string | undefined = undefined,
project_id: string | null = null,
organization_id: string | null = null,
client: Client | undefined = undefined,
maxRetriesOnError: number = 10,
retryInterval: number = 0.5,
): Promise<string | undefined> {
| undefined;
fileName?: string | undefined;
project_id?: string | undefined;
organization_id?: string | undefined;
client?: Client | undefined;
maxRetriesOnError?: number;
retryInterval?: number;
}): Promise<string | undefined> {
let file: File | undefined = undefined;
if (typeof filePath === "undefined" && typeof fileContent === "undefined") {
throw new Error(
@@ -79,7 +88,7 @@ export async function uploadFile(
} as BodyUploadFileApiV1FilesPost;
const uploadData = {
body: fileToUpload,
query: { organization_id: organization_id, project_id: project_id },
query: { project_id: project_id, organization_id: organization_id },
} as UploadFileApiV1FilesPostData;
const uploadOptions = uploadData as Options<UploadFileApiV1FilesPostData>;
if (typeof client != "undefined") {
@@ -95,6 +104,8 @@ export async function uploadFile(
const uploadResponse = await uploadFileApiV1FilesPost(uploadOptions);
let fileId: string | undefined = undefined;
if (!uploadResponse.response.ok) {
const error = await uploadResponse.response.text();
console.error("Error while uploading file: ", error);
retries++;
await sleep(retryInterval * 1000);
}
@@ -3,7 +3,10 @@ import { LlamaParseReader } from "../src/reader.js";
import { LlamaCloudIndex } from "../src/LlamaCloudIndex.js";
import { LlamaExtract, LlamaExtractAgent } from "../src/LlamaExtract.js";
import { LlamaClassify } from "../src/LlamaClassify.js";
import { ClassifierRule, ClassifyParsingConfiguration } from "../src/classify.js";
import {
ClassifierRule,
ClassifyParsingConfiguration,
} from "../src/classify.js";
import { Document } from "@llamaindex/core/schema";
import { fs } from "@llamaindex/env";
import { ExtractConfig } from "../src/api.js";
@@ -499,25 +502,29 @@ describe("Integration Tests", () => {
process.env.LLAMA_CLOUD_API_KEY!,
"https://api.cloud.llamaindex.ai",
);
const testContent =
`A Fox one day spied a beautiful bunch of ripe grapes hanging from a vine trained along the branches of a tree. The grapes seemed ready to burst with juice, and the Fox's mouth watered as he gazed longingly at them. The bunch hung from a high branch, and the Fox had to jump for it. The first time he jumped he missed it by a long way. So he walked off a short distance and took a running leap at it, only to fall short once more. Again and again he tried, but in vain. Now he sat down and looked at the grapes in disgust. "What a fool I am," he said. "Here I am wearing myself out to get a bunch of sour grapes that are not worth gaping for." And off he walked very, very scornfully.There are many who pretend to despise and belittle that which is beyond their reach.`;
const testContent = `A Fox one day spied a beautiful bunch of ripe grapes hanging from a vine trained along the branches of a tree. The grapes seemed ready to burst with juice, and the Fox's mouth watered as he gazed longingly at them. The bunch hung from a high branch, and the Fox had to jump for it. The first time he jumped he missed it by a long way. So he walked off a short distance and took a running leap at it, only to fall short once more. Again and again he tried, but in vain. Now he sat down and looked at the grapes in disgust. "What a fool I am," he said. "Here I am wearing myself out to get a bunch of sour grapes that are not worth gaping for." And off he walked very, very scornfully.There are many who pretend to despise and belittle that which is beyond their reach.`;
const testFilePath = "the_fox_and_the_grapes.md";
await fs.writeFile(testFilePath, new TextEncoder().encode(testContent));
const rules: ClassifierRule[] = [
{type: "fable", description: "A short story featuring animals whose aim is to teach the reader a lesson (the moral of the story)"},
{type: "fairy_tale", description: "A mid-to-long story featuring humans, magic creatures and other characters, whose main aim is to entertain the readers."}
]
{
type: "fable",
description:
"A short story featuring animals whose aim is to teach the reader a lesson (the moral of the story)",
},
{
type: "fairy_tale",
description:
"A mid-to-long story featuring humans, magic creatures and other characters, whose main aim is to entertain the readers.",
},
];
const parsingConfig: ClassifyParsingConfiguration = {lang: "en"}
const parsingConfig: ClassifyParsingConfiguration = { lang: "en" };
const result = await classifyClient.classify(
rules,
parsingConfig,
undefined,
["the_fox_and_the_grapes.md"]
);
const result = await classifyClient.classify(rules, parsingConfig, {
filePaths: ["the_fox_and_the_grapes.md"],
});
expect("items" in result).toBeTruthy();
expect(result.items.length).toBeGreaterThan(0);
expect("result" in result.items[0]).toBeTruthy();
@@ -527,7 +534,7 @@ describe("Integration Tests", () => {
const resultBuffer = await classifyClient.classify(
rules,
parsingConfig,
[buffer],
{ fileContents: [buffer] },
);
expect("items" in resultBuffer).toBeTruthy();
expect(resultBuffer.items.length).toBeGreaterThan(0);
@@ -535,9 +542,11 @@ describe("Integration Tests", () => {
expect(resultBuffer.items[0].result!.type === "fable").toBeTruthy();
try {
await fs.unlink("the_fox_and_the_grapes.md")
} catch(err) {
console.log(`Unable to delete file the_fox_and_the_grapes.md because of ${err}`)
await fs.unlink("the_fox_and_the_grapes.md");
} catch (err) {
console.log(
`Unable to delete file the_fox_and_the_grapes.md because of ${err}`,
);
}
},
60000,