mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-03 19:19:08 -04:00
Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 19e5c318a0 | |||
| d49301555f | |||
| f648bb7b90 | |||
| 06f884a437 | |||
| 9e66861d07 | |||
| ae74f70d7d | |||
| 5b4a53177e | |||
| 5da1cda939 | |||
| 1285e381bd | |||
| 5d5cd44276 | |||
| ed37c645af | |||
| c40adafecc | |||
| 995b465205 | |||
| 8929dcf1dd | |||
| af0b79f1cd | |||
| 1995b38660 | |||
| 001a5159cf | |||
| 9d7d2052e7 | |||
| fd90e25f0e | |||
| 97c00d67c3 | |||
| 6ebd7c2f13 | |||
| 0267bb0e8e | |||
| 7875ee91e6 | |||
| e3405fca44 | |||
| f3bc2b61e7 | |||
| 4c703767b7 | |||
| a27648200d | |||
| c93bb02002 | |||
| e9ded4e65f | |||
| 47a6f5fe5a | |||
| b80f33e264 | |||
| b6409b6823 | |||
| db3f556cb4 | |||
| 4b5179169b | |||
| 971d37ceba | |||
| 3e0ffdc688 | |||
| 049471bade | |||
| 1e296ebe72 | |||
| f9f1de9516 | |||
| f576812e7a | |||
| c3bf3c7178 |
@@ -105,6 +105,7 @@ jobs:
|
||||
run: |
|
||||
pnpm pack --pack-destination ${{ runner.temp }} -C packages/llamaindex
|
||||
pnpm pack --pack-destination ${{ runner.temp }} -C packages/workflow
|
||||
pnpm pack --pack-destination ${{ runner.temp }} -C packages/core
|
||||
- name: Install packed packages
|
||||
run: npm add ${{ runner.temp }}/*.tgz
|
||||
working-directory: e2e/npm
|
||||
@@ -121,7 +122,6 @@ jobs:
|
||||
- nextjs-edge-runtime
|
||||
- nextjs-node-runtime
|
||||
- waku-query-engine
|
||||
- llama-parse-browser
|
||||
- vite-import-llamaindex
|
||||
runs-on: ubuntu-latest
|
||||
name: Build LlamaIndex Example (${{ matrix.packages }})
|
||||
@@ -162,7 +162,7 @@ jobs:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
directory: e2e/examples/vite-import-llamaindex
|
||||
skip_step: "install"
|
||||
build_script: build
|
||||
build_script: ci-build
|
||||
package_manager: pnpm
|
||||
|
||||
typecheck-examples:
|
||||
@@ -203,7 +203,7 @@ jobs:
|
||||
fi
|
||||
done
|
||||
- name: Install
|
||||
run: npm add ${{ runner.temp }}/*.tgz
|
||||
run: npm add ${{ runner.temp }}/*.tgz --legacy-peer-deps
|
||||
working-directory: ${{ runner.temp }}/examples
|
||||
- name: Run Type Check
|
||||
run: npx tsc --project ./tsconfig.json
|
||||
|
||||
@@ -1,5 +1,103 @@
|
||||
# @llamaindex/doc
|
||||
|
||||
## 0.2.55
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [06f884a]
|
||||
- Updated dependencies [06f884a]
|
||||
- Updated dependencies [d493015]
|
||||
- @llamaindex/core@0.6.22
|
||||
- @llamaindex/workflow@1.1.24
|
||||
- llamaindex@0.12.0
|
||||
- @llamaindex/node-parser@2.0.22
|
||||
- @llamaindex/openai@0.4.20
|
||||
- @llamaindex/readers@3.1.21
|
||||
|
||||
## 0.2.54
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ed37c64: Addition of APAC_ANTHROPIC_CLAUDE_4_SONNET type/record in @llamaindex/aws for APAC support for claude 4 sonnet per issue 2184.
|
||||
- Updated dependencies [8929dcf]
|
||||
- Updated dependencies [5da1cda]
|
||||
- llamaindex@0.11.29
|
||||
- @llamaindex/core@0.6.21
|
||||
- @llamaindex/workflow@1.1.23
|
||||
- @llamaindex/openai@0.4.19
|
||||
- @llamaindex/cloud@4.1.3
|
||||
- @llamaindex/node-parser@2.0.21
|
||||
- @llamaindex/readers@3.1.20
|
||||
|
||||
## 0.2.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1995b38]
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/workflow@1.1.22
|
||||
- @llamaindex/openai@0.4.18
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.2.52
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [0267bb0]
|
||||
- @llamaindex/core@0.6.20
|
||||
- @llamaindex/cloud@4.1.2
|
||||
- llamaindex@0.11.27
|
||||
- @llamaindex/node-parser@2.0.20
|
||||
- @llamaindex/openai@0.4.17
|
||||
- @llamaindex/readers@3.1.19
|
||||
- @llamaindex/workflow@1.1.21
|
||||
|
||||
## 0.2.51
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [4c70376]
|
||||
- @llamaindex/openai@0.4.16
|
||||
|
||||
## 0.2.50
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b6409b6]
|
||||
- @llamaindex/openai@0.4.15
|
||||
|
||||
## 0.2.49
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [4b51791]
|
||||
- @llamaindex/cloud@4.1.1
|
||||
- llamaindex@0.11.26
|
||||
|
||||
## 0.2.48
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- Updated dependencies [049471b]
|
||||
- @llamaindex/cloud@4.1.0
|
||||
- llamaindex@0.11.25
|
||||
|
||||
## 0.2.47
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c3bf3c7]
|
||||
- Updated dependencies [f9f1de9]
|
||||
- @llamaindex/cloud@4.0.28
|
||||
- @llamaindex/core@0.6.19
|
||||
- llamaindex@0.11.24
|
||||
- @llamaindex/node-parser@2.0.19
|
||||
- @llamaindex/openai@0.4.14
|
||||
- @llamaindex/readers@3.1.18
|
||||
- @llamaindex/workflow@1.1.20
|
||||
|
||||
## 0.2.46
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/doc",
|
||||
"version": "0.2.46",
|
||||
"version": "0.2.55",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"postinstall": "fumadocs-mdx",
|
||||
@@ -15,14 +15,14 @@
|
||||
"dependencies": {
|
||||
"@huggingface/transformers": "^3.5.0",
|
||||
"@icons-pack/react-simple-icons": "^10.1.0",
|
||||
"@llamaindex/chat-ui-docs": "^0.0.5",
|
||||
"@llamaindex/cloud": "workspace:*",
|
||||
"@llamaindex/chat-ui-docs": "^0.1.0",
|
||||
"llama-cloud-services": "^0.3.5",
|
||||
"@llamaindex/core": "workspace:*",
|
||||
"@llamaindex/node-parser": "workspace:*",
|
||||
"@llamaindex/openai": "workspace:*",
|
||||
"@llamaindex/readers": "workspace:*",
|
||||
"@llamaindex/workflow": "workspace:*",
|
||||
"@llamaindex/workflow-docs": "0.1.1",
|
||||
"@llamaindex/workflow-docs": "0.1.4",
|
||||
"@mdx-js/mdx": "^3.1.0",
|
||||
"@monaco-editor/react": "^4.7.0",
|
||||
"@next/third-parties": "^15.3.4",
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 154 KiB |
@@ -1,8 +1,8 @@
|
||||
import { upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut } from "@llamaindex/cloud/api";
|
||||
import fg from "fast-glob";
|
||||
import { fileGenerator, remarkDocGen, remarkInstall } from "fumadocs-docgen";
|
||||
import { remarkAutoTypeTable } from "fumadocs-typescript";
|
||||
import matter from "gray-matter";
|
||||
import { upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut } from "llama-cloud-services/api";
|
||||
import * as fs from "node:fs/promises";
|
||||
import path, { relative } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
import { ClientMDXContent } from "@/components/mdx";
|
||||
import { BotMessage } from "@/components/message";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { LlamaCloudRetriever } from "@/deps/cloud";
|
||||
import { ContextChatEngine } from "@llamaindex/core/chat-engine";
|
||||
import { Settings } from "@llamaindex/core/global";
|
||||
import { ChatMessage } from "@llamaindex/core/llms";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { createAI, createStreamableUI, getMutableAIState } from "ai/rsc";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
Settings.llm = new OpenAI({
|
||||
model: "gpt-4o",
|
||||
});
|
||||
|
||||
const retriever = new LlamaCloudRetriever({
|
||||
apiKey: process.env.LLAMA_CLOUD_API_KEY!,
|
||||
baseUrl: "https://api.cloud.llamaindex.ai/",
|
||||
|
||||
pipelineId: process.env.LLAMA_CLOUD_PIPELINE_ID!,
|
||||
});
|
||||
|
||||
const initialAIState = {
|
||||
messages: [],
|
||||
} as {
|
||||
messages: ChatMessage[];
|
||||
};
|
||||
|
||||
export type UIMessage = {
|
||||
id: number;
|
||||
display: ReactNode;
|
||||
};
|
||||
|
||||
const initialUIState = {
|
||||
messages: [],
|
||||
} as {
|
||||
messages: UIMessage[];
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const runAsyncFnWithoutBlocking = (fn: (...args: any) => Promise<any>) => {
|
||||
fn().catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
};
|
||||
|
||||
export const AIProvider = createAI({
|
||||
initialAIState,
|
||||
initialUIState,
|
||||
actions: {
|
||||
query: async (message: string): Promise<UIMessage> => {
|
||||
"use server";
|
||||
const chatEngine = new ContextChatEngine({ retriever });
|
||||
|
||||
const id = Date.now();
|
||||
const aiState = getMutableAIState<typeof AIProvider>();
|
||||
aiState.update({
|
||||
...aiState.get(),
|
||||
messages: [
|
||||
...aiState.get().messages,
|
||||
{
|
||||
role: "user",
|
||||
content: message,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const ui = createStreamableUI(
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-full" />
|
||||
<Skeleton className="h-4 w-full" />
|
||||
</div>,
|
||||
);
|
||||
|
||||
runAsyncFnWithoutBlocking(async () => {
|
||||
const response = await chatEngine.chat({
|
||||
message,
|
||||
chatHistory: aiState.get().messages,
|
||||
stream: true,
|
||||
});
|
||||
|
||||
let content = "";
|
||||
|
||||
for await (const { delta } of response) {
|
||||
content += delta;
|
||||
ui.update(<ClientMDXContent id={id} content={content} />);
|
||||
}
|
||||
|
||||
ui.done();
|
||||
|
||||
aiState.done({
|
||||
...aiState.get(),
|
||||
messages: [
|
||||
...aiState.get().messages,
|
||||
{
|
||||
role: "assistant",
|
||||
content,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
id,
|
||||
display: <BotMessage>{ui.value}</BotMessage>,
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1,4 +1,3 @@
|
||||
import { AIProvider } from "@/actions";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { GoogleAnalytics, GoogleTagManager } from "@next/third-parties/google";
|
||||
import { RootProvider } from "fumadocs-ui/provider";
|
||||
@@ -39,9 +38,7 @@ export default function Layout({ children }: { children: ReactNode }) {
|
||||
<GoogleTagManager gtmId="GTM-WWRFB36R" />
|
||||
<body className="flex min-h-screen flex-col">
|
||||
<TooltipProvider>
|
||||
<AIProvider>
|
||||
<RootProvider>{children}</RootProvider>
|
||||
</AIProvider>
|
||||
<RootProvider>{children}</RootProvider>
|
||||
</TooltipProvider>
|
||||
</body>
|
||||
<GoogleAnalytics gaId="G-NB9B8LW9W5" />
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
"use client";
|
||||
import type { AIProvider, UIMessage } from "@/actions";
|
||||
import { UserMessage } from "@/components/message";
|
||||
import { useActions, useUIState } from "ai/rsc";
|
||||
import { Info } from "lucide-react";
|
||||
import { ButtonHTMLAttributes, useState } from "react";
|
||||
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
|
||||
import { Button } from "./ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "./ui/dialog";
|
||||
import { Textarea } from "./ui/textarea";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
|
||||
|
||||
type AITriggerProps = ButtonHTMLAttributes<HTMLButtonElement>;
|
||||
|
||||
function ChatList({ messages }: { messages: UIMessage[] }) {
|
||||
if (messages.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative mx-auto w-full px-4">
|
||||
{messages.map((message, index) => (
|
||||
<div key={index} className="pb-4">
|
||||
{message.display}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const AITrigger = (props: AITriggerProps) => {
|
||||
const [{ messages }, setUIState] = useUIState<typeof AIProvider>();
|
||||
const { query } = useActions<typeof AIProvider>();
|
||||
const [inputValue, setInputValue] = useState("");
|
||||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger {...props} />
|
||||
<DialogPortal>
|
||||
<DialogOverlay className="bg-fd-background/50 data-[state=closed]:animate-fd-fade-out data-[state=open]:animate-fd-fade-in fixed inset-0 z-50 backdrop-blur-sm" />
|
||||
<DialogContent
|
||||
onOpenAutoFocus={(e) => {
|
||||
document.getElementById("nd-ai-input")?.focus();
|
||||
e.preventDefault();
|
||||
}}
|
||||
className="bg-fd-popover text-fd-popover-foreground data-[state=closed]:animate-fd-dialog-out data-[state=open]:animate-fd-dialog-in fixed left-1/2 z-50 my-[5vh] flex max-h-[90dvh] w-[98vw] max-w-[860px] origin-left -translate-x-1/2 flex-col rounded-lg border shadow-lg focus-visible:outline-none"
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="sr-only">Search AI</DialogTitle>
|
||||
<DialogDescription className="sr-only">
|
||||
Ask AI some questions.
|
||||
</DialogDescription>
|
||||
<Alert>
|
||||
<Info className="size-4" />
|
||||
<AlertTitle>Heads up!</AlertTitle>
|
||||
<AlertDescription>
|
||||
Answers from LlamaCloud may be inaccurate, please use with
|
||||
discretion.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
</DialogHeader>
|
||||
<div className="mt-4 flex-grow overflow-scroll">
|
||||
<ChatList messages={messages} />
|
||||
</div>
|
||||
<form
|
||||
className="space-y-4 px-4 py-2"
|
||||
action={async () => {
|
||||
const value = inputValue.trim();
|
||||
setInputValue("");
|
||||
if (!value) return;
|
||||
|
||||
// Add user message UI
|
||||
setUIState((state) => ({
|
||||
...state,
|
||||
messages: [
|
||||
...state.messages,
|
||||
{
|
||||
id: Date.now(),
|
||||
display: <UserMessage>{value}</UserMessage>,
|
||||
},
|
||||
],
|
||||
}));
|
||||
|
||||
try {
|
||||
// Submit and get response message
|
||||
const responseMessage = await query(value);
|
||||
setUIState((state) => ({
|
||||
...state,
|
||||
messages: [...state.messages, responseMessage],
|
||||
}));
|
||||
} catch (error) {
|
||||
// You may want to show a toast or trigger an error state.
|
||||
console.error(error);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex w-full flex-row items-center gap-2">
|
||||
<Textarea
|
||||
tabIndex={0}
|
||||
placeholder="Ask AI about documentation."
|
||||
className="w-full resize-none bg-transparent px-4 focus-within:outline-none sm:text-sm"
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
event.currentTarget.form?.requestSubmit(null);
|
||||
}
|
||||
}}
|
||||
autoFocus
|
||||
spellCheck={false}
|
||||
autoComplete="off"
|
||||
autoCorrect="off"
|
||||
name="message"
|
||||
rows={1}
|
||||
value={inputValue}
|
||||
onChange={(e) => setInputValue(e.target.value)}
|
||||
/>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="submit"
|
||||
size="icon"
|
||||
disabled={inputValue === ""}
|
||||
>
|
||||
<span className="sr-only">Send message</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Send message</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</DialogPortal>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,85 @@
|
||||
---
|
||||
title: MCP Toolbox For Databases
|
||||
description: MCP Toolbox for Databases is an open source MCP server for databases.
|
||||
---
|
||||
|
||||
# MCP Toolbox for Databases
|
||||
|
||||
[MCP Toolbox for Databases](https://github.com/googleapis/genai-toolbox) is an open source MCP server for databases. It was designed with enterprise-grade and production-quality in mind. It enables you to develop tools easier, faster, and more securely by handling the complexities such as connection pooling, authentication, and more.
|
||||
|
||||
Toolbox Tools can be seemlessly integrated with LlamaIndex applications. For more
|
||||
information on [getting
|
||||
started](https://googleapis.github.io/genai-toolbox/getting-started/local_quickstart_js/) or
|
||||
[configuring](https://googleapis.github.io/genai-toolbox/getting-started/configure/)
|
||||
Toolbox, see the
|
||||
[documentation](https://googleapis.github.io/genai-toolbox/getting-started/introduction/).
|
||||
|
||||

|
||||
|
||||
### Configure and deploy
|
||||
|
||||
Toolbox is an open source server that you deploy and manage yourself. For more
|
||||
instructions on deploying and configuring, see the official Toolbox
|
||||
documentation:
|
||||
|
||||
* [Installing the Server](https://googleapis.github.io/genai-toolbox/getting-started/introduction/#installing-the-server)
|
||||
* [Configuring Toolbox](https://googleapis.github.io/genai-toolbox/getting-started/configure/)
|
||||
|
||||
### Install client SDK
|
||||
|
||||
LlamaIndex relies on the `@toolbox-sdk/core` node package to use Toolbox. Install the
|
||||
package before getting started:
|
||||
|
||||
```shell
|
||||
npm install @toolbox-sdk/core
|
||||
```
|
||||
|
||||
### Loading Toolbox Tools
|
||||
|
||||
Once your Toolbox server is configured and up and running, you can load tools
|
||||
from your server using the SDK:
|
||||
|
||||
```javascript
|
||||
import { gemini, GEMINI_MODEL } from "@llamaindex/google";
|
||||
import { agent } from "@llamaindex/workflow";
|
||||
import { tool } from "llamaindex";
|
||||
import { ToolboxClient } from "@toolbox-sdk/core";
|
||||
|
||||
// Initialize LLM
|
||||
const llm = gemini({
|
||||
model: GEMINI_MODEL.GEMINI_2_0_FLASH,
|
||||
apiKey: process.env.GOOGLE_API_KEY,
|
||||
});
|
||||
|
||||
// Replace with your Toolbox Server URL
|
||||
const URL = 'https://127.0.0.1:5000';
|
||||
|
||||
const client = new ToolboxClient("http://127.0.0.1:5000");
|
||||
const toolboxTools = await client.loadToolset("my-toolset");
|
||||
|
||||
const getTool = (toolboxTool) => tool({
|
||||
name: toolboxTool.getName(),
|
||||
description: toolboxTool.getDescription(),
|
||||
parameters: toolboxTool.getParamSchema(),
|
||||
execute: toolboxTool
|
||||
});
|
||||
const tools = toolboxTools.map(getTool);
|
||||
|
||||
const myAgent = agent({
|
||||
tools: tools,
|
||||
llm,
|
||||
memory,
|
||||
systemPrompt: prompt,
|
||||
});
|
||||
const result = await myAgent.run(query);
|
||||
console.log(result);
|
||||
```
|
||||
|
||||
### Advanced Toolbox Features
|
||||
|
||||
Toolbox has a variety of features to make developing Gen AI tools for databases seamless.
|
||||
For more information, read more about the following:
|
||||
|
||||
- [Authenticated Parameters](https://googleapis.github.io/genai-toolbox/resources/tools/#authenticated-parameters): bind tool inputs to values from OIDC tokens automatically, making it easy to run sensitive queries without potentially leaking data
|
||||
- [Authorized Invocations](https://googleapis.github.io/genai-toolbox/resources/tools/#authorized-invocations): restrict access to use a tool based on the users Auth token
|
||||
- [OpenTelemetry](https://googleapis.github.io/genai-toolbox/how-to/export_telemetry/): get metrics and tracing from Toolbox with [OpenTelemetry](https://opentelemetry.io/docs/)
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"title": "Integration",
|
||||
"description": "See our integrations",
|
||||
"pages": ["open-llm-metry", "lang-trace", "vercel"]
|
||||
"pages": ["open-llm-metry", "lang-trace", "mcp-toolbox", "vercel"]
|
||||
}
|
||||
|
||||
@@ -38,7 +38,8 @@ Here's how to create a simple vector store index and query it using Vercel's AI
|
||||
import { openai } from "@ai-sdk/openai";
|
||||
import { llamaindex } from "@llamaindex/vercel";
|
||||
import { streamText } from "ai";
|
||||
import { Document, VectorStoreIndex } from "llamaindex";
|
||||
import { Document } from "llamaindex";
|
||||
import { LlamaCloudIndex } from "llama-cloud-services";
|
||||
|
||||
// Create an index from your documents
|
||||
const document = new Document({ text: yourText, id_: "unique-id" });
|
||||
@@ -69,7 +70,7 @@ streamText({
|
||||
For production deployments, you can use LlamaCloud to store and manage your documents:
|
||||
|
||||
```typescript
|
||||
import { LlamaCloudIndex } from "@llamaindex/cloud";
|
||||
import { LlamaCloudIndex } from "llama-cloud-services";
|
||||
|
||||
// Create a LlamaCloud index
|
||||
const index = await LlamaCloudIndex.fromDocuments({
|
||||
|
||||
@@ -37,6 +37,58 @@ console.log(result.data.result); // Baby Llama is called cria
|
||||
console.log(result.data.message); // { role: 'assistant', content: 'Baby Llama is called cria' }
|
||||
```
|
||||
|
||||
### Structured Output
|
||||
|
||||
You can extract structured data from agent responses by providing a `responseFormat` with a Zod schema. This is useful when you need the agent's response in a specific format for further processing:
|
||||
|
||||
```typescript
|
||||
import { z } from "zod";
|
||||
import { tool } from "llamaindex";
|
||||
import { agent } from "@llamaindex/workflow";
|
||||
import { openai } from "@llamaindex/openai";
|
||||
|
||||
// Define a weather tool
|
||||
const weatherTool = tool({
|
||||
name: "weatherTool",
|
||||
description: "Get weather information",
|
||||
parameters: z.object({
|
||||
location: z.string(),
|
||||
}),
|
||||
execute: ({ location }) => {
|
||||
return `The weather in ${location} is sunny. The temperature is 72 degrees. The humidity is 50%. The wind speed is 10 mph.`;
|
||||
},
|
||||
});
|
||||
|
||||
// Define the structure you want for the response
|
||||
const responseSchema = z.object({
|
||||
temperature: z.number(),
|
||||
humidity: z.number(),
|
||||
windSpeed: z.number(),
|
||||
});
|
||||
|
||||
// Create the agent
|
||||
const weatherAgent = agent({
|
||||
name: "weatherAgent",
|
||||
tools: [weatherTool],
|
||||
llm: openai({ model: "gpt-4.1-mini" }),
|
||||
});
|
||||
|
||||
// Run with structured output
|
||||
const result = await weatherAgent.run("What's the weather in Tokyo?", {
|
||||
responseFormat: responseSchema,
|
||||
});
|
||||
|
||||
console.log("Natural language result:", result.data.result);
|
||||
console.log("Structured data:", result.data.object);
|
||||
// Output: { temperature: 72, humidity: 50, windSpeed: 10 }
|
||||
```
|
||||
|
||||
The agent will:
|
||||
1. Use the weather tool to get the raw weather information
|
||||
2. Process that information through the LLM
|
||||
3. Extract structured data according to your schema
|
||||
4. Return both the natural language response and the structured object
|
||||
|
||||
### Event Streaming
|
||||
|
||||
Agent Workflows provide a unified interface for event streaming, making it easy to track and respond to different events during execution:
|
||||
|
||||
@@ -9,6 +9,7 @@ Sometimes your need more control over LLM interactions than what high-level agen
|
||||
Use `llm.exec` when you need to:
|
||||
- Build custom agent logic in [workflow](/docs/llamaindex/modules/agents/workflows) steps
|
||||
- Have precise control over message handling and tool execution
|
||||
- Extract structured data from LLM responses
|
||||
|
||||
## Basic Usage
|
||||
|
||||
@@ -51,6 +52,38 @@ messages.push(...newMessages);
|
||||
|
||||
> `newMessages` is an array as each tool call generates two messages: a tool call message and the tool call result message.
|
||||
|
||||
## Structured Output
|
||||
|
||||
You can use `responseFormat` with a Zod schema to get structured data from the LLM response:
|
||||
|
||||
```ts
|
||||
import { openai } from "@llamaindex/openai";
|
||||
import { ChatMessage } from "llamaindex";
|
||||
import z from "zod";
|
||||
|
||||
const llm = openai({ model: "gpt-4.1-mini" });
|
||||
|
||||
const schema = z.object({
|
||||
title: z.string(),
|
||||
author: z.string(),
|
||||
year: z.number(),
|
||||
});
|
||||
|
||||
const messages = [
|
||||
{
|
||||
role: "user",
|
||||
content: "I have been reading La Divina Commedia by Dante Alighieri, published in 1321",
|
||||
} as ChatMessage,
|
||||
];
|
||||
|
||||
const { newMessages, toolCalls, object } = await llm.exec({
|
||||
messages,
|
||||
responseFormat: schema,
|
||||
});
|
||||
|
||||
console.log(object); // { title: "La Divina Commedia", author: "Dante Alighieri", year: 1321 }
|
||||
```
|
||||
|
||||
## Agent Loop Pattern
|
||||
|
||||
A common pattern is to use `llm.exec` in a loop until the LLM stops making tool calls:
|
||||
@@ -102,7 +135,7 @@ For real-time responses, use the `stream` option to get the assistant's response
|
||||
|
||||
```ts
|
||||
import { openai } from "@llamaindex/openai";
|
||||
import { tool } from "llamaindex";
|
||||
import { ChatMessage, tool } from "llamaindex";
|
||||
import z from "zod";
|
||||
|
||||
async function streamingAgentLoop() {
|
||||
@@ -153,6 +186,7 @@ async function streamingAgentLoop() {
|
||||
|
||||
- **`newMessages`**: Array of new chat messages including the LLM response and any tool call messages (call or result). This is a function return the array when streaming.
|
||||
- **`toolCalls`**: Array of tool calls made by the LLM
|
||||
- **`object`**: The structured object when using `responseFormat` with a Zod schema (undefined if no schema is provided)
|
||||
- **`stream`**: Async iterable for streaming responses (only when `stream: true`)
|
||||
|
||||
## Best Practices
|
||||
@@ -161,4 +195,4 @@ For using `llm.exec` in an agent loop, take care to:
|
||||
|
||||
1. **Maintain message history**: Always add `newMessages` to your conversation history
|
||||
2. **Set exit conditions**: Implement proper logic to avoid infinite loops
|
||||
|
||||
3. **Handle structured output**: When using `responseFormat`, the `object` property contains your parsed data
|
||||
|
||||
@@ -101,6 +101,9 @@ const agent = agent({
|
||||
});
|
||||
```
|
||||
|
||||
You can also use [MCP Toolbox for
|
||||
Databases](/docs/llamaindex/integration/mcp-toolbox) to interact with MCP tools.
|
||||
|
||||
|
||||
## Function tool
|
||||
|
||||
|
||||
@@ -28,5 +28,4 @@ Here's an example of how to use a managed index together with a chat engine:
|
||||
|
||||
## API Reference
|
||||
|
||||
- [LlamaCloudIndex](/docs/api/classes/LlamaCloudIndex)
|
||||
- [LlamaCloudRetriever](/docs/api/classes/LlamaCloudRetriever)
|
||||
- [LlamaCloud Documentation](https://docs.cloud.llamaindex.ai/)
|
||||
|
||||
@@ -78,7 +78,7 @@ As the `PDFReader` is not working with the Edge runtime, here's how to use the `
|
||||
|
||||
```typescript
|
||||
import { SimpleDirectoryReader } from "@llamaindex/readers/directory";
|
||||
import { LlamaParseReader } from "@llamaindex/cloud";
|
||||
import { LlamaParseReader } from "llama-cloud-services";
|
||||
|
||||
export const DATA_DIR = "./data";
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ LlamaParse `json` mode supports extracting any images found in a page object by
|
||||
## Installation
|
||||
|
||||
```package-install
|
||||
npm i llamaindex @llamaindex/cloud @llamaindex/openai
|
||||
npm i llamaindex llama-cloud-services @llamaindex/openai
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -26,7 +26,7 @@ You can create an index across both text and image nodes by requesting alternati
|
||||
|
||||
```ts
|
||||
import { Document, ImageNode, VectorStoreIndex } from "llamaindex";
|
||||
import { LlamaParseReader } from "@llamaindex/cloud";
|
||||
import { LlamaParseReader } from "llama-cloud-services";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { createMessageContent } from "llamaindex";
|
||||
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ In JSON mode, LlamaParse will return a data structure representing the parsed ob
|
||||
## Installation
|
||||
|
||||
```package-install
|
||||
npm i llamaindex @llamaindex/cloud
|
||||
npm i llamaindex llama-cloud-services
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -16,7 +16,7 @@ For Json mode, you need to use `loadJson`. The `resultType` is automatically set
|
||||
More information about indexing the results on the next page.
|
||||
|
||||
```ts
|
||||
import { LlamaParseReader } from "@llamaindex/cloud";
|
||||
import { LlamaParseReader } from "llama-cloud-services";
|
||||
|
||||
const reader = new LlamaParseReader();
|
||||
async function main() {
|
||||
@@ -68,7 +68,7 @@ However, a simple work around is to create a new reader class that extends `Llam
|
||||
|
||||
```ts
|
||||
import { Document } from "llamaindex";
|
||||
import { LlamaParseReader } from "@llamaindex/cloud";
|
||||
import { LlamaParseReader } from "llama-cloud-services";
|
||||
|
||||
class LlamaParseReaderWithJson extends LlamaParseReader {
|
||||
// Override the loadData method
|
||||
|
||||
@@ -115,6 +115,7 @@ EU_AMAZON_NOVA_MICRO_1 = "eu.amazon.nova-micro-v1:0";
|
||||
APAC_ANTHROPIC_CLAUDE_3_5_SONNET = "apac.anthropic.claude-3-5-sonnet-20240620-v1:0";
|
||||
APAC_ANTHROPIC_CLAUDE_3_5_SONNET_V2 = "apac.anthropic.claude-3-5-sonnet-20241022-v2:0";
|
||||
APAC_ANTHROPIC_CLAUDE_3_7_SONNET = "apac.anthropic.claude-3-7-sonnet-20250219-v1:0";
|
||||
APAC_ANTHROPIC_CLAUDE_4_SONNET = "apac.anthropic.claude-sonnet-4-20250514-v1:0";
|
||||
APAC_ANTHROPIC_CLAUDE_3_HAIKU = "apac.anthropic.claude-3-haiku-20240307-v1:0";
|
||||
APAC_ANTHROPIC_CLAUDE_3_SONNET = "apac.anthropic.claude-3-sonnet-20240229-v1:0";
|
||||
APAC_AMAZON_NOVA_PRO_1 = "apac.amazon.nova-pro-v1:0";
|
||||
|
||||
@@ -4,7 +4,6 @@ title: Retriever
|
||||
|
||||
A retriever in LlamaIndex is what is used to fetch `Node`s from an index using a query string.
|
||||
|
||||
- [LlamaCloudRetriever](/docs/api/classes/LlamaCloudRetriever) to retrieve nodes from a [managed index](/docs/llamaindex/modules/data/data_index/managed)
|
||||
- [VectorIndexRetriever](/docs/api/classes/VectorIndexRetriever) will fetch the top-k most similar nodes. Ideal for dense retrieval to find most relevant nodes.
|
||||
- [SummaryIndexRetriever](/docs/api/classes/SummaryIndexRetriever) will fetch all nodes no matter the query. Ideal when complete context is necessary, e.g. analyzing large datasets.
|
||||
- [SummaryIndexLLMRetriever](/docs/api/classes/SummaryIndexLLMRetriever) utilizes an LLM to score and filter nodes based on relevancy to the query.
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
---
|
||||
title: Custom Model Per Request
|
||||
---
|
||||
|
||||
There are scenarios, such as the case of a multi-tenant backend API, where it may be required to handle each request with a custom model.
|
||||
|
||||
In such a scenario, modifying the `Settings` object directly as follows is not recommended:
|
||||
|
||||
```typescript
|
||||
import { Settings } from 'llamaindex';
|
||||
import { OpenAIEmbedding } from '@llamaindex/embeddings-openai';
|
||||
|
||||
Settings.embedModel = new OpenAIEmbedding({ apiKey: 'CLIENT_API_KEY' });
|
||||
Settings.llm = openai({ apiKey: key, model: 'gpt-4o' })
|
||||
```
|
||||
|
||||
Setting `llm` and `embedModel` directly will lead to unpredictable responses, since `Settings` is global and mutable.
|
||||
This can lead to race conditions, as each request modifies `Settings.embedModel` or `Settings.llm`.
|
||||
|
||||
The recommended approach is to use `Settings.withEmbedModel` or `Settings.withLLM` as follows:
|
||||
|
||||
```typescript
|
||||
const embedModel = new OpenAIEmbedding({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
});
|
||||
const llm = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
||||
|
||||
const llmResponse = await Settings.withEmbedModel(embedModel, async () => {
|
||||
return Settings.withLLM(llm, async () => {
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
const essay = await fs.readFile(path, "utf-8");
|
||||
// Create Document object with essay
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const index = await VectorStoreIndex.fromDocuments([document]);
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const { message, sourceNodes } = await queryEngine.query({
|
||||
query: "What did the author do in college?",
|
||||
});
|
||||
// Return response with sources
|
||||
return message.content;
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
The full example can be found [here](https://github.com/run-llama/LlamaIndexTS/tree/main/examples/local-settings).
|
||||
@@ -93,4 +93,4 @@ async function main() {
|
||||
main().catch(console.error);
|
||||
```
|
||||
|
||||
You can see the [full example file](https://github.com/run-llama/LlamaIndexTS/blob/main/examples/vectorIndexLocal.ts).
|
||||
You can see the [full example file](https://github.com/run-llama/LlamaIndexTS/blob/main/examples/index/vectorIndexLocal.ts).
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"workflows",
|
||||
"local_llm",
|
||||
"chatbot",
|
||||
"structured_data_extraction"
|
||||
"structured_data_extraction",
|
||||
"custom_model_per_request"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -46,3 +46,31 @@ You should expect output something like:
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Using the `exec` method
|
||||
|
||||
Many LLMs do not natively support structured output, and often rely exclusively on prompt or context engineering.
|
||||
|
||||
In this sense, we proved you with an alternative for structured data extraction, using the `exec` method with `responseFormat`.
|
||||
|
||||
For example, you can, in a new folder, install our Anthropic integration and `zod` v3:
|
||||
|
||||
```package-install
|
||||
npm init
|
||||
npm i -D typescript @types/node
|
||||
npm i @llamaindex/anthropic zod@3.25.76
|
||||
```
|
||||
|
||||
And then try extracting data with this code:
|
||||
|
||||
<include cwd>../../examples/agents/tools/response-format-exec.ts</include>
|
||||
|
||||
The output should look like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "La Divina Commedia",
|
||||
"author": "Dante Alighieri",
|
||||
"year": 1321
|
||||
}
|
||||
```
|
||||
@@ -1,96 +0,0 @@
|
||||
import {
|
||||
type MetadataFilter,
|
||||
type MetadataFilters,
|
||||
type RetrievalParams,
|
||||
runSearchApiV1PipelinesPipelineIdRetrievePost,
|
||||
type TextNodeWithScore,
|
||||
} from "@llamaindex/cloud/api";
|
||||
import { QueryBundle } from "@llamaindex/core/query-engine";
|
||||
import { BaseRetriever } from "@llamaindex/core/retriever";
|
||||
import { jsonToNode, NodeWithScore, ObjectType } from "@llamaindex/core/schema";
|
||||
import { extractText } from "@llamaindex/core/utils";
|
||||
|
||||
export type CloudRetrieveParams = Omit<
|
||||
RetrievalParams,
|
||||
"query" | "search_filters" | "dense_similarity_top_k"
|
||||
> & { similarityTopK?: number; filters?: MetadataFilters };
|
||||
|
||||
export type LlamaCloudRetrieverParams = {
|
||||
apiKey: string;
|
||||
baseUrl: string;
|
||||
pipelineId: string;
|
||||
} & CloudRetrieveParams;
|
||||
|
||||
export class LlamaCloudRetriever extends BaseRetriever {
|
||||
baseUrl: string;
|
||||
apiKey: string;
|
||||
|
||||
retrieveParams: CloudRetrieveParams;
|
||||
organizationId?: string;
|
||||
pipelineId: string;
|
||||
|
||||
private resultNodesToNodeWithScore(
|
||||
nodes: TextNodeWithScore[],
|
||||
): NodeWithScore[] {
|
||||
return nodes.map((node: TextNodeWithScore) => {
|
||||
const textNode = jsonToNode(node.node, ObjectType.TEXT);
|
||||
textNode.metadata = {
|
||||
...textNode.metadata,
|
||||
...node.node.extra_info,
|
||||
};
|
||||
return {
|
||||
node: textNode,
|
||||
score: node.score ?? undefined,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private convertFilter(filters?: MetadataFilters): MetadataFilters | null {
|
||||
if (!filters) return null;
|
||||
|
||||
const processFilter = (
|
||||
filter: MetadataFilter | MetadataFilters,
|
||||
): MetadataFilter | MetadataFilters => {
|
||||
if ("filters" in filter) {
|
||||
// type MetadataFilters
|
||||
return { ...filter, filters: filter.filters.map(processFilter) };
|
||||
}
|
||||
return { ...filter, value: filter.value ?? null };
|
||||
};
|
||||
|
||||
return { ...filters, filters: filters.filters.map(processFilter) };
|
||||
}
|
||||
|
||||
constructor(params: LlamaCloudRetrieverParams) {
|
||||
super();
|
||||
this.baseUrl = params.baseUrl;
|
||||
this.apiKey = params.apiKey;
|
||||
this.retrieveParams = params;
|
||||
this.pipelineId = params.pipelineId;
|
||||
}
|
||||
|
||||
override async _retrieve(query: QueryBundle): Promise<NodeWithScore[]> {
|
||||
const filters = this.convertFilter(this.retrieveParams.filters);
|
||||
const pipelineId = this.pipelineId;
|
||||
|
||||
const { data: results } =
|
||||
await runSearchApiV1PipelinesPipelineIdRetrievePost({
|
||||
throwOnError: true,
|
||||
path: {
|
||||
pipeline_id: pipelineId,
|
||||
},
|
||||
baseUrl: this.baseUrl,
|
||||
body: {
|
||||
...this.retrieveParams,
|
||||
query: extractText(query),
|
||||
search_filters: filters,
|
||||
dense_similarity_top_k: this.retrieveParams.similarityTopK!,
|
||||
},
|
||||
headers: {
|
||||
authorization: `Bearer ${this.apiKey}`,
|
||||
},
|
||||
});
|
||||
|
||||
return this.resultNodesToNodeWithScore(results.retrieval_nodes);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,6 @@
|
||||
"wrangler": "^3.89.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"hono": "^4.6.11"
|
||||
"hono": "^4.9.7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,50 @@
|
||||
# @llamaindex/cloudflare-worker-agent-test
|
||||
|
||||
## 0.0.191
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.0.190
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8929dcf]
|
||||
- llamaindex@0.11.29
|
||||
|
||||
## 0.0.189
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.0.188
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.27
|
||||
|
||||
## 0.0.187
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.26
|
||||
|
||||
## 0.0.186
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- llamaindex@0.11.25
|
||||
|
||||
## 0.0.185
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.24
|
||||
|
||||
## 0.0.184
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/cloudflare-worker-agent-test",
|
||||
"version": "0.0.184",
|
||||
"version": "0.0.191",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
@@ -1,530 +0,0 @@
|
||||
# @llamaindex/llama-parse-browser-test
|
||||
|
||||
## 0.0.82
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.27
|
||||
|
||||
## 0.0.81
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.26
|
||||
|
||||
## 0.0.80
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [2967d57]
|
||||
- @llamaindex/cloud@4.0.25
|
||||
|
||||
## 0.0.79
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.24
|
||||
|
||||
## 0.0.78
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a1b1598]
|
||||
- @llamaindex/cloud@4.0.23
|
||||
|
||||
## 0.0.77
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d2be868]
|
||||
- @llamaindex/cloud@4.0.22
|
||||
|
||||
## 0.0.76
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [579ca0c]
|
||||
- @llamaindex/cloud@4.0.21
|
||||
|
||||
## 0.0.75
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [48b0d88]
|
||||
- Updated dependencies [f185772]
|
||||
- @llamaindex/cloud@4.0.20
|
||||
|
||||
## 0.0.74
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [5a0ed1f]
|
||||
- Updated dependencies [5a0ed1f]
|
||||
- @llamaindex/cloud@4.0.19
|
||||
|
||||
## 0.0.73
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [47a7555]
|
||||
- @llamaindex/cloud@4.0.18
|
||||
|
||||
## 0.0.72
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.17
|
||||
|
||||
## 0.0.71
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.16
|
||||
|
||||
## 0.0.70
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.15
|
||||
|
||||
## 0.0.69
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.14
|
||||
|
||||
## 0.0.68
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.13
|
||||
|
||||
## 0.0.67
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.12
|
||||
|
||||
## 0.0.66
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [76ff23d]
|
||||
- @llamaindex/cloud@4.0.11
|
||||
|
||||
## 0.0.65
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.10
|
||||
|
||||
## 0.0.64
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3703f90]
|
||||
- @llamaindex/cloud@4.0.9
|
||||
|
||||
## 0.0.63
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.8
|
||||
|
||||
## 0.0.62
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [40f5f41]
|
||||
- @llamaindex/cloud@4.0.7
|
||||
|
||||
## 0.0.61
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.6
|
||||
|
||||
## 0.0.60
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [2225ffd]
|
||||
- @llamaindex/cloud@4.0.5
|
||||
|
||||
## 0.0.59
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.4
|
||||
|
||||
## 0.0.58
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [41191d0]
|
||||
- @llamaindex/cloud@4.0.3
|
||||
|
||||
## 0.0.57
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.2
|
||||
|
||||
## 0.0.56
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.0.1
|
||||
|
||||
## 0.0.55
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [bf56fc0]
|
||||
- Updated dependencies [5189b44]
|
||||
- @llamaindex/cloud@4.0.0
|
||||
|
||||
## 0.0.54
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@3.0.9
|
||||
|
||||
## 0.0.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@3.0.8
|
||||
|
||||
## 0.0.52
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@3.0.7
|
||||
|
||||
## 0.0.51
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@3.0.6
|
||||
|
||||
## 0.0.50
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@3.0.5
|
||||
|
||||
## 0.0.49
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@3.0.4
|
||||
|
||||
## 0.0.48
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@3.0.3
|
||||
|
||||
## 0.0.47
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c902fcb]
|
||||
- @llamaindex/cloud@3.0.2
|
||||
|
||||
## 0.0.46
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@3.0.1
|
||||
|
||||
## 0.0.45
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@3.0.0
|
||||
|
||||
## 0.0.44
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1c908fd]
|
||||
- @llamaindex/cloud@2.0.24
|
||||
|
||||
## 0.0.43
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [cb608b5]
|
||||
- @llamaindex/cloud@2.0.23
|
||||
|
||||
## 0.0.42
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d6c270e]
|
||||
- @llamaindex/cloud@2.0.22
|
||||
|
||||
## 0.0.41
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [5dec9f9]
|
||||
- Updated dependencies [fd9c829]
|
||||
- @llamaindex/cloud@2.0.21
|
||||
|
||||
## 0.0.40
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [012495b]
|
||||
- @llamaindex/cloud@2.0.20
|
||||
|
||||
## 0.0.39
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.19
|
||||
|
||||
## 0.0.38
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.18
|
||||
|
||||
## 0.0.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.17
|
||||
|
||||
## 0.0.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8be4589]
|
||||
- @llamaindex/cloud@2.0.16
|
||||
|
||||
## 0.0.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.15
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.14
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [90d265c]
|
||||
- @llamaindex/cloud@2.0.13
|
||||
|
||||
## 0.0.32
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.12
|
||||
|
||||
## 0.0.31
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.11
|
||||
|
||||
## 0.0.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.10
|
||||
|
||||
## 0.0.29
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.9
|
||||
|
||||
## 0.0.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.8
|
||||
|
||||
## 0.0.27
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.7
|
||||
|
||||
## 0.0.26
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.6
|
||||
|
||||
## 0.0.25
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.5
|
||||
|
||||
## 0.0.24
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.4
|
||||
|
||||
## 0.0.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.3
|
||||
|
||||
## 0.0.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.2
|
||||
|
||||
## 0.0.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.1
|
||||
|
||||
## 0.0.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@2.0.0
|
||||
|
||||
## 0.0.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@1.0.8
|
||||
|
||||
## 0.0.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@1.0.7
|
||||
|
||||
## 0.0.17
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@1.0.6
|
||||
|
||||
## 0.0.16
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@1.0.5
|
||||
|
||||
## 0.0.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [06f632b]
|
||||
- @llamaindex/cloud@1.0.4
|
||||
|
||||
## 0.0.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@1.0.3
|
||||
|
||||
## 0.0.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@1.0.2
|
||||
|
||||
## 0.0.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [4c38c1b]
|
||||
- Updated dependencies [24d065f]
|
||||
- Updated dependencies [a75af83]
|
||||
- @llamaindex/cloud@1.0.1
|
||||
|
||||
## 0.0.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@1.0.0
|
||||
|
||||
## 0.0.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@0.2.14
|
||||
|
||||
## 0.0.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@0.2.13
|
||||
|
||||
## 0.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@0.2.12
|
||||
|
||||
## 0.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [0b20ff9]
|
||||
- @llamaindex/cloud@0.2.11
|
||||
|
||||
## 0.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [981811e]
|
||||
- @llamaindex/cloud@0.2.10
|
||||
|
||||
## 0.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [df441e2]
|
||||
- @llamaindex/cloud@0.2.9
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac41ed3]
|
||||
- @llamaindex/cloud@0.2.8
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [fb36eff]
|
||||
- Updated dependencies [d24d3d1]
|
||||
- @llamaindex/cloud@0.2.7
|
||||
|
||||
## 0.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b42adeb]
|
||||
- @llamaindex/cloud@0.2.6
|
||||
|
||||
## 0.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [85c2e19]
|
||||
- @llamaindex/cloud@0.2.5
|
||||
@@ -1,111 +0,0 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with the LlamaParse Browser Test example.
|
||||
|
||||
## Package Overview
|
||||
|
||||
The `@llamaindex/llama-parse-browser-test` package is a minimal browser-based example that demonstrates how to use LlamaParse (from `@llamaindex/cloud`) in a web browser environment. This serves as both an integration test and a reference implementation for browser compatibility with LlamaIndexTS cloud services.
|
||||
|
||||
## Purpose
|
||||
|
||||
This example validates that:
|
||||
|
||||
- `@llamaindex/cloud` package works correctly in browser environments
|
||||
- LlamaParse functionality can be bundled and run in web applications
|
||||
- The build process properly handles WASM dependencies and browser-specific requirements
|
||||
- TypeScript compilation works with DOM APIs and modern bundler tooling
|
||||
|
||||
## Development Commands
|
||||
|
||||
- `npm run dev` - Start Vite development server with hot reload
|
||||
- `npm run build` - Build for production (TypeScript compilation + Vite build)
|
||||
- `npm run preview` - Preview the production build locally
|
||||
|
||||
## Architecture
|
||||
|
||||
### Build Setup
|
||||
|
||||
**Bundler**: Vite 6.x with TypeScript support
|
||||
**WASM Support**: Uses `vite-plugin-wasm` for WebAssembly module handling
|
||||
**Module System**: ESM-only (`"type": "module"`)
|
||||
**Target Environment**: Modern browsers (ES2020+)
|
||||
|
||||
### Key Configuration
|
||||
|
||||
**Vite Config (`vite.config.ts`):**
|
||||
|
||||
- `vite-plugin-wasm` - Enables WASM module imports
|
||||
- `ssr.external: ["tiktoken"]` - Excludes tiktoken from SSR bundling (browser-only)
|
||||
|
||||
**TypeScript Config (`tsconfig.json`):**
|
||||
|
||||
- Extends root monorepo TypeScript configuration
|
||||
- DOM and DOM.Iterable libraries enabled for browser APIs
|
||||
- Bundler module resolution for optimal Vite integration
|
||||
- References `@llamaindex/cloud` package for type checking
|
||||
|
||||
### Application Structure
|
||||
|
||||
**Entry Point (`src/main.ts`):**
|
||||
|
||||
- Imports `LlamaParseReader` from `@llamaindex/cloud`
|
||||
- Instantiates the reader to test browser compatibility
|
||||
- Minimal DOM manipulation for visual feedback
|
||||
|
||||
**Styling (`src/style.css`):**
|
||||
|
||||
- Modern CSS with light/dark theme support
|
||||
- Responsive design with flexbox layout
|
||||
- Clean, minimal UI suitable for testing environment
|
||||
|
||||
**HTML (`index.html`):**
|
||||
|
||||
- Standard Vite HTML template
|
||||
- Single-page application structure
|
||||
- Module script loading for ES6 imports
|
||||
|
||||
## Dependencies
|
||||
|
||||
**Core Dependency:**
|
||||
|
||||
- `@llamaindex/cloud` (workspace) - LlamaCloud integration including LlamaParse
|
||||
|
||||
**Development Dependencies:**
|
||||
|
||||
- `vite` - Modern build tool and development server
|
||||
- `vite-plugin-wasm` - WebAssembly support for Vite
|
||||
- `typescript` - TypeScript compiler and language support
|
||||
|
||||
## Testing Integration
|
||||
|
||||
This example functions as an end-to-end test by:
|
||||
|
||||
1. **Import Validation**: Verifies `@llamaindex/cloud` can be imported in browser context
|
||||
2. **Instantiation Testing**: Tests that `LlamaParseReader` can be created without errors
|
||||
3. **Bundle Compatibility**: Ensures the build process handles all dependencies correctly
|
||||
4. **Runtime Verification**: Validates the application loads and runs in actual browsers
|
||||
|
||||
## Browser Compatibility
|
||||
|
||||
The application targets modern browsers with:
|
||||
|
||||
- ES2020 language features
|
||||
- ES Modules support
|
||||
- WebAssembly support (for potential WASM dependencies)
|
||||
- Modern DOM APIs
|
||||
|
||||
## Development Notes
|
||||
|
||||
- **Minimal Implementation**: Keeps the example simple to focus on integration testing
|
||||
- **Cloud Service Focus**: Specifically tests browser compatibility with LlamaCloud services
|
||||
- **Build Validation**: Ensures the build process works end-to-end without browser-specific issues
|
||||
- **WASM Preparation**: Configured for WASM dependencies even if not currently used
|
||||
- **Type Safety**: Full TypeScript integration with proper DOM type definitions
|
||||
|
||||
## Common Issues
|
||||
|
||||
- **WASM Loading**: The `vite-plugin-wasm` handles WebAssembly module loading complexities
|
||||
- **SSR Exclusions**: Tiktoken is excluded from SSR to prevent Node.js-specific dependencies in browser builds
|
||||
- **Module Resolution**: Uses bundler module resolution for optimal compatibility with modern web tooling
|
||||
|
||||
This example serves as a foundation for integrating LlamaIndexTS cloud services into web applications and validates that the core cloud functionality works correctly in browser environments.
|
||||
@@ -1,13 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"name": "@llamaindex/llama-parse-browser-test",
|
||||
"private": true,
|
||||
"version": "0.0.82",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "^6.3.3",
|
||||
"vite-plugin-wasm": "^3.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@llamaindex/cloud": "workspace:*"
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { LlamaParseReader } from "@llamaindex/cloud";
|
||||
import "./style.css";
|
||||
|
||||
new LlamaParseReader();
|
||||
|
||||
document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
|
||||
<div>
|
||||
Hello, world!
|
||||
</div>
|
||||
`;
|
||||
@@ -1,96 +0,0 @@
|
||||
:root {
|
||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.vanilla:hover {
|
||||
filter: drop-shadow(0 0 2em #3178c6aa);
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
/// <reference types="vite/client" />
|
||||
@@ -1,26 +0,0 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "../../../packages/cloud/tsconfig.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import wasm from "vite-plugin-wasm";
|
||||
|
||||
export default {
|
||||
plugins: [wasm()],
|
||||
ssr: {
|
||||
external: ["tiktoken"],
|
||||
},
|
||||
};
|
||||
@@ -1,5 +1,50 @@
|
||||
# @llamaindex/next-agent-test
|
||||
|
||||
## 0.1.191
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.1.190
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8929dcf]
|
||||
- llamaindex@0.11.29
|
||||
|
||||
## 0.1.189
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.1.188
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.27
|
||||
|
||||
## 0.1.187
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.26
|
||||
|
||||
## 0.1.186
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- llamaindex@0.11.25
|
||||
|
||||
## 0.1.185
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.24
|
||||
|
||||
## 0.1.184
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/next-agent-test",
|
||||
"version": "0.1.184",
|
||||
"version": "0.1.191",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,5 +1,50 @@
|
||||
# test-edge-runtime
|
||||
|
||||
## 0.1.190
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.1.189
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8929dcf]
|
||||
- llamaindex@0.11.29
|
||||
|
||||
## 0.1.188
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.1.187
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.27
|
||||
|
||||
## 0.1.186
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.26
|
||||
|
||||
## 0.1.185
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- llamaindex@0.11.25
|
||||
|
||||
## 0.1.184
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.24
|
||||
|
||||
## 0.1.183
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/nextjs-edge-runtime-test",
|
||||
"version": "0.1.183",
|
||||
"version": "0.1.190",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,5 +1,71 @@
|
||||
# @llamaindex/next-node-runtime
|
||||
|
||||
## 0.1.62
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
- @llamaindex/huggingface@0.1.30
|
||||
- @llamaindex/readers@3.1.21
|
||||
|
||||
## 0.1.61
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8929dcf]
|
||||
- llamaindex@0.11.29
|
||||
- @llamaindex/huggingface@0.1.29
|
||||
- @llamaindex/readers@3.1.20
|
||||
|
||||
## 0.1.60
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
- @llamaindex/huggingface@0.1.28
|
||||
|
||||
## 0.1.59
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.27
|
||||
- @llamaindex/huggingface@0.1.27
|
||||
- @llamaindex/readers@3.1.19
|
||||
|
||||
## 0.1.58
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/huggingface@0.1.26
|
||||
|
||||
## 0.1.57
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/huggingface@0.1.25
|
||||
|
||||
## 0.1.56
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.26
|
||||
|
||||
## 0.1.55
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- llamaindex@0.11.25
|
||||
|
||||
## 0.1.54
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.24
|
||||
- @llamaindex/huggingface@0.1.24
|
||||
- @llamaindex/readers@3.1.18
|
||||
|
||||
## 0.1.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/next-node-runtime-test",
|
||||
"version": "0.1.53",
|
||||
"version": "0.1.62",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,5 +1,50 @@
|
||||
# vite-import-llamaindex
|
||||
|
||||
## 0.0.57
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.0.56
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8929dcf]
|
||||
- llamaindex@0.11.29
|
||||
|
||||
## 0.0.55
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.0.54
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.27
|
||||
|
||||
## 0.0.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.26
|
||||
|
||||
## 0.0.52
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- llamaindex@0.11.25
|
||||
|
||||
## 0.0.51
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.24
|
||||
|
||||
## 0.0.50
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
{
|
||||
"name": "vite-import-llamaindex",
|
||||
"private": true,
|
||||
"version": "0.0.50",
|
||||
"version": "0.0.57",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"size-limit": "size-limit"
|
||||
"size-limit": "size-limit",
|
||||
"ci-build": "pnpm -C ../../../ build && vite build"
|
||||
},
|
||||
"size-limit": [
|
||||
{
|
||||
@@ -16,7 +17,7 @@
|
||||
"@size-limit/preset-big-lib": "^11.1.6",
|
||||
"size-limit": "^11.1.6",
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "^6.3.3"
|
||||
"vite": "^6.3.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"llamaindex": "workspace:*"
|
||||
|
||||
@@ -1,5 +1,50 @@
|
||||
# @llamaindex/waku-query-engine-test
|
||||
|
||||
## 0.0.191
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.0.190
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8929dcf]
|
||||
- llamaindex@0.11.29
|
||||
|
||||
## 0.0.189
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.0.188
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.27
|
||||
|
||||
## 0.0.187
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.26
|
||||
|
||||
## 0.0.186
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- llamaindex@0.11.25
|
||||
|
||||
## 0.0.185
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.24
|
||||
|
||||
## 0.0.184
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/waku-query-engine-test",
|
||||
"version": "0.0.184",
|
||||
"version": "0.0.191",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -44,9 +44,7 @@ export const getWeatherTool = FunctionTool.from(
|
||||
name: "getWeather",
|
||||
description: "Get the weather for a city",
|
||||
parameters: z.object({
|
||||
city: z.string({
|
||||
description: "The city to get the weather for",
|
||||
}),
|
||||
city: z.string().describe("The city to get the weather for"),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,5 +1,294 @@
|
||||
# examples
|
||||
|
||||
## 0.3.42
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [06f884a]
|
||||
- Updated dependencies [06f884a]
|
||||
- Updated dependencies [d493015]
|
||||
- @llamaindex/core@0.6.22
|
||||
- @llamaindex/workflow@1.1.24
|
||||
- llamaindex@0.12.0
|
||||
- @llamaindex/node-parser@2.0.22
|
||||
- @llamaindex/anthropic@0.3.25
|
||||
- @llamaindex/assemblyai@0.1.21
|
||||
- @llamaindex/clip@0.0.76
|
||||
- @llamaindex/cohere@0.0.36
|
||||
- @llamaindex/deepinfra@0.0.76
|
||||
- @llamaindex/discord@0.1.21
|
||||
- @llamaindex/google@0.3.22
|
||||
- @llamaindex/huggingface@0.1.30
|
||||
- @llamaindex/jinaai@0.0.36
|
||||
- @llamaindex/mistral@0.1.22
|
||||
- @llamaindex/mixedbread@0.0.36
|
||||
- @llamaindex/notion@0.1.21
|
||||
- @llamaindex/ollama@0.1.23
|
||||
- @llamaindex/openai@0.4.20
|
||||
- @llamaindex/perplexity@0.0.33
|
||||
- @llamaindex/portkey-ai@0.0.64
|
||||
- @llamaindex/replicate@0.0.64
|
||||
- @llamaindex/bm25-retriever@0.0.11
|
||||
- @llamaindex/astra@0.0.36
|
||||
- @llamaindex/azure@0.1.37
|
||||
- @llamaindex/chroma@0.0.36
|
||||
- @llamaindex/elastic-search@0.1.22
|
||||
- @llamaindex/firestore@1.0.29
|
||||
- @llamaindex/milvus@0.1.31
|
||||
- @llamaindex/mongodb@0.0.37
|
||||
- @llamaindex/pinecone@0.1.22
|
||||
- @llamaindex/postgres@0.0.65
|
||||
- @llamaindex/qdrant@0.1.32
|
||||
- @llamaindex/supabase@0.1.23
|
||||
- @llamaindex/upstash@0.0.36
|
||||
- @llamaindex/weaviate@0.0.37
|
||||
- @llamaindex/vercel@0.1.22
|
||||
- @llamaindex/voyage-ai@1.0.28
|
||||
- @llamaindex/readers@3.1.21
|
||||
- @llamaindex/tools@0.1.12
|
||||
- @llamaindex/deepseek@0.0.38
|
||||
- @llamaindex/fireworks@0.0.36
|
||||
- @llamaindex/groq@0.0.92
|
||||
- @llamaindex/together@0.0.36
|
||||
- @llamaindex/vllm@0.0.62
|
||||
- @llamaindex/xai@0.0.23
|
||||
|
||||
## 0.3.41
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8929dcf]
|
||||
- Updated dependencies [5da1cda]
|
||||
- Updated dependencies [5d5cd44]
|
||||
- Updated dependencies [c40adaf]
|
||||
- llamaindex@0.11.29
|
||||
- @llamaindex/core@0.6.21
|
||||
- @llamaindex/tools@0.1.11
|
||||
- @llamaindex/workflow@1.1.23
|
||||
- @llamaindex/ollama@0.1.22
|
||||
- @llamaindex/openai@0.4.19
|
||||
- @llamaindex/vercel@0.1.21
|
||||
- @llamaindex/anthropic@0.3.24
|
||||
- @llamaindex/google@0.3.21
|
||||
- @llamaindex/cloud@4.1.3
|
||||
- @llamaindex/node-parser@2.0.21
|
||||
- @llamaindex/assemblyai@0.1.20
|
||||
- @llamaindex/clip@0.0.75
|
||||
- @llamaindex/cohere@0.0.35
|
||||
- @llamaindex/deepinfra@0.0.75
|
||||
- @llamaindex/discord@0.1.20
|
||||
- @llamaindex/huggingface@0.1.29
|
||||
- @llamaindex/jinaai@0.0.35
|
||||
- @llamaindex/mistral@0.1.21
|
||||
- @llamaindex/mixedbread@0.0.35
|
||||
- @llamaindex/notion@0.1.20
|
||||
- @llamaindex/perplexity@0.0.32
|
||||
- @llamaindex/portkey-ai@0.0.63
|
||||
- @llamaindex/replicate@0.0.63
|
||||
- @llamaindex/bm25-retriever@0.0.10
|
||||
- @llamaindex/astra@0.0.35
|
||||
- @llamaindex/azure@0.1.36
|
||||
- @llamaindex/chroma@0.0.35
|
||||
- @llamaindex/elastic-search@0.1.21
|
||||
- @llamaindex/firestore@1.0.28
|
||||
- @llamaindex/milvus@0.1.30
|
||||
- @llamaindex/mongodb@0.0.36
|
||||
- @llamaindex/pinecone@0.1.21
|
||||
- @llamaindex/postgres@0.0.64
|
||||
- @llamaindex/qdrant@0.1.31
|
||||
- @llamaindex/supabase@0.1.22
|
||||
- @llamaindex/upstash@0.0.35
|
||||
- @llamaindex/weaviate@0.0.36
|
||||
- @llamaindex/voyage-ai@1.0.27
|
||||
- @llamaindex/readers@3.1.20
|
||||
- @llamaindex/deepseek@0.0.37
|
||||
- @llamaindex/fireworks@0.0.35
|
||||
- @llamaindex/groq@0.0.91
|
||||
- @llamaindex/together@0.0.35
|
||||
- @llamaindex/vllm@0.0.61
|
||||
- @llamaindex/xai@0.0.22
|
||||
|
||||
## 0.3.40
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1995b38]
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/workflow@1.1.22
|
||||
- @llamaindex/openai@0.4.18
|
||||
- llamaindex@0.11.28
|
||||
- @llamaindex/clip@0.0.74
|
||||
- @llamaindex/deepinfra@0.0.74
|
||||
- @llamaindex/deepseek@0.0.36
|
||||
- @llamaindex/fireworks@0.0.34
|
||||
- @llamaindex/groq@0.0.90
|
||||
- @llamaindex/huggingface@0.1.28
|
||||
- @llamaindex/jinaai@0.0.34
|
||||
- @llamaindex/perplexity@0.0.31
|
||||
- @llamaindex/azure@0.1.35
|
||||
- @llamaindex/together@0.0.34
|
||||
- @llamaindex/vllm@0.0.60
|
||||
- @llamaindex/xai@0.0.21
|
||||
|
||||
## 0.3.39
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [0267bb0]
|
||||
- @llamaindex/core@0.6.20
|
||||
- @llamaindex/cloud@4.1.2
|
||||
- llamaindex@0.11.27
|
||||
- @llamaindex/node-parser@2.0.20
|
||||
- @llamaindex/anthropic@0.3.23
|
||||
- @llamaindex/assemblyai@0.1.19
|
||||
- @llamaindex/clip@0.0.73
|
||||
- @llamaindex/cohere@0.0.34
|
||||
- @llamaindex/deepinfra@0.0.73
|
||||
- @llamaindex/discord@0.1.19
|
||||
- @llamaindex/google@0.3.20
|
||||
- @llamaindex/huggingface@0.1.27
|
||||
- @llamaindex/jinaai@0.0.33
|
||||
- @llamaindex/mistral@0.1.20
|
||||
- @llamaindex/mixedbread@0.0.34
|
||||
- @llamaindex/notion@0.1.19
|
||||
- @llamaindex/ollama@0.1.21
|
||||
- @llamaindex/openai@0.4.17
|
||||
- @llamaindex/perplexity@0.0.30
|
||||
- @llamaindex/portkey-ai@0.0.62
|
||||
- @llamaindex/replicate@0.0.62
|
||||
- @llamaindex/bm25-retriever@0.0.9
|
||||
- @llamaindex/astra@0.0.34
|
||||
- @llamaindex/azure@0.1.34
|
||||
- @llamaindex/chroma@0.0.34
|
||||
- @llamaindex/elastic-search@0.1.20
|
||||
- @llamaindex/firestore@1.0.27
|
||||
- @llamaindex/milvus@0.1.29
|
||||
- @llamaindex/mongodb@0.0.35
|
||||
- @llamaindex/pinecone@0.1.20
|
||||
- @llamaindex/postgres@0.0.63
|
||||
- @llamaindex/qdrant@0.1.30
|
||||
- @llamaindex/supabase@0.1.21
|
||||
- @llamaindex/upstash@0.0.34
|
||||
- @llamaindex/weaviate@0.0.35
|
||||
- @llamaindex/vercel@0.1.20
|
||||
- @llamaindex/voyage-ai@1.0.26
|
||||
- @llamaindex/readers@3.1.19
|
||||
- @llamaindex/tools@0.1.10
|
||||
- @llamaindex/workflow@1.1.21
|
||||
- @llamaindex/deepseek@0.0.35
|
||||
- @llamaindex/fireworks@0.0.33
|
||||
- @llamaindex/groq@0.0.89
|
||||
- @llamaindex/together@0.0.33
|
||||
- @llamaindex/vllm@0.0.59
|
||||
- @llamaindex/xai@0.0.20
|
||||
|
||||
## 0.3.38
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [4c70376]
|
||||
- @llamaindex/openai@0.4.16
|
||||
- @llamaindex/clip@0.0.72
|
||||
- @llamaindex/deepinfra@0.0.72
|
||||
- @llamaindex/deepseek@0.0.34
|
||||
- @llamaindex/fireworks@0.0.32
|
||||
- @llamaindex/groq@0.0.88
|
||||
- @llamaindex/huggingface@0.1.26
|
||||
- @llamaindex/jinaai@0.0.32
|
||||
- @llamaindex/perplexity@0.0.29
|
||||
- @llamaindex/azure@0.1.33
|
||||
- @llamaindex/together@0.0.32
|
||||
- @llamaindex/vllm@0.0.58
|
||||
- @llamaindex/xai@0.0.19
|
||||
|
||||
## 0.3.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [47a6f5f]
|
||||
- Updated dependencies [b80f33e]
|
||||
- Updated dependencies [b6409b6]
|
||||
- Updated dependencies [b80f33e]
|
||||
- @llamaindex/ollama@0.1.20
|
||||
- @llamaindex/anthropic@0.3.22
|
||||
- @llamaindex/openai@0.4.15
|
||||
- @llamaindex/clip@0.0.71
|
||||
- @llamaindex/deepinfra@0.0.71
|
||||
- @llamaindex/deepseek@0.0.33
|
||||
- @llamaindex/fireworks@0.0.31
|
||||
- @llamaindex/groq@0.0.87
|
||||
- @llamaindex/huggingface@0.1.25
|
||||
- @llamaindex/jinaai@0.0.31
|
||||
- @llamaindex/perplexity@0.0.28
|
||||
- @llamaindex/azure@0.1.32
|
||||
- @llamaindex/together@0.0.31
|
||||
- @llamaindex/vllm@0.0.57
|
||||
- @llamaindex/xai@0.0.18
|
||||
|
||||
## 0.3.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [4b51791]
|
||||
- Updated dependencies [971d37c]
|
||||
- @llamaindex/cloud@4.1.1
|
||||
- @llamaindex/deepseek@0.0.32
|
||||
- llamaindex@0.11.26
|
||||
|
||||
## 0.3.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c3bf3c7]
|
||||
- Updated dependencies [f9f1de9]
|
||||
- @llamaindex/cloud@4.0.28
|
||||
- @llamaindex/core@0.6.19
|
||||
- llamaindex@0.11.24
|
||||
- @llamaindex/node-parser@2.0.19
|
||||
- @llamaindex/anthropic@0.3.21
|
||||
- @llamaindex/assemblyai@0.1.18
|
||||
- @llamaindex/clip@0.0.70
|
||||
- @llamaindex/cohere@0.0.33
|
||||
- @llamaindex/deepinfra@0.0.70
|
||||
- @llamaindex/discord@0.1.18
|
||||
- @llamaindex/google@0.3.18
|
||||
- @llamaindex/huggingface@0.1.24
|
||||
- @llamaindex/jinaai@0.0.30
|
||||
- @llamaindex/mistral@0.1.19
|
||||
- @llamaindex/mixedbread@0.0.33
|
||||
- @llamaindex/notion@0.1.18
|
||||
- @llamaindex/ollama@0.1.19
|
||||
- @llamaindex/openai@0.4.14
|
||||
- @llamaindex/perplexity@0.0.27
|
||||
- @llamaindex/portkey-ai@0.0.61
|
||||
- @llamaindex/replicate@0.0.61
|
||||
- @llamaindex/bm25-retriever@0.0.8
|
||||
- @llamaindex/astra@0.0.33
|
||||
- @llamaindex/azure@0.1.31
|
||||
- @llamaindex/chroma@0.0.33
|
||||
- @llamaindex/elastic-search@0.1.19
|
||||
- @llamaindex/firestore@1.0.26
|
||||
- @llamaindex/milvus@0.1.28
|
||||
- @llamaindex/mongodb@0.0.34
|
||||
- @llamaindex/pinecone@0.1.19
|
||||
- @llamaindex/postgres@0.0.62
|
||||
- @llamaindex/qdrant@0.1.29
|
||||
- @llamaindex/supabase@0.1.20
|
||||
- @llamaindex/upstash@0.0.33
|
||||
- @llamaindex/weaviate@0.0.34
|
||||
- @llamaindex/vercel@0.1.19
|
||||
- @llamaindex/voyage-ai@1.0.25
|
||||
- @llamaindex/readers@3.1.18
|
||||
- @llamaindex/tools@0.1.9
|
||||
- @llamaindex/workflow@1.1.20
|
||||
- @llamaindex/deepseek@0.0.31
|
||||
- @llamaindex/fireworks@0.0.30
|
||||
- @llamaindex/groq@0.0.86
|
||||
- @llamaindex/together@0.0.30
|
||||
- @llamaindex/vllm@0.0.56
|
||||
- @llamaindex/xai@0.0.17
|
||||
|
||||
## 0.3.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -20,9 +20,7 @@ const saveFileTool = tool({
|
||||
description:
|
||||
"Save the written content into a file that can be downloaded by the user",
|
||||
parameters: z.object({
|
||||
content: z.string({
|
||||
description: "The content to save into a file",
|
||||
}),
|
||||
content: z.string().describe("The content to save into a file"),
|
||||
}),
|
||||
execute: ({ content }: { content: string }) => {
|
||||
const filePath = os.tmpdir() + "/report.md";
|
||||
|
||||
@@ -17,9 +17,7 @@ const userQuestion = "which are the best comedies after 2010?";
|
||||
description:
|
||||
"Execute python code in a Jupyter notebook cell and return any result, stdout, stderr, display_data, and error.",
|
||||
parameters: z.object({
|
||||
code: z.string({
|
||||
description: "The python code to execute in a single cell.",
|
||||
}),
|
||||
code: z.string().describe("The python code to execute in a single cell."),
|
||||
}),
|
||||
execute: ({ code }) => {
|
||||
console.log(
|
||||
|
||||
@@ -26,9 +26,7 @@ const temperatureConverterTool = tool({
|
||||
description: "Convert a temperature from Fahrenheit to Celsius",
|
||||
name: "fahrenheitToCelsius",
|
||||
parameters: z.object({
|
||||
temperature: z.number({
|
||||
description: "The temperature in Fahrenheit",
|
||||
}),
|
||||
temperature: z.number().describe("The temperature in Fahrenheit"),
|
||||
}),
|
||||
execute: ({ temperature }) => {
|
||||
return ((temperature - 32) * 5) / 9;
|
||||
@@ -39,9 +37,7 @@ const temperatureFetcherTool = tool({
|
||||
description: "Fetch the temperature (in Fahrenheit) for a city",
|
||||
name: "fetchTemperature",
|
||||
parameters: z.object({
|
||||
city: z.string({
|
||||
description: "The city to fetch the temperature for",
|
||||
}),
|
||||
city: z.string().describe("The city to fetch the temperature for"),
|
||||
}),
|
||||
execute: ({ city }) => {
|
||||
const temperature = Math.floor(Math.random() * 58) + 32;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { openai } from "@llamaindex/openai";
|
||||
import { agent } from "@llamaindex/workflow";
|
||||
import { tool } from "llamaindex";
|
||||
|
||||
const weatherTool = tool({
|
||||
name: "weatherTool",
|
||||
description: "Get weather information",
|
||||
parameters: z.object({
|
||||
location: z.string(),
|
||||
}),
|
||||
execute: ({ location }) => {
|
||||
return `The weather in ${location} is sunny. The temperature is 72 degrees. The humidity is 50%. The wind speed is 10 mph.`;
|
||||
},
|
||||
});
|
||||
|
||||
const responseSchema = z.object({
|
||||
temperature: z.number(),
|
||||
humidity: z.number(),
|
||||
windSpeed: z.number(),
|
||||
});
|
||||
|
||||
const myAgent = agent({
|
||||
name: "myAgent",
|
||||
tools: [weatherTool],
|
||||
llm: openai({ model: "gpt-4.1-mini" }),
|
||||
});
|
||||
|
||||
async function main() {
|
||||
const result = await myAgent.run("What's the weather in Tokyo?", {
|
||||
responseFormat: responseSchema,
|
||||
});
|
||||
|
||||
console.log("result.data.result: ", result.data.result);
|
||||
console.log("result.data.object: ", result.data.object);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -14,9 +14,7 @@ const weatherTool = tool({
|
||||
name: "weather",
|
||||
description: "Get the weather",
|
||||
parameters: z.object({
|
||||
location: z.string({
|
||||
description: "The location to get the weather for",
|
||||
}),
|
||||
location: z.string().describe("The location to get the weather for"),
|
||||
}),
|
||||
execute: ({ location }) => {
|
||||
return `The weather in ${location} is sunny`;
|
||||
@@ -27,9 +25,7 @@ const inflationTool = tool({
|
||||
name: "inflation",
|
||||
description: "Get the inflation",
|
||||
parameters: z.object({
|
||||
location: z.string({
|
||||
description: "The location to get the inflation for",
|
||||
}),
|
||||
location: z.string().describe("The location to get the inflation for"),
|
||||
}),
|
||||
execute: ({ location }) => {
|
||||
return `The inflation in ${location} is 2%`;
|
||||
@@ -41,9 +37,7 @@ const saveFileTool = tool({
|
||||
description:
|
||||
"Save the written content into a file that can be downloaded by the user",
|
||||
parameters: z.object({
|
||||
content: z.string({
|
||||
description: "The content to save into a file",
|
||||
}),
|
||||
content: z.string().describe("The content to save into a file"),
|
||||
}),
|
||||
execute: ({ content }) => {
|
||||
const filePath = "./report.md";
|
||||
|
||||
@@ -14,11 +14,8 @@ const writeJokeSchema = z.object({
|
||||
.describe("The topic to write a joke or describe the joke to improve."),
|
||||
writtenJoke: z.optional(z.string()).describe("The written joke."),
|
||||
retriedTimes: z
|
||||
.number()
|
||||
.default(0)
|
||||
.describe(
|
||||
"The retried times for writing the joke. Always increase this from the input retriedTimes.",
|
||||
),
|
||||
.optional(z.number().default(0))
|
||||
.describe("The retried times for writing the joke."),
|
||||
});
|
||||
|
||||
const critiqueSchema = z.object({
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { openai } from "@llamaindex/openai";
|
||||
import { ChatMessage } from "llamaindex";
|
||||
import z from "zod";
|
||||
|
||||
const llm = openai({ model: "gpt-4.1-mini" });
|
||||
|
||||
const schema = z.object({
|
||||
title: z.string(),
|
||||
author: z.string(),
|
||||
year: z.number(),
|
||||
});
|
||||
|
||||
const messages: ChatMessage[] = [
|
||||
{
|
||||
role: "user",
|
||||
content: `I have been reading La Divina Commedia by Dante Alighieri, published in 1321`,
|
||||
},
|
||||
];
|
||||
|
||||
async function main() {
|
||||
{
|
||||
// Non-streaming
|
||||
const { object } = await llm.exec({ messages, responseFormat: schema });
|
||||
console.log("Non-streaming object:", object);
|
||||
}
|
||||
|
||||
{
|
||||
// Streaming
|
||||
let exit = false;
|
||||
do {
|
||||
const { stream, newMessages, toolCalls, object } = await llm.exec({
|
||||
messages,
|
||||
stream: true,
|
||||
responseFormat: schema,
|
||||
});
|
||||
|
||||
for await (const chunk of stream) {
|
||||
console.log(chunk.delta);
|
||||
}
|
||||
console.log("Streaming object:", object);
|
||||
|
||||
messages.push(...newMessages());
|
||||
exit = toolCalls.length === 0;
|
||||
} while (!exit);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Anthropic } from "@llamaindex/anthropic";
|
||||
import { ChatMessage, ToolCall } from "llamaindex";
|
||||
import { z } from "zod";
|
||||
|
||||
const llm = new Anthropic({ model: "claude-4-0-sonnet" });
|
||||
|
||||
const responseSchema = z.object({
|
||||
title: z.string().describe("The title of the book"),
|
||||
author: z.string().describe("The author of the book"),
|
||||
year: z.number().describe("The publication year"),
|
||||
});
|
||||
|
||||
async function main() {
|
||||
const messages: ChatMessage[] = [];
|
||||
let toolCalls: ToolCall[] = [];
|
||||
let object: z.infer<typeof responseSchema> | undefined;
|
||||
do {
|
||||
const result = await llm.exec({
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: `You are a book expert. Your task is, given a user message, extract the title, author and publication year of the book and output them in JSON format.`,
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: `I have been reading La Divina Commedia by Dante Alighieri, published in 1321, which tells the story of a guy who goes through Hell, Purgatory and Heaven just to meet his beloved ex-girlfriend.`,
|
||||
},
|
||||
],
|
||||
responseFormat: responseSchema,
|
||||
});
|
||||
object = result.object;
|
||||
messages.push(...result.newMessages);
|
||||
toolCalls = result.toolCalls;
|
||||
} while (toolCalls.length == 0);
|
||||
|
||||
console.log(messages);
|
||||
console.log(toolCalls);
|
||||
console.log(object);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -22,7 +22,7 @@ const { withState, getContext } = createStatefulMiddleware(() => ({
|
||||
const jokeFlow = withState(createWorkflow());
|
||||
|
||||
// Define handlers for each step
|
||||
jokeFlow.handle([startEvent], async (event) => {
|
||||
jokeFlow.handle([startEvent], async (context, event) => {
|
||||
// Prompt the LLM to write a joke
|
||||
const prompt = `Write your best joke about ${event.data}. Write the joke between <joke> and </joke> tags.`;
|
||||
const response = await llm.complete({ prompt });
|
||||
@@ -34,7 +34,7 @@ jokeFlow.handle([startEvent], async (event) => {
|
||||
return jokeEvent.with({ joke: joke });
|
||||
});
|
||||
|
||||
jokeFlow.handle([jokeEvent], async (event) => {
|
||||
jokeFlow.handle([jokeEvent], async (context, event) => {
|
||||
// Prompt the LLM to critique the joke
|
||||
const prompt = `Give a thorough critique of the following joke. If the joke needs improvement, put "IMPROVE" somewhere in the critique: ${event.data.joke}`;
|
||||
const response = await llm.complete({ prompt });
|
||||
@@ -50,9 +50,9 @@ jokeFlow.handle([jokeEvent], async (event) => {
|
||||
return resultEvent.with({ joke: event.data.joke, critique: response.text });
|
||||
});
|
||||
|
||||
jokeFlow.handle([critiqueEvent], async (event) => {
|
||||
jokeFlow.handle([critiqueEvent], async (context, event) => {
|
||||
// Keep track of the number of iterations
|
||||
const state = getContext().state;
|
||||
const state = context.state;
|
||||
state.numIterations++;
|
||||
|
||||
// Write a new joke based on the previous joke and critique
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { stdin as input, stdout as output } from "node:process";
|
||||
import readline from "node:readline/promises";
|
||||
|
||||
import { ContextChatEngine, LlamaCloudIndex } from "llamaindex";
|
||||
import { LlamaCloudIndex } from "llama-cloud-services";
|
||||
import { ContextChatEngine } from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
const index = new LlamaCloudIndex({
|
||||
|
||||
@@ -4,7 +4,8 @@ import { stdin as input, stdout as output } from "node:process";
|
||||
|
||||
import readline from "node:readline/promises";
|
||||
|
||||
import { Document, LlamaCloudIndex } from "llamaindex";
|
||||
import { LlamaCloudIndex } from "llama-cloud-services";
|
||||
import { Document } from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { stdin as input, stdout as output } from "node:process";
|
||||
import readline from "node:readline/promises";
|
||||
|
||||
import { LlamaCloudIndex } from "llamaindex";
|
||||
import { LlamaCloudIndex } from "llama-cloud-services";
|
||||
|
||||
async function main() {
|
||||
const index = new LlamaCloudIndex({
|
||||
|
||||
@@ -29,9 +29,9 @@ async function callLLM(init: { model: string }) {
|
||||
description:
|
||||
"Execute python code in a Jupyter notebook cell and return any result, stdout, stderr, display_data, and error.",
|
||||
parameters: z.object({
|
||||
code: z.string({
|
||||
description: "The python code to execute in a single cell.",
|
||||
}),
|
||||
code: z
|
||||
.string()
|
||||
.describe("The python code to execute in a single cell."),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# local-settings
|
||||
|
||||
## 1.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
- @llamaindex/openai@0.4.20
|
||||
@@ -0,0 +1,69 @@
|
||||
import { OpenAI, OpenAIEmbedding } from "@llamaindex/openai";
|
||||
import express, { Request, Response } from "express";
|
||||
import fs from "fs/promises";
|
||||
import { Document, Settings, VectorStoreIndex } from "llamaindex";
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
app.get("/default", async (req: Request, res: Response) => {
|
||||
const embedModel = new OpenAIEmbedding({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
});
|
||||
const llm = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
||||
|
||||
const llmResponse = await Settings.withEmbedModel(embedModel, async () => {
|
||||
return Settings.withLLM(llm, async () => {
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
const essay = await fs.readFile(path, "utf-8");
|
||||
// Create Document object with essay
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const index = await VectorStoreIndex.fromDocuments([document]);
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const { message, sourceNodes } = await queryEngine.query({
|
||||
query: "What did the author do in college?",
|
||||
});
|
||||
// Return response with sources
|
||||
return message.content;
|
||||
});
|
||||
});
|
||||
// res.send(message.content)
|
||||
res.send(llmResponse);
|
||||
});
|
||||
|
||||
app.get("/custom", async (req: Request, res: Response) => {
|
||||
const embedModel = new OpenAIEmbedding({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
model: "text-embedding-3-small",
|
||||
});
|
||||
const llm = new OpenAI({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
model: "gpt-3.5-turbo",
|
||||
});
|
||||
|
||||
const llmResponse = await Settings.withEmbedModel(embedModel, async () => {
|
||||
return Settings.withLLM(llm, async () => {
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
const essay = await fs.readFile(path, "utf-8");
|
||||
// Create Document object with essay
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const index = await VectorStoreIndex.fromDocuments([document]);
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const { message, sourceNodes } = await queryEngine.query({
|
||||
query: "What did the author do in college?",
|
||||
});
|
||||
// Return response with sources
|
||||
return message.content;
|
||||
});
|
||||
});
|
||||
// res.send(message.content)
|
||||
res.send(llmResponse);
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`);
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "local-settings",
|
||||
"version": "1.0.1",
|
||||
"main": "index.js",
|
||||
"private": "true",
|
||||
"scripts": {
|
||||
"test": "echo \"No tests for example package\""
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"devDependencies": {
|
||||
"@types/express": "^5.0.3",
|
||||
"typescript": "^5.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@llamaindex/openai": "^0.4.20",
|
||||
"express": "^5.1.0",
|
||||
"llamaindex": "^0.12.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "node",
|
||||
"types": ["node", "express"]
|
||||
},
|
||||
"include": ["*.ts"]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { anthropic } from "@llamaindex/anthropic";
|
||||
import { agent } from "@llamaindex/workflow";
|
||||
|
||||
(async function () {
|
||||
const workflow = agent({
|
||||
llm: anthropic({
|
||||
model: "claude-4-1-opus",
|
||||
}),
|
||||
});
|
||||
const result = await workflow.run(
|
||||
"What are three compounds we should consider investigating to advance research into new antibiotics? Why should we consider them?",
|
||||
);
|
||||
console.log(result.data.result);
|
||||
})();
|
||||
@@ -8,9 +8,7 @@ const weatherTool = tool({
|
||||
name: "weather",
|
||||
description: "Get the weather",
|
||||
parameters: z.object({
|
||||
location: z.string({
|
||||
description: "The location to get the weather for",
|
||||
}),
|
||||
location: z.string().describe("The location to get the weather for"),
|
||||
}),
|
||||
execute: ({ location }) => {
|
||||
return `The weather in ${location} is rainy`;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { ollama } from "@llamaindex/ollama";
|
||||
|
||||
(async () => {
|
||||
const llm = ollama({
|
||||
model: "gpt-oss:20b",
|
||||
});
|
||||
const response = await llm.complete({ prompt: "How are you?" });
|
||||
console.log("Response:", response.text);
|
||||
})();
|
||||
@@ -7,9 +7,7 @@ async function main() {
|
||||
name: "weather",
|
||||
description: "Get the weather",
|
||||
parameters: z.object({
|
||||
location: z.string({
|
||||
description: "The location to get the weather for",
|
||||
}),
|
||||
location: z.string().describe("The location to get the weather for"),
|
||||
}),
|
||||
execute: ({ location }) => {
|
||||
return `The weather in ${location} is sunny`;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { openai } from "@ai-sdk/openai";
|
||||
import { llamaindex } from "@llamaindex/vercel";
|
||||
import { streamText } from "ai";
|
||||
import { Document, LlamaCloudIndex } from "llamaindex";
|
||||
import { stepCountIs, streamText } from "ai";
|
||||
import { LlamaCloudIndex } from "llama-cloud-services";
|
||||
import { Document } from "llamaindex";
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
async function main() {
|
||||
@@ -28,7 +29,7 @@ async function main() {
|
||||
"get information from your knowledge base to answer questions.", // optional description
|
||||
}),
|
||||
},
|
||||
maxSteps: 5,
|
||||
stopWhen: stepCountIs(5),
|
||||
});
|
||||
|
||||
for await (const textPart of result.textStream) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { openai } from "@ai-sdk/openai";
|
||||
import { llamaindex } from "@llamaindex/vercel";
|
||||
import { streamText } from "ai";
|
||||
import { stepCountIs, streamText } from "ai";
|
||||
import { Document, VectorStoreIndex } from "llamaindex";
|
||||
|
||||
import fs from "node:fs/promises";
|
||||
@@ -24,7 +24,7 @@ async function main() {
|
||||
"get information from your knowledge base to answer questions.", // optional description
|
||||
}),
|
||||
},
|
||||
maxSteps: 5,
|
||||
stopWhen: stepCountIs(5),
|
||||
});
|
||||
|
||||
for await (const textPart of result.textStream) {
|
||||
|
||||
+51
-50
@@ -1,77 +1,78 @@
|
||||
{
|
||||
"name": "@llamaindex/examples",
|
||||
"version": "0.3.34",
|
||||
"version": "0.3.42",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"start": "echo 'To get started, run `npx tsx <path to example>`'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ai-sdk/openai": "^1.0.5",
|
||||
"@ai-sdk/openai": "^2.0.27",
|
||||
"@azure/cosmos": "^4.1.1",
|
||||
"@azure/identity": "^4.4.1",
|
||||
"@azure/search-documents": "^12.1.0",
|
||||
"@llamaindex/anthropic": "^0.3.20",
|
||||
"@llamaindex/assemblyai": "^0.1.17",
|
||||
"@llamaindex/astra": "^0.0.32",
|
||||
"@llamaindex/azure": "^0.1.30",
|
||||
"@llamaindex/bm25-retriever": "^0.0.7",
|
||||
"@llamaindex/chroma": "^0.0.32",
|
||||
"@llamaindex/clip": "^0.0.69",
|
||||
"@llamaindex/cloud": "^4.0.27",
|
||||
"@llamaindex/cohere": "^0.0.32",
|
||||
"@llamaindex/core": "^0.6.18",
|
||||
"@llamaindex/deepinfra": "^0.0.69",
|
||||
"@llamaindex/deepseek": "^0.0.30",
|
||||
"@llamaindex/discord": "^0.1.17",
|
||||
"@llamaindex/elastic-search": "^0.1.18",
|
||||
"@llamaindex/anthropic": "^0.3.25",
|
||||
"@llamaindex/assemblyai": "^0.1.21",
|
||||
"@llamaindex/astra": "^0.0.36",
|
||||
"@llamaindex/azure": "^0.1.37",
|
||||
"@llamaindex/bm25-retriever": "^0.0.11",
|
||||
"@llamaindex/chroma": "^0.0.36",
|
||||
"@llamaindex/clip": "^0.0.76",
|
||||
"llama-cloud-services": "^0.3.5",
|
||||
"@llamaindex/cohere": "^0.0.36",
|
||||
"@llamaindex/core": "^0.6.22",
|
||||
"@llamaindex/deepinfra": "^0.0.76",
|
||||
"@llamaindex/deepseek": "^0.0.38",
|
||||
"@llamaindex/discord": "^0.1.21",
|
||||
"@llamaindex/elastic-search": "^0.1.22",
|
||||
"@llamaindex/env": "^0.1.30",
|
||||
"@llamaindex/firestore": "^1.0.25",
|
||||
"@llamaindex/fireworks": "^0.0.29",
|
||||
"@llamaindex/google": "^0.3.17",
|
||||
"@llamaindex/groq": "^0.0.85",
|
||||
"@llamaindex/huggingface": "^0.1.23",
|
||||
"@llamaindex/jinaai": "^0.0.29",
|
||||
"@llamaindex/milvus": "^0.1.27",
|
||||
"@llamaindex/mistral": "^0.1.18",
|
||||
"@llamaindex/mixedbread": "^0.0.32",
|
||||
"@llamaindex/mongodb": "^0.0.33",
|
||||
"@llamaindex/node-parser": "^2.0.18",
|
||||
"@llamaindex/notion": "^0.1.17",
|
||||
"@llamaindex/ollama": "^0.1.18",
|
||||
"@llamaindex/openai": "^0.4.13",
|
||||
"@llamaindex/perplexity": "^0.0.26",
|
||||
"@llamaindex/pinecone": "^0.1.18",
|
||||
"@llamaindex/portkey-ai": "^0.0.60",
|
||||
"@llamaindex/postgres": "^0.0.61",
|
||||
"@llamaindex/qdrant": "^0.1.28",
|
||||
"@llamaindex/readers": "^3.1.17",
|
||||
"@llamaindex/replicate": "^0.0.60",
|
||||
"@llamaindex/supabase": "^0.1.19",
|
||||
"@llamaindex/together": "^0.0.29",
|
||||
"@llamaindex/tools": "^0.1.8",
|
||||
"@llamaindex/upstash": "^0.0.32",
|
||||
"@llamaindex/vercel": "^0.1.18",
|
||||
"@llamaindex/vllm": "^0.0.55",
|
||||
"@llamaindex/voyage-ai": "^1.0.24",
|
||||
"@llamaindex/weaviate": "^0.0.33",
|
||||
"@llamaindex/workflow": "^1.1.19",
|
||||
"@llamaindex/xai": "^0.0.16",
|
||||
"@llamaindex/firestore": "^1.0.29",
|
||||
"@llamaindex/fireworks": "^0.0.36",
|
||||
"@llamaindex/google": "^0.3.22",
|
||||
"@llamaindex/groq": "^0.0.92",
|
||||
"@llamaindex/huggingface": "^0.1.30",
|
||||
"@llamaindex/jinaai": "^0.0.36",
|
||||
"@llamaindex/milvus": "^0.1.31",
|
||||
"@llamaindex/mistral": "^0.1.22",
|
||||
"@llamaindex/mixedbread": "^0.0.36",
|
||||
"@llamaindex/mongodb": "^0.0.37",
|
||||
"@llamaindex/node-parser": "^2.0.22",
|
||||
"@llamaindex/notion": "^0.1.21",
|
||||
"@llamaindex/ollama": "^0.1.23",
|
||||
"@llamaindex/openai": "^0.4.20",
|
||||
"@llamaindex/perplexity": "^0.0.33",
|
||||
"@llamaindex/pinecone": "^0.1.22",
|
||||
"@llamaindex/portkey-ai": "^0.0.64",
|
||||
"@llamaindex/postgres": "^0.0.65",
|
||||
"@llamaindex/qdrant": "^0.1.32",
|
||||
"@llamaindex/readers": "^3.1.21",
|
||||
"@llamaindex/replicate": "^0.0.64",
|
||||
"@llamaindex/supabase": "^0.1.23",
|
||||
"@llamaindex/together": "^0.0.36",
|
||||
"@llamaindex/tools": "^0.1.12",
|
||||
"@llamaindex/upstash": "^0.0.36",
|
||||
"@llamaindex/vercel": "^0.1.22",
|
||||
"@llamaindex/vllm": "^0.0.62",
|
||||
"@llamaindex/voyage-ai": "^1.0.28",
|
||||
"@llamaindex/weaviate": "^0.0.37",
|
||||
"@llamaindex/workflow": "^1.1.24",
|
||||
"@llamaindex/xai": "^0.0.23",
|
||||
"@notionhq/client": "^4.0.0",
|
||||
"@pinecone-database/pinecone": "^4.0.0",
|
||||
"@vercel/postgres": "^0.10.0",
|
||||
"ai": "^4.3.17",
|
||||
"ai": "^5.0.39",
|
||||
"ajv": "^8.17.1",
|
||||
"commander": "^12.1.0",
|
||||
"dotenv": "^17.2.0",
|
||||
"js-tiktoken": "^1.0.14",
|
||||
"llamaindex": "^0.11.23",
|
||||
"llamaindex": "^0.12.0",
|
||||
"mongodb": "6.7.0",
|
||||
"postgres": "^3.4.4",
|
||||
"wikipedia": "^2.1.2",
|
||||
"zod": "^3.25.76"
|
||||
"zod": "^4.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^5.0.3",
|
||||
"@types/node": "^24.0.13",
|
||||
"tsx": "^4.20.3",
|
||||
"typescript": "^5.8.3"
|
||||
|
||||
@@ -9,10 +9,7 @@
|
||||
"start:html": "node --import tsx ./src/html.ts",
|
||||
"start:markdown": "node --import tsx ./src/markdown.ts",
|
||||
"start:pdf": "node --import tsx ./src/pdf.ts",
|
||||
"start:llamaparse": "node --import tsx ./src/llamaparse.ts",
|
||||
"start:notion": "node --import tsx ./src/notion.ts",
|
||||
"start:llamaparse-dir": "node --import tsx ./src/simple-directory-reader-with-llamaparse.ts",
|
||||
"start:llamaparse-json": "node --import tsx ./src/llamaparse-json.ts",
|
||||
"start:discord": "node --import tsx ./src/discord.ts",
|
||||
"start:json": "node --import tsx ./src/json.ts",
|
||||
"start:obsidian": "node --import tsx ./src/obsidian.ts",
|
||||
@@ -20,7 +17,6 @@
|
||||
"start:excel": "node --import tsx ./src/excel.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@llamaindex/cloud": "workspace:* || ^2.0.24",
|
||||
"@llamaindex/excel": "workspace:*",
|
||||
"@llamaindex/readers": "workspace:* || ^1.0.25",
|
||||
"@notionhq/client": "^4.0.0",
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import { Language, LlamaParseReader } from "@llamaindex/cloud";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
type LlamaParseReaderParams = Partial<
|
||||
Omit<LlamaParseReader, "language" | "apiKey">
|
||||
> & {
|
||||
language?: Language | Language[] | undefined;
|
||||
apiKey?: string | undefined;
|
||||
};
|
||||
|
||||
async function main() {
|
||||
const filePath = "../data/pto_policy_employee.docx";
|
||||
if (!fs.existsSync(filePath)) {
|
||||
console.error(`File ${filePath} does not exist`);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log(`File ${filePath} exists`);
|
||||
}
|
||||
|
||||
const params: LlamaParseReaderParams = {
|
||||
verbose: true,
|
||||
parsingInstruction:
|
||||
"Extract the text from the document a long with any images and tables. This is a document for a course and the contents of the images are important.",
|
||||
fastMode: false,
|
||||
gpt4oMode: true,
|
||||
useVendorMultimodalModel: true,
|
||||
vendorMultimodalModelName: "anthropic-sonnet-3.5",
|
||||
premiumMode: true,
|
||||
resultType: "markdown",
|
||||
apiKey: process.env.LLAMA_CLOUD_API_KEY,
|
||||
doNotCache: true,
|
||||
};
|
||||
|
||||
// set up the llamaparse reader
|
||||
const reader = new LlamaParseReader(params);
|
||||
|
||||
const buffer = fs.readFileSync(filePath);
|
||||
const documents = await reader.loadDataAsContent(
|
||||
new Uint8Array(buffer),
|
||||
path.basename(filePath),
|
||||
);
|
||||
|
||||
let allText = "";
|
||||
documents.forEach((doc) => {
|
||||
allText += doc.text;
|
||||
});
|
||||
|
||||
console.log(allText);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,72 +0,0 @@
|
||||
import { LlamaParseReader } from "@llamaindex/cloud";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import {
|
||||
Document,
|
||||
ImageNode,
|
||||
PromptTemplate,
|
||||
VectorStoreIndex,
|
||||
createMessageContent,
|
||||
} from "llamaindex";
|
||||
|
||||
const reader = new LlamaParseReader();
|
||||
async function main() {
|
||||
// Load PDF using LlamaParse JSON mode and return an array of json objects
|
||||
const jsonObjs = await reader.loadJson("../data/uber_10q_march_2022.pdf");
|
||||
// Access the first "pages" (=a single parsed file) object in the array
|
||||
const jsonList = jsonObjs[0]["pages"];
|
||||
|
||||
const textDocs = getTextDocs(jsonList);
|
||||
const imageTextDocs = await getImageTextDocs(jsonObjs);
|
||||
const documents = [...textDocs, ...imageTextDocs];
|
||||
// Split text, create embeddings and query the index
|
||||
const index = await VectorStoreIndex.fromDocuments(documents);
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const response = await queryEngine.query({
|
||||
query:
|
||||
"What does the bar graph titled 'Monthly Active Platform Consumers' show?",
|
||||
});
|
||||
|
||||
console.log(response.toString());
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
|
||||
// Extract and assign text and page number from jsonList, return an array of Document objects
|
||||
function getTextDocs(jsonList: { text: string; page: number }[]): Document[] {
|
||||
return jsonList.map(
|
||||
(page) => new Document({ text: page.text, metadata: { page: page.page } }),
|
||||
);
|
||||
}
|
||||
// Download all images from jsonObjs, send them to OpenAI API to get alt text, return an array of Document objects
|
||||
async function getImageTextDocs(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
jsonObjs: Record<string, any>[],
|
||||
): Promise<Document[]> {
|
||||
const llm = new OpenAI({
|
||||
model: "gpt-4o",
|
||||
temperature: 0.2,
|
||||
maxTokens: 1000,
|
||||
});
|
||||
const imageDicts = await reader.getImages(jsonObjs, "images");
|
||||
const imageDocs = [];
|
||||
|
||||
for (const imageDict of imageDicts) {
|
||||
const imageDoc = new ImageNode({ image: imageDict.path });
|
||||
const prompt = new PromptTemplate({
|
||||
template: `Describe the image as alt text`,
|
||||
});
|
||||
const message = await createMessageContent(prompt, [imageDoc]);
|
||||
|
||||
const response = await llm.complete({
|
||||
prompt: message,
|
||||
});
|
||||
|
||||
const doc = new Document({
|
||||
text: response.text,
|
||||
metadata: { path: imageDict.path },
|
||||
});
|
||||
imageDocs.push(doc);
|
||||
}
|
||||
|
||||
return imageDocs;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import { LlamaParseReader } from "@llamaindex/cloud/reader";
|
||||
import { openai, OpenAIEmbedding } from "@llamaindex/openai";
|
||||
import { Settings, VectorStoreIndex } from "llamaindex";
|
||||
|
||||
Settings.llm = openai({
|
||||
model: "gpt-4.1",
|
||||
});
|
||||
Settings.embedModel = new OpenAIEmbedding({
|
||||
model: "text-embedding-3-small",
|
||||
});
|
||||
|
||||
async function main() {
|
||||
// Load PDF using LlamaParse
|
||||
const reader = new LlamaParseReader({
|
||||
resultType: "markdown",
|
||||
baseUrl: "https://api.cloud.llamaindex.ai", // for EU use: https://api.cloud.eu.llamaindex.ai
|
||||
});
|
||||
const documents = await reader.loadData("../data/TOS.pdf");
|
||||
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const index = await VectorStoreIndex.fromDocuments(documents);
|
||||
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const response = await queryEngine.query({
|
||||
query: "What is the license grant in the TOS?",
|
||||
});
|
||||
|
||||
// Output response
|
||||
console.log(response.toString());
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,33 +0,0 @@
|
||||
import { LlamaParseReader } from "@llamaindex/cloud/reader";
|
||||
import { SimpleDirectoryReader } from "@llamaindex/readers/directory";
|
||||
import { VectorStoreIndex } from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
const reader = new SimpleDirectoryReader();
|
||||
|
||||
const docs = await reader.loadData({
|
||||
directoryPath: "../data/parallel", // brk-2022.pdf split into 6 parts
|
||||
numWorkers: 2,
|
||||
// set LlamaParse as the default reader for all file types. Set apiKey here or in environment variable LLAMA_CLOUD_API_KEY
|
||||
overrideReader: new LlamaParseReader({
|
||||
language: "en",
|
||||
resultType: "markdown",
|
||||
parsingInstruction:
|
||||
"The provided files is Berkshire Hathaway's 2022 Annual Report. They contain figures, tables and raw data. Capture the data in a structured format. Mathematical equation should be put out as LATEX markdown (between $$).",
|
||||
}),
|
||||
});
|
||||
|
||||
const index = await VectorStoreIndex.fromDocuments(docs);
|
||||
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const response = await queryEngine.query({
|
||||
query:
|
||||
"What is the general strategy for shareholder safety outlined in the report? Use a concrete example with numbers",
|
||||
});
|
||||
|
||||
// Output response
|
||||
console.log(response.toString());
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,5 +1,50 @@
|
||||
# @llamaindex/autotool
|
||||
|
||||
## 9.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 8.0.29
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8929dcf]
|
||||
- llamaindex@0.11.29
|
||||
|
||||
## 8.0.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 8.0.27
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.27
|
||||
|
||||
## 8.0.26
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.26
|
||||
|
||||
## 8.0.25
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- llamaindex@0.11.25
|
||||
|
||||
## 8.0.24
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.24
|
||||
|
||||
## 8.0.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,5 +1,57 @@
|
||||
# @llamaindex/autotool-01-node-example
|
||||
|
||||
## 0.0.138
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
- @llamaindex/autotool@9.0.0
|
||||
|
||||
## 0.0.137
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8929dcf]
|
||||
- llamaindex@0.11.29
|
||||
- @llamaindex/autotool@8.0.29
|
||||
|
||||
## 0.0.136
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
- @llamaindex/autotool@8.0.28
|
||||
|
||||
## 0.0.135
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.27
|
||||
- @llamaindex/autotool@8.0.27
|
||||
|
||||
## 0.0.134
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.26
|
||||
- @llamaindex/autotool@8.0.26
|
||||
|
||||
## 0.0.133
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- llamaindex@0.11.25
|
||||
- @llamaindex/autotool@8.0.25
|
||||
|
||||
## 0.0.132
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.24
|
||||
- @llamaindex/autotool@8.0.24
|
||||
|
||||
## 0.0.131
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -13,5 +13,5 @@
|
||||
"scripts": {
|
||||
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
|
||||
},
|
||||
"version": "0.0.131"
|
||||
"version": "0.0.138"
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
|
||||
"directory": "packages/autotool"
|
||||
},
|
||||
"version": "8.0.23",
|
||||
"version": "9.0.0",
|
||||
"description": "auto transpile your JS function to LLM Agent compatible",
|
||||
"files": [
|
||||
"dist",
|
||||
|
||||
@@ -1,689 +0,0 @@
|
||||
# @llamaindex/cloud
|
||||
|
||||
## 4.0.27
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [f29799e]
|
||||
- Updated dependencies [7224c06]
|
||||
- @llamaindex/core@0.6.18
|
||||
|
||||
## 4.0.26
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [38da40b]
|
||||
- @llamaindex/core@0.6.17
|
||||
|
||||
## 4.0.25
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 2967d57: Default to \_public agent url id
|
||||
- Updated dependencies [a8ec08c]
|
||||
- @llamaindex/core@0.6.16
|
||||
|
||||
## 4.0.24
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7ad3411]
|
||||
- Updated dependencies [5da5b3c]
|
||||
- @llamaindex/core@0.6.15
|
||||
|
||||
## 4.0.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- a1b1598: fix: add generic types into agent data responses
|
||||
|
||||
## 4.0.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- d2be868: Bug fixes for new beta agent-data cloud API
|
||||
|
||||
## 4.0.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 579ca0c: chore: bump sdk version
|
||||
|
||||
## 4.0.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 48b0d88: fix: exports in `api` submodule
|
||||
- f185772: fix(cloud): missing file
|
||||
|
||||
## 4.0.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 5a0ed1f: feat: init agent api on cloud sdk
|
||||
- 5a0ed1f: feat: init agent api on cloud sdk
|
||||
- Updated dependencies [8eeac33]
|
||||
- @llamaindex/core@0.6.14
|
||||
|
||||
## 4.0.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 47a7555: chore: bump sdk version
|
||||
|
||||
## 4.0.17
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d578889]
|
||||
- Updated dependencies [0fcc92f]
|
||||
- Updated dependencies [515a8b9]
|
||||
- @llamaindex/core@0.6.13
|
||||
|
||||
## 4.0.16
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7039e1a]
|
||||
- Updated dependencies [7039e1a]
|
||||
- @llamaindex/core@0.6.12
|
||||
|
||||
## 4.0.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a89e187]
|
||||
- Updated dependencies [62699b7]
|
||||
- Updated dependencies [c5b2691]
|
||||
- Updated dependencies [d8ac8d3]
|
||||
- @llamaindex/core@0.6.11
|
||||
|
||||
## 4.0.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1b5af14]
|
||||
- @llamaindex/core@0.6.10
|
||||
|
||||
## 4.0.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [71598f8]
|
||||
- @llamaindex/core@0.6.9
|
||||
|
||||
## 4.0.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c927457]
|
||||
- @llamaindex/core@0.6.8
|
||||
|
||||
## 4.0.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 76ff23d: Fix pRetry not working with CommonJS
|
||||
|
||||
## 4.0.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [59601dd]
|
||||
- @llamaindex/core@0.6.7
|
||||
|
||||
## 4.0.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 3703f90: feat(parse): add upload API
|
||||
|
||||
## 4.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [680b529]
|
||||
- Updated dependencies [361a685]
|
||||
- @llamaindex/core@0.6.6
|
||||
|
||||
## 4.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 40f5f41: Improve the loadJson function in LlamaParseReader to align with loadData by allowing URL inputs. Ensures s3://, http://, and https:// paths are not treated as local file paths.
|
||||
- Updated dependencies [d671ed6]
|
||||
- @llamaindex/core@0.6.5
|
||||
|
||||
## 4.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [9b2e25a]
|
||||
- @llamaindex/core@0.6.4
|
||||
- @llamaindex/env@0.1.30
|
||||
|
||||
## 4.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 2225ffd: feat: bump llama cloud sdk
|
||||
|
||||
## 4.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3ee8c83]
|
||||
- @llamaindex/core@0.6.3
|
||||
|
||||
## 4.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 41191d0: fix(parse): file input
|
||||
|
||||
## 4.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [9c63f3f]
|
||||
- @llamaindex/core@0.6.2
|
||||
|
||||
## 4.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1b6f368]
|
||||
- Updated dependencies [eaf326e]
|
||||
- @llamaindex/core@0.6.1
|
||||
|
||||
## 4.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- bf56fc0: chore: bump sdk openapi.json
|
||||
- 5189b44: fix: add retry handling logic to parser reader and fix lint issues
|
||||
- Updated dependencies [21bebfc]
|
||||
- Updated dependencies [93bc0ff]
|
||||
- Updated dependencies [91a18e7]
|
||||
- Updated dependencies [5189b44]
|
||||
- @llamaindex/core@0.6.0
|
||||
|
||||
## 3.0.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 3.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [4bac71d]
|
||||
- @llamaindex/core@0.5.7
|
||||
|
||||
## 3.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [beb922b]
|
||||
- @llamaindex/env@0.1.29
|
||||
- @llamaindex/core@0.5.6
|
||||
|
||||
## 3.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [5668970]
|
||||
- @llamaindex/core@0.5.5
|
||||
|
||||
## 3.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ad3c7f1]
|
||||
- @llamaindex/core@0.5.4
|
||||
|
||||
## 3.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [cb021e7]
|
||||
- @llamaindex/core@0.5.3
|
||||
|
||||
## 3.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d952e68]
|
||||
- @llamaindex/core@0.5.2
|
||||
|
||||
## 3.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- c902fcb: chore: bump llamacloud openapi
|
||||
|
||||
## 3.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [cc50c9c]
|
||||
- @llamaindex/env@0.1.28
|
||||
- @llamaindex/core@0.5.1
|
||||
|
||||
## 3.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [6a4a737]
|
||||
- Updated dependencies [d924c63]
|
||||
- @llamaindex/core@0.5.0
|
||||
|
||||
## 2.0.24
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 1c908fd: Revert previous release (not working with CJS)
|
||||
- Updated dependencies [1c908fd]
|
||||
- @llamaindex/core@0.4.23
|
||||
- @llamaindex/env@0.1.27
|
||||
|
||||
## 2.0.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cb608b5: fix: bundle output incorrect
|
||||
- Updated dependencies [cb608b5]
|
||||
- @llamaindex/core@0.4.22
|
||||
- @llamaindex/env@0.1.26
|
||||
|
||||
## 2.0.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- d6c270e: feat: support pass project and org id to llama parse reader
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- @llamaindex/core@0.4.21
|
||||
|
||||
## 2.0.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 5dec9f9: chore: bump sdk deps version
|
||||
- fd9c829: chore: bump llamacloud openapi
|
||||
- Updated dependencies [d211b7a]
|
||||
- @llamaindex/core@0.4.20
|
||||
|
||||
## 2.0.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 012495b: chore: bump llamacloud sdk
|
||||
|
||||
## 2.0.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a9b5b99]
|
||||
- @llamaindex/core@0.4.19
|
||||
|
||||
## 2.0.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b504303]
|
||||
- Updated dependencies [e0f6cc3]
|
||||
- @llamaindex/env@0.1.25
|
||||
- @llamaindex/core@0.4.18
|
||||
|
||||
## 2.0.17
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3d1808b]
|
||||
- @llamaindex/core@0.4.17
|
||||
|
||||
## 2.0.16
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 8be4589: chore: bump version
|
||||
- Updated dependencies [8be4589]
|
||||
- @llamaindex/core@0.4.16
|
||||
- @llamaindex/env@0.1.24
|
||||
|
||||
## 2.0.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d2b2722]
|
||||
- @llamaindex/env@0.1.23
|
||||
- @llamaindex/core@0.4.15
|
||||
|
||||
## 2.0.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [969365c]
|
||||
- @llamaindex/env@0.1.22
|
||||
- @llamaindex/core@0.4.14
|
||||
|
||||
## 2.0.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 90d265c: chore: bump version
|
||||
- Updated dependencies [90d265c]
|
||||
- @llamaindex/core@0.4.13
|
||||
- @llamaindex/env@0.1.21
|
||||
|
||||
## 2.0.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ef4f63d]
|
||||
- @llamaindex/core@0.4.12
|
||||
|
||||
## 2.0.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [6d22fa2]
|
||||
- @llamaindex/core@0.4.11
|
||||
|
||||
## 2.0.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a7b0ac3]
|
||||
- Updated dependencies [c69605f]
|
||||
- @llamaindex/core@0.4.10
|
||||
|
||||
## 2.0.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7ae6eaa]
|
||||
- @llamaindex/core@0.4.9
|
||||
|
||||
## 2.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [f865c98]
|
||||
- @llamaindex/core@0.4.8
|
||||
|
||||
## 2.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d89ebe0]
|
||||
- Updated dependencies [fd8c882]
|
||||
- @llamaindex/core@0.4.7
|
||||
|
||||
## 2.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [4fc001c]
|
||||
- @llamaindex/env@0.1.20
|
||||
- @llamaindex/core@0.4.6
|
||||
|
||||
## 2.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ad85bd0]
|
||||
- @llamaindex/core@0.4.5
|
||||
- @llamaindex/env@0.1.19
|
||||
|
||||
## 2.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a8d3fa6]
|
||||
- @llamaindex/env@0.1.18
|
||||
- @llamaindex/core@0.4.4
|
||||
|
||||
## 2.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [95a5cc6]
|
||||
- @llamaindex/core@0.4.3
|
||||
|
||||
## 2.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [14cc9eb]
|
||||
- @llamaindex/env@0.1.17
|
||||
- @llamaindex/core@0.4.2
|
||||
|
||||
## 2.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [9c73f0a]
|
||||
- @llamaindex/core@0.4.1
|
||||
|
||||
## 2.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [359fd33]
|
||||
- Updated dependencies [efb7e1b]
|
||||
- Updated dependencies [98ba1e7]
|
||||
- Updated dependencies [620c63c]
|
||||
- @llamaindex/core@0.4.0
|
||||
|
||||
## 1.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [60b185f]
|
||||
- @llamaindex/core@0.3.7
|
||||
|
||||
## 1.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [691c5bc]
|
||||
- @llamaindex/core@0.3.6
|
||||
|
||||
## 1.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [fa60fc6]
|
||||
- @llamaindex/env@0.1.16
|
||||
- @llamaindex/core@0.3.5
|
||||
|
||||
## 1.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [e2a0876]
|
||||
- @llamaindex/core@0.3.4
|
||||
|
||||
## 1.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 06f632b: fix(cloud): allow filename in llama parse
|
||||
|
||||
## 1.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [0493f67]
|
||||
- @llamaindex/core@0.3.3
|
||||
|
||||
## 1.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [4ba2cfe]
|
||||
- @llamaindex/env@0.1.15
|
||||
- @llamaindex/core@0.3.2
|
||||
|
||||
## 1.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 4c38c1b: fix(cloud): do not detect file type in llama parse
|
||||
- 24d065f: Log Parse Job Errors when verbose is enabled
|
||||
- a75af83: refactor: move some llm and embedding to single package
|
||||
- Updated dependencies [ae49ff4]
|
||||
- Updated dependencies [a75af83]
|
||||
- @llamaindex/env@0.1.14
|
||||
- @llamaindex/core@0.3.1
|
||||
|
||||
## 1.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1364e8e]
|
||||
- Updated dependencies [96fc69c]
|
||||
- @llamaindex/core@0.3.0
|
||||
|
||||
## 0.2.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [5f67820]
|
||||
- @llamaindex/core@0.2.12
|
||||
|
||||
## 0.2.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ee697fb]
|
||||
- @llamaindex/core@0.2.11
|
||||
|
||||
## 0.2.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3489e7d]
|
||||
- Updated dependencies [468bda5]
|
||||
- @llamaindex/core@0.2.10
|
||||
|
||||
## 0.2.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 0b20ff9: fix: package.json format
|
||||
|
||||
## 0.2.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 981811e: fix(cloud): llama parse reader save image incorrectly
|
||||
|
||||
## 0.2.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- df441e2: fix: consoleLogger is missing from `@llamaindex/env`
|
||||
- Updated dependencies [df441e2]
|
||||
- @llamaindex/core@0.2.8
|
||||
- @llamaindex/env@0.1.13
|
||||
|
||||
## 0.2.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ac41ed3: feat: bump cloud sdk version
|
||||
|
||||
## 0.2.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- fb36eff: fix: backport for node.js 18
|
||||
|
||||
There could have one missing API in the node.js 18, so we need to backport it to make it work.
|
||||
|
||||
- d24d3d1: fix: print warning when llama parse reader has error
|
||||
- Updated dependencies [2cd1383]
|
||||
- @llamaindex/core@0.2.3
|
||||
|
||||
## 0.2.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- b42adeb: fix: get job result in llama parse reader
|
||||
- Updated dependencies [749b43a]
|
||||
- @llamaindex/core@0.2.2
|
||||
|
||||
## 0.2.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 85c2e19: feat: `@llamaindex/cloud` package update
|
||||
|
||||
- Bump to latest openapi schema
|
||||
- Move LlamaParse class from llamaindex, this will allow you use llamaparse in more non-node.js environment
|
||||
|
||||
- Updated dependencies [ac07e3c]
|
||||
- Updated dependencies [70ccb4a]
|
||||
- Updated dependencies [1a6137b]
|
||||
- Updated dependencies [ac07e3c]
|
||||
- @llamaindex/core@0.2.1
|
||||
- @llamaindex/env@0.1.11
|
||||
|
||||
## 0.2.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 4810364: fix: bump version
|
||||
|
||||
## 0.2.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 0bf8d80: fix: bump version
|
||||
|
||||
## 0.2.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 58abc57: fix: align version
|
||||
|
||||
## 0.2.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 1f680d7: chore: bump llamacloud api
|
||||
|
||||
## 0.2.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 3ed6acc: feat: cloud api change
|
||||
|
||||
## 0.1.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 36ddec4: fix: typo in custom page separator parameter for LlamaParse
|
||||
|
||||
## 0.1.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 1c444d5: feat(cloud): update openapi.json
|
||||
|
||||
## 0.1.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- f326ab8: chore: bump version
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 321c39d: fix: generate api as class
|
||||
@@ -1,9 +0,0 @@
|
||||
# @llamaindex/cloud
|
||||
|
||||
> LlamaCloud is a new generation of managed parsing, ingestion, and retrieval services, designed to bring production-grade context-augmentation to your LLM and RAG applications.
|
||||
|
||||
For more information, see the [API documentation](https://docs.cloud.llamaindex.ai/).
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": "./dist/index.js",
|
||||
"private": true
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import { defaultPlugins, defineConfig } from "@hey-api/openapi-ts";
|
||||
|
||||
export default defineConfig({
|
||||
// you can download this file to get the latest version of the OpenAPI document
|
||||
// @link https://api.cloud.llamaindex.ai/api/openapi.json
|
||||
input: "./openapi.json",
|
||||
output: {
|
||||
path: "./src/client",
|
||||
format: "prettier",
|
||||
lint: "eslint",
|
||||
},
|
||||
plugins: [
|
||||
...defaultPlugins,
|
||||
"@hey-api/client-fetch",
|
||||
"zod",
|
||||
"@hey-api/schemas",
|
||||
"@hey-api/sdk",
|
||||
{
|
||||
enums: "javascript",
|
||||
identifierCase: "PascalCase",
|
||||
name: "@hey-api/typescript",
|
||||
},
|
||||
],
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,97 +0,0 @@
|
||||
{
|
||||
"name": "@llamaindex/cloud",
|
||||
"version": "4.0.27",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"generate": "./node_modules/.bin/openapi-ts",
|
||||
"build": "pnpm run generate && bunchee",
|
||||
"dev": "bunchee --watch"
|
||||
},
|
||||
"files": [
|
||||
"openapi.json",
|
||||
"./api",
|
||||
"./reader",
|
||||
"./parse",
|
||||
"./beta/agent"
|
||||
],
|
||||
"exports": {
|
||||
"./openapi.json": "./openapi.json",
|
||||
"./beta/agent": {
|
||||
"require": {
|
||||
"types": "./beta/agent/dist/index.d.cts",
|
||||
"default": "./beta/agent/dist/index.cjs"
|
||||
},
|
||||
"import": {
|
||||
"types": "./beta/agent/dist/index.d.ts",
|
||||
"default": "./beta/agent/dist/index.js"
|
||||
},
|
||||
"default": "./beta/agent/dist/index.js"
|
||||
},
|
||||
"./api": {
|
||||
"require": {
|
||||
"types": "./api/dist/index.d.cts",
|
||||
"default": "./api/dist/index.cjs"
|
||||
},
|
||||
"import": {
|
||||
"types": "./api/dist/index.d.ts",
|
||||
"default": "./api/dist/index.js"
|
||||
},
|
||||
"default": "./api/dist/index.js"
|
||||
},
|
||||
"./reader": {
|
||||
"require": {
|
||||
"types": "./reader/dist/index.d.cts",
|
||||
"default": "./reader/dist/index.cjs"
|
||||
},
|
||||
"import": {
|
||||
"types": "./reader/dist/index.d.ts",
|
||||
"default": "./reader/dist/index.js"
|
||||
},
|
||||
"default": "./reader/dist/index.js"
|
||||
},
|
||||
"./parse": {
|
||||
"require": {
|
||||
"types": "./parse/dist/index.d.cts",
|
||||
"default": "./parse/dist/index.cjs"
|
||||
},
|
||||
"import": {
|
||||
"types": "./parse/dist/index.d.ts",
|
||||
"default": "./parse/dist/index.js"
|
||||
},
|
||||
"default": "./parse/dist/index.js"
|
||||
},
|
||||
".": {
|
||||
"require": {
|
||||
"types": "./reader/dist/index.d.cts",
|
||||
"default": "./reader/dist/index.cjs"
|
||||
},
|
||||
"import": {
|
||||
"types": "./reader/dist/index.d.ts",
|
||||
"default": "./reader/dist/index.js"
|
||||
},
|
||||
"default": "./reader/dist/index.js"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
|
||||
"directory": "packages/cloud"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@hey-api/client-fetch": "^0.10.1",
|
||||
"@hey-api/openapi-ts": "^0.67.5",
|
||||
"@llama-flow/core": "^0.4.1",
|
||||
"@llamaindex/core": "workspace:*",
|
||||
"@llamaindex/env": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@llama-flow/core": "^0.4.1",
|
||||
"@llamaindex/core": "workspace:*",
|
||||
"@llamaindex/env": "workspace:*"
|
||||
},
|
||||
"dependencies": {
|
||||
"p-retry": "^6.2.1",
|
||||
"zod": "^3.25.76"
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": "./dist/index.js",
|
||||
"private": true
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": "./dist/index.js",
|
||||
"private": true
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { client } from "./client/client.gen";
|
||||
|
||||
client.setConfig({
|
||||
baseUrl: "https://api.cloud.llamaindex.ai/",
|
||||
headers: {
|
||||
"X-SDK-Name": "llamaindex-ts",
|
||||
},
|
||||
});
|
||||
|
||||
export * from "./client";
|
||||
export { client };
|
||||
@@ -1,329 +0,0 @@
|
||||
import { createClient, createConfig } from "@hey-api/client-fetch";
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import {
|
||||
aggregateAgentDataApiV1BetaAgentDataAggregatePost,
|
||||
createAgentDataApiV1BetaAgentDataPost,
|
||||
deleteAgentDataApiV1BetaAgentDataItemIdDelete,
|
||||
getAgentDataApiV1BetaAgentDataItemIdGet,
|
||||
searchAgentDataApiV1BetaAgentDataSearchPost,
|
||||
updateAgentDataApiV1BetaAgentDataItemIdPut,
|
||||
type AgentData,
|
||||
type AggregateGroup,
|
||||
} from "../../client";
|
||||
import type {
|
||||
AggregateAgentDataOptions,
|
||||
SearchAgentDataOptions,
|
||||
TypedAgentData,
|
||||
TypedAgentDataItems,
|
||||
TypedAggregateGroup,
|
||||
TypedAggregateGroupItems,
|
||||
} from "./types";
|
||||
|
||||
/**
|
||||
* Async client for agent data operations
|
||||
*/
|
||||
export class AgentClient<T = unknown> {
|
||||
private client: ReturnType<typeof createClient>;
|
||||
private baseUrl: string;
|
||||
private headers: Record<string, string>;
|
||||
private collection: string;
|
||||
private agentUrlId: string;
|
||||
|
||||
constructor({
|
||||
apiKey = getEnv("LLAMA_CLOUD_API_KEY"),
|
||||
baseUrl = "https://api.cloud.llamaindex.ai/",
|
||||
collection = "default",
|
||||
agentUrlId = "_public",
|
||||
}: {
|
||||
apiKey?: string;
|
||||
baseUrl?: string;
|
||||
collection?: string;
|
||||
agentUrlId?: string;
|
||||
}) {
|
||||
this.baseUrl = baseUrl;
|
||||
|
||||
this.headers = {
|
||||
"X-SDK-Name": "llamaindex-ts",
|
||||
...(apiKey && { Authorization: `Bearer ${apiKey}` }),
|
||||
};
|
||||
|
||||
this.client = createClient(
|
||||
createConfig({
|
||||
baseUrl: this.baseUrl,
|
||||
headers: this.headers,
|
||||
}),
|
||||
);
|
||||
|
||||
this.collection = collection;
|
||||
this.agentUrlId = agentUrlId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new agent data
|
||||
*/
|
||||
async createItem(data: T): Promise<TypedAgentData<T>> {
|
||||
const response = await createAgentDataApiV1BetaAgentDataPost({
|
||||
throwOnError: true,
|
||||
body: {
|
||||
agent_slug: this.agentUrlId,
|
||||
collection: this.collection,
|
||||
data: data as Record<string, unknown>,
|
||||
},
|
||||
client: this.client,
|
||||
});
|
||||
|
||||
return this.transformResponse(response.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get agent data by ID
|
||||
*/
|
||||
async getItem(id: string): Promise<TypedAgentData<T> | null> {
|
||||
try {
|
||||
const response = await getAgentDataApiV1BetaAgentDataItemIdGet({
|
||||
throwOnError: true,
|
||||
path: { item_id: id },
|
||||
client: this.client,
|
||||
});
|
||||
|
||||
return this.transformResponse(response.data);
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
"response" in error &&
|
||||
(error as { response?: { status?: number } }).response?.status === 404
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update agent data
|
||||
*/
|
||||
async updateItem(id: string, data: T): Promise<TypedAgentData<T>> {
|
||||
const response = await updateAgentDataApiV1BetaAgentDataItemIdPut({
|
||||
throwOnError: true,
|
||||
path: { item_id: id },
|
||||
body: {
|
||||
data: data as Record<string, unknown>,
|
||||
},
|
||||
client: this.client,
|
||||
});
|
||||
|
||||
return this.transformResponse(response.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete agent data
|
||||
*/
|
||||
async deleteItem(id: string): Promise<void> {
|
||||
await deleteAgentDataApiV1BetaAgentDataItemIdDelete({
|
||||
throwOnError: true,
|
||||
path: { item_id: id },
|
||||
client: this.client,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Search agent data
|
||||
*/
|
||||
async search(
|
||||
options: SearchAgentDataOptions,
|
||||
): Promise<TypedAgentDataItems<T>> {
|
||||
const response = await searchAgentDataApiV1BetaAgentDataSearchPost({
|
||||
throwOnError: true,
|
||||
body: {
|
||||
agent_slug: this.agentUrlId,
|
||||
...(this.collection !== undefined && {
|
||||
collection: this.collection,
|
||||
}),
|
||||
...(options.filter !== undefined && { filter: options.filter }),
|
||||
...(options.orderBy !== undefined && { order_by: options.orderBy }),
|
||||
...(options.pageSize !== undefined && { page_size: options.pageSize }),
|
||||
...(options.offset !== undefined && { offset: options.offset }),
|
||||
...(options.includeTotal !== undefined && {
|
||||
include_total: options.includeTotal,
|
||||
}),
|
||||
},
|
||||
client: this.client,
|
||||
});
|
||||
|
||||
const result: TypedAgentDataItems<T> = {
|
||||
items: response.data.items.map((item: AgentData) =>
|
||||
this.transformResponse(item),
|
||||
),
|
||||
};
|
||||
|
||||
if (
|
||||
response.data.total_size !== null &&
|
||||
response.data.total_size !== undefined
|
||||
) {
|
||||
result.totalSize = response.data.total_size;
|
||||
}
|
||||
|
||||
if (
|
||||
response.data.next_page_token !== null &&
|
||||
response.data.next_page_token !== undefined
|
||||
) {
|
||||
result.nextPageToken = response.data.next_page_token;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregate agent data into groups
|
||||
*/
|
||||
async aggregate(
|
||||
options: AggregateAgentDataOptions,
|
||||
): Promise<TypedAggregateGroupItems<T>> {
|
||||
const response = await aggregateAgentDataApiV1BetaAgentDataAggregatePost({
|
||||
throwOnError: true,
|
||||
body: {
|
||||
agent_slug: this.agentUrlId,
|
||||
...(this.collection !== undefined && {
|
||||
collection: this.collection,
|
||||
}),
|
||||
...(options.filter !== undefined && { filter: options.filter }),
|
||||
...(options.groupBy !== undefined && { group_by: options.groupBy }),
|
||||
...(options.count !== undefined && { count: options.count }),
|
||||
...(options.first !== undefined && { first: options.first }),
|
||||
...(options.orderBy !== undefined && { order_by: options.orderBy }),
|
||||
...(options.offset !== undefined && { offset: options.offset }),
|
||||
...(options.pageSize !== undefined && { page_size: options.pageSize }),
|
||||
},
|
||||
client: this.client,
|
||||
});
|
||||
|
||||
const result: TypedAggregateGroupItems<T> = {
|
||||
items: response.data.items.map((item) =>
|
||||
this.transformAggregateResponse(item),
|
||||
),
|
||||
};
|
||||
|
||||
if (
|
||||
response.data.total_size !== null &&
|
||||
response.data.total_size !== undefined
|
||||
) {
|
||||
result.totalSize = response.data.total_size;
|
||||
}
|
||||
|
||||
if (
|
||||
response.data.next_page_token !== null &&
|
||||
response.data.next_page_token !== undefined
|
||||
) {
|
||||
result.nextPageToken = response.data.next_page_token;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform API response to typed data
|
||||
*/
|
||||
private transformResponse(data: AgentData): TypedAgentData<T> {
|
||||
const result: TypedAgentData<T> = {
|
||||
id: data.id!,
|
||||
agentUrlId: data.agent_slug,
|
||||
data: data.data as T,
|
||||
createdAt: new Date(data.created_at!),
|
||||
updatedAt: new Date(data.updated_at!),
|
||||
};
|
||||
|
||||
if (data.collection !== undefined) {
|
||||
result.collection = data.collection;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform API aggregate response to typed data
|
||||
*/
|
||||
private transformAggregateResponse(
|
||||
data: AggregateGroup,
|
||||
): TypedAggregateGroup<T> {
|
||||
const result: TypedAggregateGroup<T> = {
|
||||
groupKey: data.group_key,
|
||||
};
|
||||
|
||||
if (data.count !== null && data.count !== undefined) {
|
||||
result.count = data.count;
|
||||
}
|
||||
|
||||
if (data.first_item !== null && data.first_item !== undefined) {
|
||||
result.firstItem = data.first_item as T;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export interface AgentDataClientOptions<T = unknown> {
|
||||
/** API key for the client */
|
||||
apiKey?: string;
|
||||
/** Base URL for the client */
|
||||
/** Base URL of the llama cloud api */
|
||||
baseUrl?: string;
|
||||
/** If running in an agent runtime, optionally provide the window url to infer the agent url id */
|
||||
windowUrl?: string;
|
||||
/** Agent URL ID for the client, if not provided, it will be inferred from the window url, or fall back to "default" */
|
||||
agentUrlId?: string;
|
||||
/** Collection name for the client, defaults to "default" */
|
||||
collection?: string;
|
||||
}
|
||||
/**
|
||||
* Create a new AsyncAgentDataClient instance. Does it's best to infer an agent url id from environment.
|
||||
* Pass in the window url and/or env to infer the agent url id from them.
|
||||
* @param options - The options for the client
|
||||
* @returns A new AgentClient instance
|
||||
*/
|
||||
export function createAgentDataClient<T = unknown>({
|
||||
apiKey,
|
||||
baseUrl,
|
||||
windowUrl,
|
||||
env,
|
||||
agentUrlId,
|
||||
collection = "default",
|
||||
}: {
|
||||
apiKey?: string;
|
||||
baseUrl?: string;
|
||||
windowUrl?: string;
|
||||
env?: Record<string, string>;
|
||||
agentUrlId?: string;
|
||||
collection?: string;
|
||||
} = {}): AgentClient<T> {
|
||||
if (env && !agentUrlId) {
|
||||
agentUrlId =
|
||||
env.LLAMA_DEPLOY_DEPLOYMENT_NAME ||
|
||||
env.NEXT_PUBLIC_LLAMA_DEPLOY_DEPLOYMENT_NAME ||
|
||||
env.VITE_LLAMA_DEPLOY_DEPLOYMENT_NAME;
|
||||
}
|
||||
if (windowUrl && !agentUrlId) {
|
||||
try {
|
||||
const url = new URL(windowUrl);
|
||||
const path = url.pathname;
|
||||
const isLocalhost = // local agents should default to _public, otherwise a full deployment is required
|
||||
url.hostname.includes("localhost") ||
|
||||
url.hostname.includes("127.0.0.1");
|
||||
if (path.startsWith("/deployments/") && !isLocalhost) {
|
||||
// /deployments/<agent-url-id>/ui/ -> ["", "deployments", "<agent-url-id>", "ui"]
|
||||
agentUrlId = path.split("/")[2];
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
"Failed to infer agent url id from window url, falling back to default",
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return new AgentClient({
|
||||
...(apiKey && { apiKey }),
|
||||
...(baseUrl && { baseUrl }),
|
||||
...(agentUrlId && { agentUrlId }),
|
||||
collection,
|
||||
});
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
export { AgentClient, createAgentDataClient } from "./client";
|
||||
|
||||
export type {
|
||||
AggregateAgentDataOptions,
|
||||
ComparisonOperator,
|
||||
ExtractedData,
|
||||
FilterOperation,
|
||||
SearchAgentDataOptions,
|
||||
StatusType,
|
||||
TypedAgentData,
|
||||
TypedAgentDataItems,
|
||||
TypedAggregateGroup,
|
||||
TypedAggregateGroupItems,
|
||||
} from "./types";
|
||||
|
||||
export { StatusType as StatusTypeEnum } from "./types";
|
||||
@@ -1,138 +0,0 @@
|
||||
import type { FilterOperation as RawFilterOperation } from "../../client/types.gen";
|
||||
/**
|
||||
* Status types for agent data processing
|
||||
*/
|
||||
export const StatusType = {
|
||||
ERROR: "error",
|
||||
ACCEPTED: "accepted",
|
||||
REJECTED: "rejected",
|
||||
PENDING_REVIEW: "pending_review",
|
||||
} as const;
|
||||
|
||||
export type StatusType = (typeof StatusType)[keyof typeof StatusType];
|
||||
|
||||
export const ComparisonOperator = {
|
||||
GT: "gt",
|
||||
GTE: "gte",
|
||||
LT: "lt",
|
||||
LTE: "lte",
|
||||
EQ: "eq",
|
||||
INCLUDES: "includes",
|
||||
} as const;
|
||||
|
||||
export type ComparisonOperator =
|
||||
(typeof ComparisonOperator)[keyof typeof ComparisonOperator];
|
||||
|
||||
/**
|
||||
* Filter operation for searching/filtering agent data
|
||||
*/
|
||||
export type FilterOperation = RawFilterOperation;
|
||||
|
||||
/**
|
||||
* Base extracted data interface
|
||||
*/
|
||||
export interface ExtractedData<T = unknown> {
|
||||
/** The original data that was extracted from the document. For tracking changes. Should not be updated. */
|
||||
original_data: T;
|
||||
/** The latest state of the data. Will differ if data has been updated. */
|
||||
data?: T;
|
||||
/** The status of the extracted data. Prefer to use the StatusType values, but any string is allowed. */
|
||||
status: StatusType | string;
|
||||
/** Confidence scores, if any, for each primitive field in the original_data data. */
|
||||
confidence?: Record<string, unknown>;
|
||||
/** The ID of the file that was used to extract the data. */
|
||||
file_id?: string;
|
||||
/** The name of the file that was used to extract the data. */
|
||||
file_name?: string;
|
||||
/** The hash of the file that was used to extract the data. */
|
||||
file_hash?: string;
|
||||
/** Additional metadata about the extracted data, such as errors, tokens, etc. */
|
||||
metadata?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* TypedAgentData interface for typed agent data
|
||||
*/
|
||||
export interface TypedAgentData<T = unknown> {
|
||||
/** The unique ID of the agent data record. */
|
||||
id: string;
|
||||
/** The ID of the agent that created the data. */
|
||||
agentUrlId: string;
|
||||
/** The collection of the agent data. */
|
||||
collection?: string;
|
||||
/** The data of the agent data. Usually an ExtractedData<SomeOtherType> */
|
||||
data: T;
|
||||
/** The date and time the data was created. */
|
||||
createdAt: Date;
|
||||
/** The date and time the data was last updated. */
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paginated response of typed agent data items
|
||||
*/
|
||||
export interface TypedAgentDataItems<T = unknown> {
|
||||
items: TypedAgentData<T>[];
|
||||
totalSize?: number;
|
||||
nextPageToken?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for listing agent data
|
||||
*/
|
||||
export interface SearchAgentDataOptions {
|
||||
/** Filter options for the list. */
|
||||
filter?: Record<string, FilterOperation>;
|
||||
/** Order by options for the list. */
|
||||
orderBy?: string;
|
||||
/** Page size for the list. */
|
||||
pageSize?: number;
|
||||
/** Offset for the list. */
|
||||
offset?: number;
|
||||
/**
|
||||
* Whether to include the total number of items in the response.
|
||||
* Should use only for first request to build total pagination, and not subsequent requests.
|
||||
*/
|
||||
includeTotal?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for aggregating agent data
|
||||
*/
|
||||
export interface AggregateAgentDataOptions {
|
||||
/** Filter options for the aggregation. */
|
||||
filter?: Record<string, FilterOperation>;
|
||||
/** Fields to group by. */
|
||||
groupBy?: string[];
|
||||
/** Whether to count the number of items in each group. */
|
||||
count?: boolean;
|
||||
/** Whether to return the first item in each group. */
|
||||
first?: boolean;
|
||||
/** Order by options for the aggregation. */
|
||||
orderBy?: string;
|
||||
/** Offset for the aggregation. */
|
||||
offset?: number;
|
||||
/** Page size for the aggregation. */
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Single aggregation group result
|
||||
*/
|
||||
export interface TypedAggregateGroup<T = unknown> {
|
||||
/** The group key values */
|
||||
groupKey: Record<string, unknown>;
|
||||
/** Count of items in the group */
|
||||
count?: number;
|
||||
/** First item in the group */
|
||||
firstItem?: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paginated response of aggregated agent data
|
||||
*/
|
||||
export interface TypedAggregateGroupItems<T = unknown> {
|
||||
items: TypedAggregateGroup<T>[];
|
||||
totalSize?: number;
|
||||
nextPageToken?: string;
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
import { workflowEvent } from "@llama-flow/core";
|
||||
import { zodEvent } from "@llama-flow/core/util/zod";
|
||||
import { z } from "zod";
|
||||
import { parseFormSchema } from "./schema";
|
||||
|
||||
export const uploadEvent = zodEvent(
|
||||
parseFormSchema.merge(
|
||||
z.object({
|
||||
file: z
|
||||
.string()
|
||||
.or(z.instanceof(File))
|
||||
.or(z.instanceof(Blob))
|
||||
.or(z.instanceof(Uint8Array))
|
||||
.optional()
|
||||
.describe("input"),
|
||||
}),
|
||||
),
|
||||
{
|
||||
debugLabel: "upload",
|
||||
uniqueId: "52099967-34a8-419b-8950-c859eab60145",
|
||||
},
|
||||
);
|
||||
export const checkStatusEvent = workflowEvent<string>({
|
||||
debugLabel: "check-status",
|
||||
uniqueId: "462157fc-1ded-4ba7-9bc4-3e870395bd20",
|
||||
});
|
||||
export const checkStatusSuccessEvent = workflowEvent<string>({
|
||||
debugLabel: "check-status-success",
|
||||
uniqueId: "360b7641-30f7-456e-851d-104bb5e3f8d2",
|
||||
});
|
||||
export const requestMarkdownEvent = workflowEvent<string>({
|
||||
debugLabel: "markdown-request",
|
||||
uniqueId: "aa4c2e3c-0f09-4035-aab6-c72719c877cc",
|
||||
});
|
||||
export const requestTextEvent = workflowEvent<string>({
|
||||
debugLabel: "text-request",
|
||||
uniqueId: "6976536e-5399-4285-9455-0b70f1dfc92b",
|
||||
});
|
||||
export const requestJsonEvent = workflowEvent<string>({
|
||||
debugLabel: "json-request",
|
||||
uniqueId: "9fc4a330-52ad-4aac-8092-a650998b7f6f",
|
||||
});
|
||||
|
||||
export const markdownResultEvent = workflowEvent<string>({
|
||||
debugLabel: "markdown-result",
|
||||
uniqueId: "2dfb57c8-73d1-4394-bea8-f05246d934d4",
|
||||
});
|
||||
export const textResultEvent = workflowEvent<string>({
|
||||
debugLabel: "text-result",
|
||||
uniqueId: "a27deec6-b24f-4eda-a5ac-ba2fb2bf37c8",
|
||||
});
|
||||
export const jsonResultEvent = workflowEvent<unknown>({
|
||||
debugLabel: "json-result",
|
||||
uniqueId: "e086e6bd-a612-4f25-ab41-9b31dcb8af86",
|
||||
});
|
||||
@@ -1,225 +0,0 @@
|
||||
import { createClient, createConfig } from "@hey-api/client-fetch";
|
||||
import { createWorkflow, type InferWorkflowEventData } from "@llama-flow/core";
|
||||
import { createStatefulMiddleware } from "@llama-flow/core/middleware/state";
|
||||
import { withTraceEvents } from "@llama-flow/core/middleware/trace-events";
|
||||
import { pRetryHandler } from "@llama-flow/core/util/p-retry";
|
||||
import { fs, getEnv, path } from "@llamaindex/env";
|
||||
import {
|
||||
type BodyUploadFileApiV1ParsingUploadPost,
|
||||
getJobApiV1ParsingJobJobIdGet,
|
||||
getJobJsonResultApiV1ParsingJobJobIdResultJsonGet,
|
||||
getJobResultApiV1ParsingJobJobIdResultMarkdownGet,
|
||||
getJobTextResultApiV1ParsingJobJobIdResultTextGet,
|
||||
type StatusEnum,
|
||||
uploadFileApiV1ParsingUploadPost,
|
||||
} from "./client";
|
||||
import {
|
||||
checkStatusEvent,
|
||||
checkStatusSuccessEvent,
|
||||
jsonResultEvent,
|
||||
markdownResultEvent,
|
||||
requestJsonEvent,
|
||||
requestMarkdownEvent,
|
||||
requestTextEvent,
|
||||
textResultEvent,
|
||||
uploadEvent,
|
||||
} from "./events";
|
||||
|
||||
export type LlamaParseWorkflowParams = {
|
||||
region?: "us" | "eu" | "us-staging";
|
||||
apiKey?: string;
|
||||
};
|
||||
|
||||
const URLS = {
|
||||
us: "https://api.cloud.llamaindex.ai",
|
||||
eu: "https://api.cloud.eu.llamaindex.ai",
|
||||
"us-staging": "https://api.staging.llamaindex.ai",
|
||||
} as const;
|
||||
|
||||
const { withState, getContext } = createStatefulMiddleware(
|
||||
(params: LlamaParseWorkflowParams) => {
|
||||
const apiKey = params.apiKey ?? getEnv("LLAMA_CLOUD_API_KEY");
|
||||
const region = params.region ?? "us";
|
||||
if (!apiKey) {
|
||||
throw new Error("LLAMA_CLOUD_API_KEY is not set");
|
||||
}
|
||||
return {
|
||||
cache: {} as Record<string, StatusEnum>,
|
||||
client: createClient(
|
||||
createConfig({
|
||||
baseUrl: URLS[region],
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
}),
|
||||
),
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
const llamaParseWorkflow = withState(withTraceEvents(createWorkflow()));
|
||||
|
||||
llamaParseWorkflow.handle([uploadEvent], async ({ data: form }) => {
|
||||
const { state } = getContext();
|
||||
const finalForm = { ...form };
|
||||
if ("file" in form) {
|
||||
// support loads from the file system
|
||||
const file = form?.file;
|
||||
const isFilePath = typeof file === "string";
|
||||
const data = isFilePath ? await fs.readFile(file) : file;
|
||||
const filename: string | undefined = isFilePath
|
||||
? path.basename(file)
|
||||
: undefined;
|
||||
finalForm.file = data
|
||||
? globalThis.File && filename
|
||||
? new File([data], filename)
|
||||
: new Blob([data])
|
||||
: undefined;
|
||||
}
|
||||
const {
|
||||
data: { id, status },
|
||||
} = await uploadFileApiV1ParsingUploadPost({
|
||||
throwOnError: true,
|
||||
body: {
|
||||
...finalForm,
|
||||
} as BodyUploadFileApiV1ParsingUploadPost,
|
||||
client: state.client,
|
||||
});
|
||||
state.cache[id] = status;
|
||||
return checkStatusEvent.with(id);
|
||||
});
|
||||
|
||||
llamaParseWorkflow.handle(
|
||||
[checkStatusEvent],
|
||||
pRetryHandler(
|
||||
async ({ data: uuid }) => {
|
||||
const { state } = getContext();
|
||||
if (state.cache[uuid] === "SUCCESS") {
|
||||
return checkStatusSuccessEvent.with(uuid);
|
||||
}
|
||||
const {
|
||||
data: { status },
|
||||
} = await getJobApiV1ParsingJobJobIdGet({
|
||||
throwOnError: true,
|
||||
path: {
|
||||
job_id: uuid,
|
||||
},
|
||||
client: state.client,
|
||||
});
|
||||
state.cache[uuid] = status;
|
||||
if (status === "SUCCESS") {
|
||||
return checkStatusSuccessEvent.with(uuid);
|
||||
}
|
||||
throw new Error(`LLamaParse status: ${status}`);
|
||||
},
|
||||
{
|
||||
retries: 100,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
//#region sub workflow
|
||||
llamaParseWorkflow.handle([requestMarkdownEvent], async ({ data: job_id }) => {
|
||||
const { state } = getContext();
|
||||
const { data } = await getJobResultApiV1ParsingJobJobIdResultMarkdownGet({
|
||||
throwOnError: true,
|
||||
path: {
|
||||
job_id,
|
||||
},
|
||||
client: state.client,
|
||||
});
|
||||
return markdownResultEvent.with(data.markdown);
|
||||
});
|
||||
|
||||
llamaParseWorkflow.handle([requestTextEvent], async ({ data: job_id }) => {
|
||||
const { state } = getContext();
|
||||
const { data } = await getJobTextResultApiV1ParsingJobJobIdResultTextGet({
|
||||
throwOnError: true,
|
||||
path: {
|
||||
job_id,
|
||||
},
|
||||
client: state.client,
|
||||
});
|
||||
return textResultEvent.with(data.text);
|
||||
});
|
||||
|
||||
llamaParseWorkflow.handle([requestJsonEvent], async ({ data: job_id }) => {
|
||||
const { state } = getContext();
|
||||
const { data } = await getJobJsonResultApiV1ParsingJobJobIdResultJsonGet({
|
||||
throwOnError: true,
|
||||
path: {
|
||||
job_id,
|
||||
},
|
||||
client: state.client,
|
||||
});
|
||||
return jsonResultEvent.with(data.pages);
|
||||
});
|
||||
//#endregion
|
||||
|
||||
export type ParseJob = {
|
||||
get jobId(): string;
|
||||
get signal(): AbortSignal;
|
||||
get context(): ReturnType<typeof llamaParseWorkflow.createContext>;
|
||||
get form(): InferWorkflowEventData<typeof uploadEvent>;
|
||||
|
||||
markdown(): Promise<string>;
|
||||
text(): Promise<string>;
|
||||
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
json(): Promise<any[]>;
|
||||
};
|
||||
|
||||
export const upload = async (
|
||||
params: InferWorkflowEventData<typeof uploadEvent> & LlamaParseWorkflowParams,
|
||||
): Promise<ParseJob> => {
|
||||
//#region upload event
|
||||
const context = llamaParseWorkflow.createContext(params);
|
||||
const { stream, sendEvent } = context;
|
||||
const ev = uploadEvent.with(params);
|
||||
sendEvent(ev);
|
||||
|
||||
const uploadThread = await llamaParseWorkflow
|
||||
.substream(ev, stream)
|
||||
.until((ev) => checkStatusSuccessEvent.include(ev))
|
||||
.toArray();
|
||||
//#region
|
||||
const jobId: string = uploadThread.at(-1)!.data;
|
||||
return {
|
||||
get signal() {
|
||||
// lazy load
|
||||
return context.signal;
|
||||
},
|
||||
get jobId() {
|
||||
return jobId;
|
||||
},
|
||||
get form() {
|
||||
return ev.data;
|
||||
},
|
||||
get context() {
|
||||
return context;
|
||||
},
|
||||
async markdown(): Promise<string> {
|
||||
const requestEv = requestMarkdownEvent.with(jobId);
|
||||
const { sendEvent, stream } = llamaParseWorkflow.createContext(params);
|
||||
sendEvent(requestEv);
|
||||
const markdownThread = await stream.until(markdownResultEvent).toArray();
|
||||
return markdownThread.at(-1)!.data;
|
||||
},
|
||||
async text(): Promise<string> {
|
||||
const requestEv = requestTextEvent.with(jobId);
|
||||
const { sendEvent, stream } = llamaParseWorkflow.createContext(params);
|
||||
sendEvent(requestEv);
|
||||
const textThread = await stream.until(textResultEvent).toArray();
|
||||
return textThread.at(-1)!.data;
|
||||
},
|
||||
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async json(): Promise<any[]> {
|
||||
const requestEv = requestJsonEvent.with(jobId);
|
||||
const { sendEvent, stream } = llamaParseWorkflow.createContext(params);
|
||||
sendEvent(requestEv);
|
||||
const jsonThread = await stream
|
||||
.until((ev) => jsonResultEvent.include(ev))
|
||||
.toArray();
|
||||
return jsonThread.at(-1)!.data;
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -1,781 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { type Client, createClient, createConfig } from "@hey-api/client-fetch";
|
||||
import { Document, FileReader } from "@llamaindex/core/schema";
|
||||
import { fs, getEnv, path } from "@llamaindex/env";
|
||||
import {
|
||||
type BodyUploadFileApiParsingUploadPost,
|
||||
type FailPageMode,
|
||||
type ParserLanguages,
|
||||
type ParsingMode,
|
||||
getJobApiV1ParsingJobJobIdGet,
|
||||
getJobImageResultApiV1ParsingJobJobIdResultImageNameGet,
|
||||
getJobJsonResultApiV1ParsingJobJobIdResultJsonGet,
|
||||
getJobResultApiV1ParsingJobJobIdResultMarkdownGet,
|
||||
getJobTextResultApiV1ParsingJobJobIdResultTextGet,
|
||||
uploadFileApiV1ParsingUploadPost,
|
||||
} from "./api";
|
||||
import { sleep } from "./utils";
|
||||
|
||||
export type Language = ParserLanguages;
|
||||
export type ResultType = "text" | "markdown" | "json";
|
||||
|
||||
// Export the backoff pattern type.
|
||||
export type BackoffPattern = "constant" | "linear" | "exponential";
|
||||
|
||||
// TODO: should move into @llamaindex/env
|
||||
type WriteStream = {
|
||||
write: (text: string) => void;
|
||||
};
|
||||
|
||||
// Do not modify this variable or cause type errors
|
||||
// eslint-disable-next-line no-var
|
||||
var process: any;
|
||||
|
||||
/**
|
||||
* Represents a reader for parsing files using the LlamaParse API.
|
||||
* See https://github.com/run-llama/llama_parse
|
||||
*/
|
||||
export class LlamaParseReader extends FileReader {
|
||||
project_id?: string | undefined;
|
||||
organization_id?: string | undefined;
|
||||
// The API key for the LlamaParse API. Can be set as an environment variable: LLAMA_CLOUD_API_KEY
|
||||
apiKey: string;
|
||||
// The base URL of the Llama Cloud Platform.
|
||||
baseUrl: string = "https://api.cloud.llamaindex.ai";
|
||||
// The result type for the parser.
|
||||
resultType: ResultType = "text";
|
||||
// The interval in seconds to check if the parsing is done.
|
||||
checkInterval: number = 1;
|
||||
// The maximum timeout in seconds to wait for the parsing to finish.
|
||||
maxTimeout = 2000;
|
||||
// Whether to print the progress of the parsing.
|
||||
verbose = true;
|
||||
// The language to parse the file in.
|
||||
language: ParserLanguages[] = ["en"];
|
||||
|
||||
// New polling options:
|
||||
// Controls the backoff mode: "constant", "linear", or "exponential".
|
||||
backoffPattern: BackoffPattern = "linear";
|
||||
// Maximum interval in seconds between polls.
|
||||
maxCheckInterval: number = 5;
|
||||
// Maximum number of retryable errors before giving up.
|
||||
maxErrorCount: number = 4;
|
||||
|
||||
// The parsing instruction for the parser. Backend default is an empty string.
|
||||
parsingInstruction?: string | undefined;
|
||||
// Whether to ignore diagonal text (when the text rotation in degrees is not 0, 90, 180, or 270). Backend default is false.
|
||||
skipDiagonalText?: boolean | undefined;
|
||||
// Whether to ignore the cache and re-process the document. Documents are cached for 48 hours after job completion. Backend default is false.
|
||||
invalidateCache?: boolean | undefined;
|
||||
// Whether the document should not be cached. Backend default is false.
|
||||
doNotCache?: boolean | undefined;
|
||||
// Whether to use a faster mode to extract text (skipping OCR and table/heading reconstruction). Not compatible with gpt4oMode. Backend default is false.
|
||||
fastMode?: boolean | undefined;
|
||||
// Whether to keep columns in the text according to document layout. May reduce reconstruction accuracy and LLM/embedings performance.
|
||||
doNotUnrollColumns?: boolean | undefined;
|
||||
// A templated page separator for splitting text. If not set, default is "\n---\n".
|
||||
pageSeparator?: string | undefined;
|
||||
// A templated prefix to add at the beginning of each page.
|
||||
pagePrefix?: string | undefined;
|
||||
// A templated suffix to add at the end of each page.
|
||||
pageSuffix?: string | undefined;
|
||||
// Deprecated. Use vendorMultimodal params. Whether to use gpt-4o to extract text.
|
||||
gpt4oMode: boolean = false;
|
||||
// Deprecated. Use vendorMultimodal params. The API key for GPT-4o. Can be set via LLAMA_CLOUD_GPT4O_API_KEY.
|
||||
gpt4oApiKey?: string | undefined;
|
||||
// The bounding box margins as a string.
|
||||
boundingBox?: string | undefined;
|
||||
// The target pages (comma separated list, starting at 0).
|
||||
targetPages?: string | undefined;
|
||||
// Whether to ignore errors during parsing.
|
||||
ignoreErrors: boolean = true;
|
||||
// Whether to split by page using the pageSeparator (or "\n---\n" as default).
|
||||
splitByPage: boolean = true;
|
||||
// Whether to use the vendor multimodal API.
|
||||
useVendorMultimodalModel: boolean = false;
|
||||
// The model name for the vendor multimodal API.
|
||||
vendorMultimodalModelName?: string | undefined;
|
||||
// The API key for the multimodal API. Can be set via LLAMA_CLOUD_VENDOR_MULTIMODAL_API_KEY.
|
||||
vendorMultimodalApiKey?: string | undefined;
|
||||
|
||||
webhookUrl?: string | undefined;
|
||||
premiumMode?: boolean | undefined;
|
||||
takeScreenshot?: boolean | undefined;
|
||||
disableOcr?: boolean | undefined;
|
||||
disableReconstruction?: boolean | undefined;
|
||||
inputS3Path?: string | undefined;
|
||||
outputS3PathPrefix?: string | undefined;
|
||||
continuousMode?: boolean | undefined;
|
||||
isFormattingInstruction?: boolean | undefined;
|
||||
annotateLinks?: boolean | undefined;
|
||||
azureOpenaiDeploymentName?: string | undefined;
|
||||
azureOpenaiEndpoint?: string | undefined;
|
||||
azureOpenaiApiVersion?: string | undefined;
|
||||
azureOpenaiKey?: string | undefined;
|
||||
auto_mode?: boolean | undefined;
|
||||
auto_mode_trigger_on_image_in_page?: boolean | undefined;
|
||||
auto_mode_trigger_on_table_in_page?: boolean | undefined;
|
||||
auto_mode_trigger_on_text_in_page?: string | undefined;
|
||||
auto_mode_trigger_on_regexp_in_page?: string | undefined;
|
||||
bbox_bottom?: number | undefined;
|
||||
bbox_left?: number | undefined;
|
||||
bbox_right?: number | undefined;
|
||||
bbox_top?: number | undefined;
|
||||
disable_image_extraction?: boolean | undefined;
|
||||
extract_charts?: boolean | undefined;
|
||||
guess_xlsx_sheet_name?: boolean | undefined;
|
||||
html_make_all_elements_visible?: boolean | undefined;
|
||||
html_remove_fixed_elements?: boolean | undefined;
|
||||
html_remove_navigation_elements?: boolean | undefined;
|
||||
http_proxy?: string | undefined;
|
||||
input_url?: string | undefined;
|
||||
max_pages?: number | undefined;
|
||||
output_pdf_of_document?: boolean | undefined;
|
||||
structured_output?: boolean | undefined;
|
||||
structured_output_json_schema?: string | undefined;
|
||||
structured_output_json_schema_name?: string | undefined;
|
||||
extract_layout?: boolean | undefined;
|
||||
|
||||
// numWorkers is implemented in SimpleDirectoryReader
|
||||
stdout?: WriteStream | undefined;
|
||||
|
||||
readonly #client: Client;
|
||||
|
||||
output_tables_as_HTML: boolean = false;
|
||||
input_s3_region?: string | undefined;
|
||||
output_s3_region?: string | undefined;
|
||||
preserve_layout_alignment_across_pages?: boolean | undefined;
|
||||
spreadsheet_extract_sub_tables?: boolean | undefined;
|
||||
formatting_instruction?: string | undefined;
|
||||
parse_mode?: ParsingMode | undefined;
|
||||
system_prompt?: string | undefined;
|
||||
system_prompt_append?: string | undefined;
|
||||
user_prompt?: string | undefined;
|
||||
job_timeout_in_seconds?: number | undefined;
|
||||
job_timeout_extra_time_per_page_in_seconds?: number | undefined;
|
||||
strict_mode_image_extraction?: boolean | undefined;
|
||||
strict_mode_image_ocr?: boolean | undefined;
|
||||
strict_mode_reconstruction?: boolean | undefined;
|
||||
strict_mode_buggy_font?: boolean | undefined;
|
||||
ignore_document_elements_for_layout_detection?: boolean | undefined;
|
||||
complemental_formatting_instruction?: string | undefined;
|
||||
content_guideline_instruction?: string | undefined;
|
||||
adaptive_long_table?: boolean | undefined;
|
||||
model?: string | undefined;
|
||||
auto_mode_configuration_json?: string | undefined;
|
||||
compact_markdown_table?: boolean | undefined;
|
||||
markdown_table_multiline_header_separator?: string | undefined;
|
||||
page_error_tolerance?: number | undefined;
|
||||
replace_failed_page_mode?: FailPageMode | undefined;
|
||||
replace_failed_page_with_error_message_prefix?: string | undefined;
|
||||
replace_failed_page_with_error_message_suffix?: string | undefined;
|
||||
save_images?: boolean | undefined;
|
||||
preset?: string | undefined;
|
||||
high_res_ocr?: boolean | undefined;
|
||||
outlined_table_extraction?: boolean | undefined;
|
||||
hide_headers?: boolean | undefined;
|
||||
hide_footers?: boolean | undefined;
|
||||
page_header_prefix?: string | undefined;
|
||||
page_header_suffix?: string | undefined;
|
||||
page_footer_prefix?: string | undefined;
|
||||
page_footer_suffix?: string | undefined;
|
||||
merge_tables_across_pages_in_markdown?: boolean | undefined;
|
||||
|
||||
constructor(
|
||||
params: Partial<Omit<LlamaParseReader, "language" | "apiKey">> & {
|
||||
language?: ParserLanguages | ParserLanguages[] | undefined;
|
||||
apiKey?: string | undefined;
|
||||
} = {},
|
||||
) {
|
||||
super();
|
||||
Object.assign(this, params);
|
||||
this.language = Array.isArray(this.language)
|
||||
? this.language
|
||||
: [this.language];
|
||||
this.stdout =
|
||||
(params.stdout ?? typeof process !== "undefined")
|
||||
? process!.stdout
|
||||
: undefined;
|
||||
const apiKey = params.apiKey ?? getEnv("LLAMA_CLOUD_API_KEY");
|
||||
if (!apiKey) {
|
||||
throw new Error(
|
||||
"API Key is required for LlamaParseReader. Please pass the apiKey parameter or set the LLAMA_CLOUD_API_KEY environment variable.",
|
||||
);
|
||||
}
|
||||
this.apiKey = apiKey;
|
||||
if (this.baseUrl.endsWith("/")) {
|
||||
this.baseUrl = this.baseUrl.slice(0, -1);
|
||||
}
|
||||
if (this.baseUrl.endsWith("/api/parsing")) {
|
||||
this.baseUrl = this.baseUrl.slice(0, -"/api/parsing".length);
|
||||
}
|
||||
|
||||
if (params.gpt4oMode) {
|
||||
params.gpt4oApiKey =
|
||||
params.gpt4oApiKey ?? getEnv("LLAMA_CLOUD_GPT4O_API_KEY");
|
||||
|
||||
this.gpt4oApiKey = params.gpt4oApiKey;
|
||||
}
|
||||
if (params.useVendorMultimodalModel) {
|
||||
params.vendorMultimodalApiKey =
|
||||
params.vendorMultimodalApiKey ??
|
||||
getEnv("LLAMA_CLOUD_VENDOR_MULTIMODAL_API_KEY");
|
||||
|
||||
this.vendorMultimodalApiKey = params.vendorMultimodalApiKey;
|
||||
}
|
||||
|
||||
this.#client = createClient(
|
||||
createConfig({
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.apiKey}`,
|
||||
},
|
||||
baseUrl: this.baseUrl,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a job for the LlamaParse API.
|
||||
*
|
||||
* @param data - The file data as a Uint8Array.
|
||||
* @param filename - Optional filename for the file.
|
||||
* @returns A Promise resolving to the job ID as a string.
|
||||
*/
|
||||
async #createJob(
|
||||
data: Uint8Array | string,
|
||||
filename?: string,
|
||||
): Promise<string> {
|
||||
if (this.verbose) {
|
||||
console.log("Started uploading the file");
|
||||
}
|
||||
|
||||
let file: File | Blob | null = null;
|
||||
let input_s3_path: string | undefined = this.inputS3Path;
|
||||
let input_url: string | undefined = this.input_url;
|
||||
if (typeof data !== "string") {
|
||||
// TODO: remove Blob usage when we drop Node.js 18 support
|
||||
file =
|
||||
globalThis.File && filename
|
||||
? new File([data], filename)
|
||||
: new Blob([data]);
|
||||
} else if (data.startsWith("s3://")) {
|
||||
input_s3_path = data;
|
||||
} else if (data.startsWith("http://") || data.startsWith("https://")) {
|
||||
input_url = data;
|
||||
}
|
||||
|
||||
const body = {
|
||||
file,
|
||||
input_s3_path,
|
||||
input_url,
|
||||
language: this.language,
|
||||
parsing_instruction: this.parsingInstruction,
|
||||
skip_diagonal_text: this.skipDiagonalText,
|
||||
invalidate_cache: this.invalidateCache,
|
||||
do_not_cache: this.doNotCache,
|
||||
fast_mode: this.fastMode,
|
||||
do_not_unroll_columns: this.doNotUnrollColumns,
|
||||
page_separator: this.pageSeparator,
|
||||
page_prefix: this.pagePrefix,
|
||||
page_suffix: this.pageSuffix,
|
||||
gpt4o_mode: this.gpt4oMode,
|
||||
gpt4o_api_key: this.gpt4oApiKey,
|
||||
bounding_box: this.boundingBox,
|
||||
target_pages: this.targetPages,
|
||||
use_vendor_multimodal_model: this.useVendorMultimodalModel,
|
||||
vendor_multimodal_model_name: this.vendorMultimodalModelName,
|
||||
vendor_multimodal_api_key: this.vendorMultimodalApiKey,
|
||||
premium_mode: this.premiumMode,
|
||||
webhook_url: this.webhookUrl,
|
||||
take_screenshot: this.takeScreenshot,
|
||||
disable_ocr: this.disableOcr,
|
||||
disable_reconstruction: this.disableReconstruction,
|
||||
output_s3_path_prefix: this.outputS3PathPrefix,
|
||||
continuous_mode: this.continuousMode,
|
||||
is_formatting_instruction: this.isFormattingInstruction,
|
||||
annotate_links: this.annotateLinks,
|
||||
azure_openai_deployment_name: this.azureOpenaiDeploymentName,
|
||||
azure_openai_endpoint: this.azureOpenaiEndpoint,
|
||||
azure_openai_api_version: this.azureOpenaiApiVersion,
|
||||
azure_openai_key: this.azureOpenaiKey,
|
||||
auto_mode: this.auto_mode,
|
||||
auto_mode_trigger_on_image_in_page:
|
||||
this.auto_mode_trigger_on_image_in_page,
|
||||
auto_mode_trigger_on_table_in_page:
|
||||
this.auto_mode_trigger_on_table_in_page,
|
||||
auto_mode_trigger_on_text_in_page: this.auto_mode_trigger_on_text_in_page,
|
||||
auto_mode_trigger_on_regexp_in_page:
|
||||
this.auto_mode_trigger_on_regexp_in_page,
|
||||
bbox_bottom: this.bbox_bottom,
|
||||
bbox_left: this.bbox_left,
|
||||
bbox_right: this.bbox_right,
|
||||
bbox_top: this.bbox_top,
|
||||
disable_image_extraction: this.disable_image_extraction,
|
||||
extract_charts: this.extract_charts,
|
||||
guess_xlsx_sheet_name: this.guess_xlsx_sheet_name,
|
||||
html_make_all_elements_visible: this.html_make_all_elements_visible,
|
||||
html_remove_fixed_elements: this.html_remove_fixed_elements,
|
||||
html_remove_navigation_elements: this.html_remove_navigation_elements,
|
||||
http_proxy: this.http_proxy,
|
||||
max_pages: this.max_pages,
|
||||
output_pdf_of_document: this.output_pdf_of_document,
|
||||
structured_output: this.structured_output,
|
||||
structured_output_json_schema: this.structured_output_json_schema,
|
||||
structured_output_json_schema_name:
|
||||
this.structured_output_json_schema_name,
|
||||
extract_layout: this.extract_layout,
|
||||
output_tables_as_HTML: this.output_tables_as_HTML,
|
||||
input_s3_region: this.input_s3_region,
|
||||
output_s3_region: this.output_s3_region,
|
||||
preserve_layout_alignment_across_pages:
|
||||
this.preserve_layout_alignment_across_pages,
|
||||
spreadsheet_extract_sub_tables: this.spreadsheet_extract_sub_tables,
|
||||
formatting_instruction: this.formatting_instruction,
|
||||
parse_mode: this.parse_mode,
|
||||
system_prompt: this.system_prompt,
|
||||
system_prompt_append: this.system_prompt_append,
|
||||
user_prompt: this.user_prompt,
|
||||
job_timeout_in_seconds: this.job_timeout_in_seconds,
|
||||
job_timeout_extra_time_per_page_in_seconds:
|
||||
this.job_timeout_extra_time_per_page_in_seconds,
|
||||
strict_mode_image_extraction: this.strict_mode_image_extraction,
|
||||
strict_mode_image_ocr: this.strict_mode_image_ocr,
|
||||
strict_mode_reconstruction: this.strict_mode_reconstruction,
|
||||
strict_mode_buggy_font: this.strict_mode_buggy_font,
|
||||
ignore_document_elements_for_layout_detection:
|
||||
this.ignore_document_elements_for_layout_detection,
|
||||
complemental_formatting_instruction:
|
||||
this.complemental_formatting_instruction,
|
||||
content_guideline_instruction: this.content_guideline_instruction,
|
||||
adaptive_long_table: this.adaptive_long_table,
|
||||
model: this.model,
|
||||
auto_mode_configuration_json: this.auto_mode_configuration_json,
|
||||
compact_markdown_table: this.compact_markdown_table,
|
||||
markdown_table_multiline_header_separator:
|
||||
this.markdown_table_multiline_header_separator,
|
||||
page_error_tolerance: this.page_error_tolerance,
|
||||
replace_failed_page_mode: this.replace_failed_page_mode,
|
||||
replace_failed_page_with_error_message_prefix:
|
||||
this.replace_failed_page_with_error_message_prefix,
|
||||
replace_failed_page_with_error_message_suffix:
|
||||
this.replace_failed_page_with_error_message_suffix,
|
||||
save_images: this.save_images,
|
||||
preset: this.preset,
|
||||
high_res_ocr: this.high_res_ocr,
|
||||
outlined_table_extraction: this.outlined_table_extraction,
|
||||
hide_headers: this.hide_headers,
|
||||
hide_footers: this.hide_footers,
|
||||
page_header_prefix: this.page_header_prefix,
|
||||
page_header_suffix: this.page_header_suffix,
|
||||
page_footer_prefix: this.page_footer_prefix,
|
||||
page_footer_suffix: this.page_footer_suffix,
|
||||
merge_tables_across_pages_in_markdown:
|
||||
this.merge_tables_across_pages_in_markdown,
|
||||
} satisfies {
|
||||
[Key in keyof BodyUploadFileApiParsingUploadPost]-?:
|
||||
| BodyUploadFileApiParsingUploadPost[Key]
|
||||
| undefined;
|
||||
} as unknown as BodyUploadFileApiParsingUploadPost;
|
||||
|
||||
const response = await uploadFileApiV1ParsingUploadPost({
|
||||
client: this.#client,
|
||||
throwOnError: true,
|
||||
query: {
|
||||
project_id: this.project_id ?? null,
|
||||
organization_id: this.organization_id ?? null,
|
||||
},
|
||||
signal: AbortSignal.timeout(this.maxTimeout * 1000),
|
||||
body,
|
||||
});
|
||||
|
||||
return response.data.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the result of a parsing job.
|
||||
*
|
||||
* Uses a polling loop with retry logic. Each API call is retried
|
||||
* up to maxErrorCount times if it fails with a 5XX or socket error.
|
||||
* The delay between polls increases according to the specified backoffPattern ("constant", "linear", or "exponential"),
|
||||
* capped by maxCheckInterval.
|
||||
*
|
||||
* @param jobId - The job ID.
|
||||
* @param resultType - The type of result to fetch ("text", "json", or "markdown").
|
||||
* @returns A Promise resolving to the job result.
|
||||
*/
|
||||
private async getJobResult(
|
||||
jobId: string,
|
||||
resultType: "text" | "json" | "markdown",
|
||||
): Promise<any> {
|
||||
let tries = 0;
|
||||
let currentInterval = this.checkInterval;
|
||||
const { default: pRetry } = await import("p-retry");
|
||||
|
||||
while (true) {
|
||||
await sleep(currentInterval * 1000);
|
||||
|
||||
// Wraps the API call in a retry
|
||||
let result;
|
||||
try {
|
||||
result = await pRetry(
|
||||
() =>
|
||||
getJobApiV1ParsingJobJobIdGet({
|
||||
client: this.#client,
|
||||
throwOnError: true,
|
||||
path: { job_id: jobId },
|
||||
signal: AbortSignal.timeout(this.maxTimeout * 1000),
|
||||
}),
|
||||
{
|
||||
retries: this.maxErrorCount,
|
||||
onFailedAttempt: (error) => {
|
||||
// Retry only on 5XX or socket errors.
|
||||
const status = (error.cause as any)?.response?.status;
|
||||
if (
|
||||
!(
|
||||
(status && status >= 500 && status < 600) ||
|
||||
((error.cause as any)?.code &&
|
||||
((error.cause as any).code === "ECONNRESET" ||
|
||||
(error.cause as any).code === "ETIMEDOUT" ||
|
||||
(error.cause as any).code === "ECONNREFUSED"))
|
||||
)
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
if (this.verbose) {
|
||||
console.warn(
|
||||
`Attempting to get job ${jobId} result (attempt ${error.attemptNumber}) failed. Retrying...`,
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
);
|
||||
} catch (e: any) {
|
||||
throw new Error(
|
||||
`Max error count reached for job ${jobId}: ${e.message}`,
|
||||
);
|
||||
}
|
||||
|
||||
const { data } = result;
|
||||
const status = (data as Record<string, unknown>)["status"];
|
||||
|
||||
if (status === "SUCCESS") {
|
||||
let resultData;
|
||||
switch (resultType) {
|
||||
case "json": {
|
||||
resultData =
|
||||
await getJobJsonResultApiV1ParsingJobJobIdResultJsonGet({
|
||||
client: this.#client,
|
||||
throwOnError: true,
|
||||
path: { job_id: jobId },
|
||||
query: {
|
||||
organization_id: this.organization_id ?? null,
|
||||
},
|
||||
signal: AbortSignal.timeout(this.maxTimeout * 1000),
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "markdown": {
|
||||
resultData =
|
||||
await getJobResultApiV1ParsingJobJobIdResultMarkdownGet({
|
||||
client: this.#client,
|
||||
throwOnError: true,
|
||||
path: { job_id: jobId },
|
||||
query: {
|
||||
organization_id: this.organization_id ?? null,
|
||||
},
|
||||
signal: AbortSignal.timeout(this.maxTimeout * 1000),
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "text": {
|
||||
resultData =
|
||||
await getJobTextResultApiV1ParsingJobJobIdResultTextGet({
|
||||
client: this.#client,
|
||||
throwOnError: true,
|
||||
path: { job_id: jobId },
|
||||
query: {
|
||||
organization_id: this.organization_id ?? null,
|
||||
},
|
||||
signal: AbortSignal.timeout(this.maxTimeout * 1000),
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
return resultData.data;
|
||||
} else if (status === "PENDING") {
|
||||
if (this.verbose && tries % 10 === 0) {
|
||||
this.stdout?.write(".");
|
||||
}
|
||||
tries++;
|
||||
} else {
|
||||
if (this.verbose) {
|
||||
console.error(
|
||||
`Received error response ${status} for job ${jobId}. Got Error Code: ${data.error_code} and Error Message: ${data.error_message}`,
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`Failed to parse the file: ${jobId}, status: ${status}`,
|
||||
);
|
||||
}
|
||||
|
||||
// Adjust the polling interval based on the backoff pattern.
|
||||
if (this.backoffPattern === "exponential") {
|
||||
currentInterval = Math.min(currentInterval * 2, this.maxCheckInterval);
|
||||
} else if (this.backoffPattern === "linear") {
|
||||
currentInterval = Math.min(
|
||||
currentInterval + this.checkInterval,
|
||||
this.maxCheckInterval,
|
||||
);
|
||||
} else if (this.backoffPattern === "constant") {
|
||||
currentInterval = this.checkInterval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override async loadData(filePath?: string): Promise<Document[]> {
|
||||
if (!filePath) {
|
||||
if (this.input_url) {
|
||||
return this.loadDataAsContent(this.input_url, this.input_url);
|
||||
} else if (this.inputS3Path) {
|
||||
return this.loadDataAsContent(this.inputS3Path, this.inputS3Path);
|
||||
} else {
|
||||
throw new TypeError("File path is required");
|
||||
}
|
||||
} else {
|
||||
const data =
|
||||
filePath.startsWith("s3://") ||
|
||||
filePath.startsWith("http://") ||
|
||||
filePath.startsWith("https://")
|
||||
? filePath
|
||||
: await fs.readFile(filePath);
|
||||
return this.loadDataAsContent(data, filePath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from a file and returns an array of Document objects.
|
||||
* To be used with resultType "text" or "markdown".
|
||||
*
|
||||
* @param fileContent - The content of the file as a Uint8Array.
|
||||
* @param filename - Optional filename for the file.
|
||||
* @returns A Promise that resolves to an array of Document objects.
|
||||
*/
|
||||
async loadDataAsContent(
|
||||
fileContent: Uint8Array | string,
|
||||
filename?: string,
|
||||
): Promise<Document[]> {
|
||||
return this.#createJob(fileContent, filename)
|
||||
.then(async (jobId) => {
|
||||
if (this.verbose) {
|
||||
console.log(`Started parsing the file under job id ${jobId}`);
|
||||
}
|
||||
|
||||
// Return results as Document objects.
|
||||
const jobResults = await this.getJobResult(jobId, this.resultType);
|
||||
const resultText = jobResults[this.resultType];
|
||||
|
||||
// Split the text by separator if splitByPage is true.
|
||||
if (this.splitByPage) {
|
||||
return this.splitTextBySeparator(resultText);
|
||||
}
|
||||
|
||||
return [new Document({ text: resultText })];
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn(
|
||||
`Error while parsing the file with: ${error.message ?? error.detail}`,
|
||||
);
|
||||
if (this.ignoreErrors) {
|
||||
return [];
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from a file and returns an array of JSON objects.
|
||||
* To be used with resultType "json".
|
||||
*
|
||||
* @param filePathOrContent - The file path or the file content as a Uint8Array.
|
||||
* @returns A Promise that resolves to an array of JSON objects.
|
||||
*/
|
||||
async loadJson(
|
||||
filePathOrContent: string | Uint8Array,
|
||||
): Promise<Record<string, any>[]> {
|
||||
let jobId;
|
||||
const isFilePath =
|
||||
typeof filePathOrContent === "string" &&
|
||||
!(
|
||||
filePathOrContent.startsWith("s3://") ||
|
||||
filePathOrContent.startsWith("http://") ||
|
||||
filePathOrContent.startsWith("https://")
|
||||
);
|
||||
try {
|
||||
const data = isFilePath
|
||||
? await fs.readFile(filePathOrContent)
|
||||
: filePathOrContent;
|
||||
// Create a job for the file.
|
||||
jobId = await this.#createJob(
|
||||
data,
|
||||
isFilePath ? path.basename(filePathOrContent) : undefined,
|
||||
);
|
||||
if (this.verbose) {
|
||||
console.log(`Started parsing the file under job id ${jobId}`);
|
||||
}
|
||||
|
||||
// Return results as an array of JSON objects.
|
||||
const resultJson = await this.getJobResult(jobId, "json");
|
||||
resultJson.job_id = jobId;
|
||||
resultJson.file_path = isFilePath ? filePathOrContent : undefined;
|
||||
return [resultJson];
|
||||
} catch (e) {
|
||||
console.error(`Error while parsing the file under job id ${jobId}`, e);
|
||||
if (this.ignoreErrors) {
|
||||
return [];
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads and saves images from a given JSON result to a specified download path.
|
||||
* Currently only supports resultType "json".
|
||||
*
|
||||
* @param jsonResult - The JSON result containing image information.
|
||||
* @param downloadPath - The path where the downloaded images will be saved.
|
||||
* @returns A Promise that resolves to an array of image objects.
|
||||
*/
|
||||
async getImages(
|
||||
jsonResult: Record<string, any>[],
|
||||
downloadPath: string,
|
||||
): Promise<Record<string, any>[]> {
|
||||
try {
|
||||
// Create download directory if it doesn't exist (checks for write access).
|
||||
try {
|
||||
await fs.access(downloadPath);
|
||||
} catch {
|
||||
await fs.mkdir(downloadPath, { recursive: true });
|
||||
}
|
||||
|
||||
const images: Record<string, any>[] = [];
|
||||
for (const result of jsonResult) {
|
||||
const jobId = result.job_id;
|
||||
for (const page of result.pages) {
|
||||
if (this.verbose) {
|
||||
console.log(`> Image for page ${page.page}: ${page.images}`);
|
||||
}
|
||||
for (const image of page.images) {
|
||||
const imageName = image.name;
|
||||
const imagePath = await this.getImagePath(
|
||||
downloadPath,
|
||||
jobId,
|
||||
imageName,
|
||||
);
|
||||
await this.fetchAndSaveImage(imageName, imagePath, jobId);
|
||||
// Assign metadata to the image.
|
||||
image.path = imagePath;
|
||||
image.job_id = jobId;
|
||||
image.original_pdf_path = result.file_path;
|
||||
image.page_number = page.page;
|
||||
images.push(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
return images;
|
||||
} catch (e) {
|
||||
console.error(`Error while downloading images from the parsed result`, e);
|
||||
if (this.ignoreErrors) {
|
||||
return [];
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the file path for an image.
|
||||
*
|
||||
* @param downloadPath - The base download directory.
|
||||
* @param jobId - The job ID.
|
||||
* @param imageName - The image name.
|
||||
* @returns A Promise that resolves to the full image path.
|
||||
*/
|
||||
private async getImagePath(
|
||||
downloadPath: string,
|
||||
jobId: string,
|
||||
imageName: string,
|
||||
): Promise<string> {
|
||||
return path.join(downloadPath, `${jobId}-${imageName}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches an image from the API and saves it to the specified path.
|
||||
*
|
||||
* @param imageName - The name of the image.
|
||||
* @param imagePath - The local path to save the image.
|
||||
* @param jobId - The associated job ID.
|
||||
*/
|
||||
private async fetchAndSaveImage(
|
||||
imageName: string,
|
||||
imagePath: string,
|
||||
jobId: string,
|
||||
): Promise<void> {
|
||||
const response =
|
||||
await getJobImageResultApiV1ParsingJobJobIdResultImageNameGet({
|
||||
client: this.#client,
|
||||
path: {
|
||||
job_id: jobId,
|
||||
name: imageName,
|
||||
},
|
||||
});
|
||||
if (response.error) {
|
||||
throw new Error(`Failed to download image: ${response.error.detail}`);
|
||||
}
|
||||
const blob = (await response.data) as Blob;
|
||||
// Write the image buffer to the specified imagePath.
|
||||
await fs.writeFile(imagePath, new Uint8Array(await blob.arrayBuffer()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters out invalid values (null, undefined, empty string) for specific parameters.
|
||||
*
|
||||
* @param params - The parameters object.
|
||||
* @param keysToCheck - The keys to check for valid values.
|
||||
* @returns A new object with filtered parameters.
|
||||
*/
|
||||
private filterSpecificParams(
|
||||
params: Record<string, any>,
|
||||
keysToCheck: string[],
|
||||
): Record<string, any> {
|
||||
const filteredParams: Record<string, any> = {};
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (keysToCheck.includes(key)) {
|
||||
if (value !== null && value !== undefined && value !== "") {
|
||||
filteredParams[key] = value;
|
||||
}
|
||||
} else {
|
||||
filteredParams[key] = value;
|
||||
}
|
||||
}
|
||||
return filteredParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits text into Document objects using the page separator.
|
||||
*
|
||||
* @param text - The text to be split.
|
||||
* @returns An array of Document objects.
|
||||
*/
|
||||
private splitTextBySeparator(text: string): Document[] {
|
||||
const separator = this.pageSeparator ?? "\n---\n";
|
||||
const textChunks = text.split(separator);
|
||||
return textChunks.map(
|
||||
(docChunk: string) =>
|
||||
new Document({
|
||||
text: docChunk,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user