mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-09 11:25:43 -04:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 19e5c318a0 | |||
| d49301555f | |||
| f648bb7b90 | |||
| 06f884a437 | |||
| 9e66861d07 | |||
| ae74f70d7d |
@@ -122,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 }})
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
# @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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/doc",
|
||||
"version": "0.2.54",
|
||||
"version": "0.2.55",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"postinstall": "fumadocs-mdx",
|
||||
@@ -16,13 +16,13 @@
|
||||
"@huggingface/transformers": "^3.5.0",
|
||||
"@icons-pack/react-simple-icons": "^10.1.0",
|
||||
"@llamaindex/chat-ui-docs": "^0.1.0",
|
||||
"@llamaindex/cloud": "workspace:*",
|
||||
"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",
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
};
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,12 @@
|
||||
# @llamaindex/cloudflare-worker-agent-test
|
||||
|
||||
## 0.0.191
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.0.190
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/cloudflare-worker-agent-test",
|
||||
"version": "0.0.190",
|
||||
"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,563 +0,0 @@
|
||||
# @llamaindex/llama-parse-browser-test
|
||||
|
||||
## 0.0.87
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.1.3
|
||||
|
||||
## 0.0.86
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@4.1.2
|
||||
|
||||
## 0.0.85
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [4b51791]
|
||||
- @llamaindex/cloud@4.1.1
|
||||
|
||||
## 0.0.84
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- @llamaindex/cloud@4.1.0
|
||||
|
||||
## 0.0.83
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c3bf3c7]
|
||||
- @llamaindex/cloud@4.0.28
|
||||
|
||||
## 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.87",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "^6.3.6",
|
||||
"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,12 @@
|
||||
# @llamaindex/next-agent-test
|
||||
|
||||
## 0.1.191
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.1.190
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/next-agent-test",
|
||||
"version": "0.1.190",
|
||||
"version": "0.1.191",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# test-edge-runtime
|
||||
|
||||
## 0.1.190
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.1.189
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/nextjs-edge-runtime-test",
|
||||
"version": "0.1.189",
|
||||
"version": "0.1.190",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
# @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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/next-node-runtime-test",
|
||||
"version": "0.1.61",
|
||||
"version": "0.1.62",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# vite-import-llamaindex
|
||||
|
||||
## 0.0.57
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.0.56
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "vite-import-llamaindex",
|
||||
"private": true,
|
||||
"version": "0.0.56",
|
||||
"version": "0.0.57",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @llamaindex/waku-query-engine-test
|
||||
|
||||
## 0.0.191
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.0.190
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/waku-query-engine-test",
|
||||
"version": "0.0.190",
|
||||
"version": "0.0.191",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,58 @@
|
||||
# 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
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -13,6 +13,7 @@ const responseSchema = z.object({
|
||||
async function main() {
|
||||
const messages: ChatMessage[] = [];
|
||||
let toolCalls: ToolCall[] = [];
|
||||
let object: z.infer<typeof responseSchema> | undefined;
|
||||
do {
|
||||
const result = await llm.exec({
|
||||
messages: [
|
||||
@@ -27,13 +28,14 @@ async function main() {
|
||||
],
|
||||
responseFormat: responseSchema,
|
||||
});
|
||||
console.log(result.newMessages[0].content);
|
||||
object = result.object;
|
||||
messages.push(...result.newMessages);
|
||||
toolCalls = result.toolCalls;
|
||||
} while (toolCalls.length == 0);
|
||||
|
||||
console.log(messages[1].content);
|
||||
console.log(messages);
|
||||
console.log(toolCalls);
|
||||
console.log(object);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# local-settings
|
||||
|
||||
## 1.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
- @llamaindex/openai@0.4.20
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "local-settings",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"main": "index.js",
|
||||
"private": "true",
|
||||
"scripts": {
|
||||
@@ -15,8 +15,8 @@
|
||||
"typescript": "^5.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@llamaindex/openai": "^0.4.16",
|
||||
"@llamaindex/openai": "^0.4.20",
|
||||
"express": "^5.1.0",
|
||||
"llamaindex": "^0.11.26"
|
||||
"llamaindex": "^0.12.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { openai } from "@ai-sdk/openai";
|
||||
import { llamaindex } from "@llamaindex/vercel";
|
||||
import { stepCountIs, streamText } from "ai";
|
||||
import { Document, LlamaCloudIndex } from "llamaindex";
|
||||
import { LlamaCloudIndex } from "llama-cloud-services";
|
||||
import { Document } from "llamaindex";
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
async function main() {
|
||||
|
||||
+47
-47
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/examples",
|
||||
"version": "0.3.41",
|
||||
"version": "0.3.42",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
@@ -11,52 +11,52 @@
|
||||
"@azure/cosmos": "^4.1.1",
|
||||
"@azure/identity": "^4.4.1",
|
||||
"@azure/search-documents": "^12.1.0",
|
||||
"@llamaindex/anthropic": "^0.3.24",
|
||||
"@llamaindex/assemblyai": "^0.1.20",
|
||||
"@llamaindex/astra": "^0.0.35",
|
||||
"@llamaindex/azure": "^0.1.36",
|
||||
"@llamaindex/bm25-retriever": "^0.0.10",
|
||||
"@llamaindex/chroma": "^0.0.35",
|
||||
"@llamaindex/clip": "^0.0.75",
|
||||
"@llamaindex/cloud": "^4.1.3",
|
||||
"@llamaindex/cohere": "^0.0.35",
|
||||
"@llamaindex/core": "^0.6.21",
|
||||
"@llamaindex/deepinfra": "^0.0.75",
|
||||
"@llamaindex/deepseek": "^0.0.37",
|
||||
"@llamaindex/discord": "^0.1.20",
|
||||
"@llamaindex/elastic-search": "^0.1.21",
|
||||
"@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.28",
|
||||
"@llamaindex/fireworks": "^0.0.35",
|
||||
"@llamaindex/google": "^0.3.21",
|
||||
"@llamaindex/groq": "^0.0.91",
|
||||
"@llamaindex/huggingface": "^0.1.29",
|
||||
"@llamaindex/jinaai": "^0.0.35",
|
||||
"@llamaindex/milvus": "^0.1.30",
|
||||
"@llamaindex/mistral": "^0.1.21",
|
||||
"@llamaindex/mixedbread": "^0.0.35",
|
||||
"@llamaindex/mongodb": "^0.0.36",
|
||||
"@llamaindex/node-parser": "^2.0.21",
|
||||
"@llamaindex/notion": "^0.1.20",
|
||||
"@llamaindex/ollama": "^0.1.22",
|
||||
"@llamaindex/openai": "^0.4.19",
|
||||
"@llamaindex/perplexity": "^0.0.32",
|
||||
"@llamaindex/pinecone": "^0.1.21",
|
||||
"@llamaindex/portkey-ai": "^0.0.63",
|
||||
"@llamaindex/postgres": "^0.0.64",
|
||||
"@llamaindex/qdrant": "^0.1.31",
|
||||
"@llamaindex/readers": "^3.1.20",
|
||||
"@llamaindex/replicate": "^0.0.63",
|
||||
"@llamaindex/supabase": "^0.1.22",
|
||||
"@llamaindex/together": "^0.0.35",
|
||||
"@llamaindex/tools": "^0.1.11",
|
||||
"@llamaindex/upstash": "^0.0.35",
|
||||
"@llamaindex/vercel": "^0.1.21",
|
||||
"@llamaindex/vllm": "^0.0.61",
|
||||
"@llamaindex/voyage-ai": "^1.0.27",
|
||||
"@llamaindex/weaviate": "^0.0.36",
|
||||
"@llamaindex/workflow": "^1.1.23",
|
||||
"@llamaindex/xai": "^0.0.22",
|
||||
"@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",
|
||||
@@ -65,7 +65,7 @@
|
||||
"commander": "^12.1.0",
|
||||
"dotenv": "^17.2.0",
|
||||
"js-tiktoken": "^1.0.14",
|
||||
"llamaindex": "^0.11.29",
|
||||
"llamaindex": "^0.12.0",
|
||||
"mongodb": "6.7.0",
|
||||
"postgres": "^3.4.4",
|
||||
"wikipedia": "^2.1.2",
|
||||
|
||||
@@ -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,12 @@
|
||||
# @llamaindex/autotool
|
||||
|
||||
## 9.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 8.0.29
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# @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
|
||||
|
||||
@@ -13,5 +13,5 @@
|
||||
"scripts": {
|
||||
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
|
||||
},
|
||||
"version": "0.0.137"
|
||||
"version": "0.0.138"
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
|
||||
"directory": "packages/autotool"
|
||||
},
|
||||
"version": "8.0.29",
|
||||
"version": "9.0.0",
|
||||
"description": "auto transpile your JS function to LLM Agent compatible",
|
||||
"files": [
|
||||
"dist",
|
||||
|
||||
@@ -1,723 +0,0 @@
|
||||
# @llamaindex/cloud
|
||||
|
||||
## 4.1.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [5da1cda]
|
||||
- @llamaindex/core@0.6.21
|
||||
|
||||
## 4.1.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [0267bb0]
|
||||
- @llamaindex/core@0.6.20
|
||||
|
||||
## 4.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 4b51791: Add deprecation to README
|
||||
|
||||
## 4.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 049471b: Add deprecation warning
|
||||
|
||||
## 4.0.28
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- c3bf3c7: Adding support for citations to beta agent data schema
|
||||
- Updated dependencies [f9f1de9]
|
||||
- @llamaindex/core@0.6.19
|
||||
|
||||
## 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,10 +0,0 @@
|
||||
# @llamaindex/cloud
|
||||
|
||||
> [!WARNING]
|
||||
> This package has been deprecated since version 4.1.0.
|
||||
> Please migrate to [llama-cloud-services](https://www.npmjs.com/package/llama-cloud-services).
|
||||
> See the 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,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.1.3",
|
||||
"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,18 +0,0 @@
|
||||
// Deprecation warning
|
||||
console.warn(`
|
||||
The package @llamaindex/cloud has been deprecated since version 4.1.0
|
||||
* Please migrate to llama-cloud-services.
|
||||
* See the documentation: https://docs.cloud.llamaindex.ai
|
||||
`);
|
||||
|
||||
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,23 +0,0 @@
|
||||
// Deprecation warning
|
||||
console.warn(`
|
||||
The package @llamaindex/cloud has been deprecated since version 4.1.0
|
||||
* Please migrate to llama-cloud-services.
|
||||
* See the documentation: https://docs.cloud.llamaindex.ai
|
||||
`);
|
||||
|
||||
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,163 +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;
|
||||
|
||||
/**
|
||||
* Metadata for an extracted field, including confidence and citation information
|
||||
*/
|
||||
export interface ExtractedFieldMetadata {
|
||||
/** The confidence score for the field, combined with parsing confidence if applicable */
|
||||
confidence?: number;
|
||||
/** The confidence score for the field based on the extracted text only */
|
||||
extracted_confidence?: number;
|
||||
/** The page number that the field occurred on */
|
||||
page_number?: number;
|
||||
/** The original text this field's value was derived from */
|
||||
matching_text?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dictionary mapping field names to their metadata
|
||||
* Values can be ExtractedFieldMetadata objects, nested dictionaries, or arrays
|
||||
*/
|
||||
export type ExtractedFieldMetadataDict = Record<
|
||||
string,
|
||||
ExtractedFieldMetadata | Record<string, unknown> | unknown[]
|
||||
>;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
/** The overall confidence score for the extracted data. */
|
||||
overall_confidence?: number;
|
||||
/** Page links, and perhaps eventually bounding boxes, for individual fields in the extracted data. */
|
||||
field_metadata?: ExtractedFieldMetadataDict;
|
||||
/** 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,232 +0,0 @@
|
||||
// Deprecation warning
|
||||
console.warn(`
|
||||
The package @llamaindex/cloud has been deprecated since version 4.1.0
|
||||
* Please migrate to llama-cloud-services.
|
||||
* See the documentation: https://docs.cloud.llamaindex.ai
|
||||
`);
|
||||
|
||||
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,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
import { FailPageMode, ParserLanguages, ParsingMode } from "./client";
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
type Language = ParserLanguages;
|
||||
const VALUES: [Language, ...Language[]] = [
|
||||
ParserLanguages.EN,
|
||||
...Object.values(ParserLanguages),
|
||||
];
|
||||
const languageSchema = z.enum(VALUES);
|
||||
|
||||
const PARSE_PRESETS = [
|
||||
"fast",
|
||||
"balanced",
|
||||
"premium",
|
||||
"structured",
|
||||
"auto",
|
||||
"scientific",
|
||||
"invoice",
|
||||
"slides",
|
||||
"_carlyle",
|
||||
] as const;
|
||||
|
||||
export const parsePresetSchema = z.enum(PARSE_PRESETS);
|
||||
|
||||
export const parseFormSchema = z.object({
|
||||
adaptive_long_table: z.boolean().optional(),
|
||||
annotate_links: z.boolean().optional(),
|
||||
auto_mode: z.boolean().optional(),
|
||||
auto_mode_trigger_on_image_in_page: z.boolean().optional(),
|
||||
auto_mode_trigger_on_table_in_page: z.boolean().optional(),
|
||||
auto_mode_trigger_on_text_in_page: z.string().optional(),
|
||||
auto_mode_trigger_on_regexp_in_page: z.string().optional(),
|
||||
auto_mode_configuration_json: z.string().optional(),
|
||||
azure_openai_api_version: z.string().optional(),
|
||||
azure_openai_deployment_name: z.string().optional(),
|
||||
azure_openai_endpoint: z.string().optional(),
|
||||
azure_openai_key: z.string().optional(),
|
||||
bbox_bottom: z.number().min(0).max(1).optional(),
|
||||
bbox_left: z.number().min(0).max(1).optional(),
|
||||
bbox_right: z.number().min(0).max(1).optional(),
|
||||
bbox_top: z.number().min(0).max(1).optional(),
|
||||
disable_ocr: z.boolean().optional(),
|
||||
disable_reconstruction: z.boolean().optional(),
|
||||
disable_image_extraction: z.boolean().optional(),
|
||||
do_not_cache: z.coerce.boolean().optional(),
|
||||
do_not_unroll_columns: z.coerce.boolean().optional(),
|
||||
extract_charts: z.boolean().optional(),
|
||||
guess_xlsx_sheet_name: z.boolean().optional(),
|
||||
html_make_all_elements_visible: z.boolean().optional(),
|
||||
html_remove_fixed_elements: z.boolean().optional(),
|
||||
html_remove_navigation_elements: z.boolean().optional(),
|
||||
http_proxy: z
|
||||
.string()
|
||||
.url(
|
||||
'Set a valid URL for the HTTP proxy, e.g., "http://proxy.example.com:8080"',
|
||||
)
|
||||
.refine(
|
||||
(url) => {
|
||||
try {
|
||||
const parsedUrl = new URL(url);
|
||||
return (
|
||||
parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:"
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
{
|
||||
message: "Invalid HTTP proxy URL",
|
||||
},
|
||||
)
|
||||
.optional(),
|
||||
input_s3_path: z.string().optional(),
|
||||
input_s3_region: z.string().optional(),
|
||||
input_url: z.string().optional(),
|
||||
invalidate_cache: z.boolean().optional(),
|
||||
language: z.array(languageSchema).optional(),
|
||||
extract_layout: z.boolean().optional(),
|
||||
max_pages: z.number().nullable().optional(),
|
||||
output_pdf_of_document: z.boolean().optional(),
|
||||
output_s3_path_prefix: z.string().optional(),
|
||||
output_s3_region: z.string().optional(),
|
||||
page_prefix: z.string().optional(),
|
||||
page_separator: z.string().optional(),
|
||||
page_suffix: z.string().optional(),
|
||||
preserve_layout_alignment_across_pages: z.boolean().optional(),
|
||||
skip_diagonal_text: z.boolean().optional(),
|
||||
spreadsheet_extract_sub_tables: z.boolean().optional(),
|
||||
structured_output: z.boolean().optional(),
|
||||
structured_output_json_schema: z.string().optional(),
|
||||
structured_output_json_schema_name: z.string().optional(),
|
||||
take_screenshot: z.boolean().optional(),
|
||||
target_pages: z.string().optional(),
|
||||
vendor_multimodal_api_key: z.string().optional(),
|
||||
vendor_multimodal_model_name: z.string().optional(),
|
||||
model: z.string().optional(),
|
||||
webhook_url: z.string().url().optional(),
|
||||
parse_mode: z.nativeEnum(ParsingMode).nullable().optional(),
|
||||
system_prompt: z.string().optional(),
|
||||
system_prompt_append: z.string().optional(),
|
||||
user_prompt: z.string().optional(),
|
||||
job_timeout_in_seconds: z.number().optional(),
|
||||
job_timeout_extra_time_per_page_in_seconds: z.number().optional(),
|
||||
strict_mode_image_extraction: z.boolean().optional(),
|
||||
strict_mode_image_ocr: z.boolean().optional(),
|
||||
strict_mode_reconstruction: z.boolean().optional(),
|
||||
strict_mode_buggy_font: z.boolean().optional(),
|
||||
save_images: z.boolean().optional(),
|
||||
ignore_document_elements_for_layout_detection: z.boolean().optional(),
|
||||
output_tables_as_HTML: z.boolean().optional(),
|
||||
use_vendor_multimodal_model: z.boolean().optional(),
|
||||
bounding_box: z.string().optional(),
|
||||
gpt4o_mode: z.boolean().optional(),
|
||||
gpt4o_api_key: z.string().optional(),
|
||||
complemental_formatting_instruction: z.string().optional(),
|
||||
content_guideline_instruction: z.string().optional(),
|
||||
premium_mode: z.boolean().optional(),
|
||||
is_formatting_instruction: z.boolean().optional(),
|
||||
continuous_mode: z.boolean().optional(),
|
||||
parsing_instruction: z.string().optional(),
|
||||
fast_mode: z.boolean().optional(),
|
||||
formatting_instruction: z.string().optional(),
|
||||
preset: parsePresetSchema.optional(),
|
||||
compact_markdown_table: z.boolean().optional(),
|
||||
markdown_table_multiline_header_separator: z.string().optional(),
|
||||
page_error_tolerance: z.number().min(0).max(1).optional(),
|
||||
replace_failed_page_mode: z.nativeEnum(FailPageMode).nullable().optional(),
|
||||
replace_failed_page_with_error_message_prefix: z.string().optional(),
|
||||
replace_failed_page_with_error_message_suffix: z.string().optional(),
|
||||
});
|
||||
@@ -1,3 +0,0 @@
|
||||
export async function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist/type",
|
||||
"tsBuildInfoFile": "./dist/.tsbuildinfo",
|
||||
"emitDeclarationOnly": true,
|
||||
"moduleResolution": "Bundler",
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"types": []
|
||||
},
|
||||
"include": ["./src"],
|
||||
"exclude": ["node_modules"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../core/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "../env/tsconfig.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"$schema": "https://turbo.build/schema.json",
|
||||
"extends": ["//"],
|
||||
"tasks": {
|
||||
"build": {
|
||||
"outputs": ["**/dist/**", "src/client/**"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
# @llamaindex/community
|
||||
|
||||
## 0.0.104
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [06f884a]
|
||||
- @llamaindex/core@0.6.22
|
||||
|
||||
## 0.0.103
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/community",
|
||||
"description": "Community package for LlamaIndexTS",
|
||||
"version": "0.0.103",
|
||||
"version": "0.0.104",
|
||||
"type": "module",
|
||||
"types": "dist/type/index.d.ts",
|
||||
"main": "dist/cjs/index.js",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @llamaindex/core
|
||||
|
||||
## 0.6.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 06f884a: feat: return structured object from llm.exec
|
||||
|
||||
## 0.6.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/core",
|
||||
"type": "module",
|
||||
"version": "0.6.21",
|
||||
"version": "0.6.22",
|
||||
"description": "LlamaIndex Core Module",
|
||||
"exports": {
|
||||
"./agent": {
|
||||
|
||||
@@ -3,8 +3,17 @@ import type { JSONObject } from "../global";
|
||||
import { tool } from "../tools/";
|
||||
import { extractText } from "../utils/llms";
|
||||
import { streamConverter } from "../utils/stream";
|
||||
import { isZodSchema, safeParseSchema } from "../zod";
|
||||
import { callToolToMessage, getToolCallsFromResponse } from "./tool-call";
|
||||
import {
|
||||
isZodSchema,
|
||||
safeParseSchema,
|
||||
type ZodInfer,
|
||||
type ZodSchema,
|
||||
} from "../zod";
|
||||
import {
|
||||
callToolToMessage,
|
||||
getToolCallsFromResponse,
|
||||
type CallToolToMessageResult,
|
||||
} from "./tool-call";
|
||||
import type {
|
||||
ChatMessage,
|
||||
ChatResponse,
|
||||
@@ -22,6 +31,8 @@ import type {
|
||||
ToolCallLLMMessageOptions,
|
||||
} from "./type";
|
||||
|
||||
const STRUCTURED_OUTPUT_TOOL_NAME = "format_output";
|
||||
|
||||
export abstract class BaseLLM<
|
||||
AdditionalChatOptions extends object = object,
|
||||
AdditionalMessageOptions extends object = object,
|
||||
@@ -77,33 +88,40 @@ export abstract class BaseLLM<
|
||||
>,
|
||||
): Promise<ChatResponse<AdditionalMessageOptions>>;
|
||||
|
||||
exec(
|
||||
exec<Z extends ZodSchema>(
|
||||
params: LLMChatParamsStreaming<
|
||||
AdditionalChatOptions,
|
||||
AdditionalMessageOptions
|
||||
AdditionalMessageOptions,
|
||||
Z
|
||||
>,
|
||||
): Promise<ExecStreamResponse<AdditionalMessageOptions>>;
|
||||
exec(
|
||||
): Promise<ExecStreamResponse<AdditionalMessageOptions, ZodInfer<Z>>>;
|
||||
exec<Z extends ZodSchema>(
|
||||
params: LLMChatParamsNonStreaming<
|
||||
AdditionalChatOptions,
|
||||
AdditionalMessageOptions
|
||||
AdditionalMessageOptions,
|
||||
Z
|
||||
>,
|
||||
): Promise<ExecResponse<AdditionalMessageOptions>>;
|
||||
async exec(
|
||||
): Promise<ExecResponse<AdditionalMessageOptions, ZodInfer<Z>>>;
|
||||
async exec<Z extends ZodSchema>(
|
||||
params:
|
||||
| LLMChatParamsStreaming<AdditionalChatOptions, AdditionalMessageOptions>
|
||||
| LLMChatParamsStreaming<
|
||||
AdditionalChatOptions,
|
||||
AdditionalMessageOptions,
|
||||
Z
|
||||
>
|
||||
| LLMChatParamsNonStreaming<
|
||||
AdditionalChatOptions,
|
||||
AdditionalMessageOptions
|
||||
AdditionalMessageOptions,
|
||||
Z
|
||||
>,
|
||||
): Promise<
|
||||
| ExecResponse<AdditionalMessageOptions>
|
||||
| ExecStreamResponse<AdditionalMessageOptions>
|
||||
| ExecResponse<AdditionalMessageOptions, ZodInfer<Z>>
|
||||
| ExecStreamResponse<AdditionalMessageOptions, ZodInfer<Z>>
|
||||
> {
|
||||
const responseFormat = params.responseFormat;
|
||||
if (typeof responseFormat != "undefined" && isZodSchema(responseFormat)) {
|
||||
const structuredTool = tool({
|
||||
name: "format_output",
|
||||
name: STRUCTURED_OUTPUT_TOOL_NAME,
|
||||
description: "Respond with a JSON object",
|
||||
parameters: responseFormat,
|
||||
execute: (args) => {
|
||||
@@ -133,31 +151,40 @@ export abstract class BaseLLM<
|
||||
const response = await this.chat(params);
|
||||
newMessages.push(response.message);
|
||||
const toolCalls = getToolCallsFromResponse(response);
|
||||
|
||||
let structuredOutput: ZodInfer<Z> | undefined = undefined;
|
||||
if (params.tools && toolCalls.length > 0) {
|
||||
for (const toolCall of toolCalls) {
|
||||
const toolResultMessage =
|
||||
await callToolToMessage<AdditionalMessageOptions>(
|
||||
params.tools,
|
||||
toolCall,
|
||||
logger,
|
||||
);
|
||||
const toolResultMessage = await callToolToMessage(
|
||||
params.tools,
|
||||
toolCall,
|
||||
logger,
|
||||
);
|
||||
if (toolResultMessage) {
|
||||
newMessages.push(toolResultMessage);
|
||||
newMessages.push(
|
||||
toolResultMessage as ChatMessage<AdditionalMessageOptions>,
|
||||
);
|
||||
}
|
||||
if (toolCall.name === STRUCTURED_OUTPUT_TOOL_NAME) {
|
||||
structuredOutput = toolResultMessage?.options?.toolResult
|
||||
?.result as ZodInfer<Z>;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
newMessages,
|
||||
toolCalls,
|
||||
object: structuredOutput,
|
||||
};
|
||||
}
|
||||
|
||||
async streamExec(
|
||||
async streamExec<Z extends ZodSchema>(
|
||||
params: LLMChatParamsStreaming<
|
||||
AdditionalChatOptions,
|
||||
AdditionalMessageOptions
|
||||
AdditionalMessageOptions,
|
||||
Z
|
||||
>,
|
||||
): Promise<ExecStreamResponse<AdditionalMessageOptions>> {
|
||||
): Promise<ExecStreamResponse<AdditionalMessageOptions, ZodInfer<Z>>> {
|
||||
const logger = params.logger ?? emptyLogger;
|
||||
const responseStream = await this.chat(params);
|
||||
const iterator = responseStream[Symbol.asyncIterator]();
|
||||
@@ -170,6 +197,16 @@ export abstract class BaseLLM<
|
||||
firstChunk?.options && "toolCall" in firstChunk.options;
|
||||
|
||||
if (!hasToolCallsInFirst) {
|
||||
// extract structured output from the last message
|
||||
const lastMessage = params.messages[params.messages.length - 1];
|
||||
const toolResult = (
|
||||
lastMessage?.options as { toolResult: CallToolToMessageResult }
|
||||
)?.toolResult;
|
||||
const structuredOutput =
|
||||
toolResult?.name === STRUCTURED_OUTPUT_TOOL_NAME
|
||||
? (toolResult.result as ZodInfer<Z>)
|
||||
: undefined;
|
||||
|
||||
let content = firstChunk?.delta ?? "";
|
||||
let finished = false;
|
||||
return {
|
||||
@@ -201,6 +238,7 @@ export abstract class BaseLLM<
|
||||
]
|
||||
: [];
|
||||
},
|
||||
object: structuredOutput,
|
||||
};
|
||||
}
|
||||
// Helper function to process a chunk
|
||||
@@ -252,15 +290,21 @@ export abstract class BaseLLM<
|
||||
toolCall: toolCalls,
|
||||
} as AdditionalMessageOptions,
|
||||
});
|
||||
let structuredOutput: ZodInfer<Z> | undefined = undefined;
|
||||
for (const toolCall of toolCalls) {
|
||||
const toolResultMessage =
|
||||
await callToolToMessage<AdditionalMessageOptions>(
|
||||
params.tools,
|
||||
toolCall,
|
||||
logger,
|
||||
);
|
||||
const toolResultMessage = await callToolToMessage(
|
||||
params.tools,
|
||||
toolCall,
|
||||
logger,
|
||||
);
|
||||
if (toolResultMessage) {
|
||||
messages.push(toolResultMessage);
|
||||
messages.push(
|
||||
toolResultMessage as ChatMessage<AdditionalMessageOptions>,
|
||||
);
|
||||
}
|
||||
if (toolCall.name === STRUCTURED_OUTPUT_TOOL_NAME) {
|
||||
structuredOutput = toolResultMessage?.options?.toolResult
|
||||
?.result as ZodInfer<Z>;
|
||||
}
|
||||
}
|
||||
return {
|
||||
@@ -269,6 +313,7 @@ export abstract class BaseLLM<
|
||||
return messages;
|
||||
},
|
||||
toolCalls,
|
||||
object: structuredOutput,
|
||||
};
|
||||
} else {
|
||||
throw new Error("Cannot get tool calls from response");
|
||||
|
||||
@@ -8,6 +8,8 @@ import type {
|
||||
LLMCompletionParamsNonStreaming,
|
||||
LLMCompletionParamsStreaming,
|
||||
LLMMetadata,
|
||||
ToolCall,
|
||||
ToolCallLLMMessageOptions,
|
||||
} from "./type";
|
||||
|
||||
export class MockLLM extends ToolCallLLM {
|
||||
@@ -15,18 +17,29 @@ export class MockLLM extends ToolCallLLM {
|
||||
options: {
|
||||
timeBetweenToken: number;
|
||||
responseMessage: string;
|
||||
mockToolCallResponse?: {
|
||||
toolCalls: ToolCall[];
|
||||
responseMessage?: string;
|
||||
};
|
||||
};
|
||||
supportToolCall: boolean = false;
|
||||
supportToolCall: boolean = true;
|
||||
|
||||
constructor(options?: {
|
||||
timeBetweenToken?: number;
|
||||
responseMessage?: string;
|
||||
metadata?: LLMMetadata;
|
||||
mockToolCallResponse?: {
|
||||
toolCalls: ToolCall[];
|
||||
responseMessage?: string;
|
||||
};
|
||||
}) {
|
||||
super();
|
||||
this.options = {
|
||||
timeBetweenToken: options?.timeBetweenToken ?? 20,
|
||||
responseMessage: options?.responseMessage ?? "This is a mock response",
|
||||
...(options?.mockToolCallResponse && {
|
||||
mockToolCallResponse: options.mockToolCallResponse,
|
||||
}),
|
||||
};
|
||||
this.metadata = options?.metadata ?? {
|
||||
model: "MockLLM",
|
||||
@@ -34,7 +47,7 @@ export class MockLLM extends ToolCallLLM {
|
||||
topP: 0.5,
|
||||
contextWindow: 1024,
|
||||
tokenizer: undefined,
|
||||
structuredOutput: false,
|
||||
structuredOutput: true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -51,14 +64,46 @@ export class MockLLM extends ToolCallLLM {
|
||||
): Promise<AsyncIterable<ChatResponseChunk> | ChatResponse<object>> {
|
||||
const responseMessage = this.options.responseMessage;
|
||||
const timeBetweenToken = this.options.timeBetweenToken;
|
||||
const mockToolCallResponse = this.options.mockToolCallResponse;
|
||||
|
||||
// Check if we have tools and should simulate tool calls
|
||||
const shouldSimulateToolCalls = params.tools && mockToolCallResponse;
|
||||
|
||||
if (params.stream) {
|
||||
return (async function* () {
|
||||
for (const char of responseMessage) {
|
||||
yield { delta: char, raw: {} };
|
||||
await new Promise((resolve) => setTimeout(resolve, timeBetweenToken));
|
||||
}
|
||||
})();
|
||||
if (shouldSimulateToolCalls) {
|
||||
return (async function* () {
|
||||
// First yield the tool call
|
||||
yield {
|
||||
delta: "",
|
||||
raw: {},
|
||||
options: {
|
||||
toolCall: mockToolCallResponse.toolCalls,
|
||||
} as ToolCallLLMMessageOptions,
|
||||
};
|
||||
})();
|
||||
} else {
|
||||
return (async function* () {
|
||||
for (const char of responseMessage) {
|
||||
yield { delta: char, raw: {} };
|
||||
await new Promise((resolve) =>
|
||||
setTimeout(resolve, timeBetweenToken),
|
||||
);
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldSimulateToolCalls) {
|
||||
return {
|
||||
message: {
|
||||
content: mockToolCallResponse.responseMessage || "",
|
||||
role: "assistant",
|
||||
options: {
|
||||
toolCall: mockToolCallResponse.toolCalls,
|
||||
} as ToolCallLLMMessageOptions,
|
||||
},
|
||||
raw: {},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { type Logger } from "@llamaindex/env";
|
||||
import { callTool } from "../agent/utils.js";
|
||||
import type { JSONValue } from "../global";
|
||||
import { stringifyJSONToMessageContent } from "../utils";
|
||||
import type {
|
||||
BaseTool,
|
||||
@@ -37,28 +38,30 @@ export const getToolCallsFromResponse = (
|
||||
return [];
|
||||
};
|
||||
|
||||
export const callToolToMessage = async <
|
||||
AdditionalMessageOptions extends object = object,
|
||||
>(
|
||||
export type CallToolToMessageResult = {
|
||||
id: string;
|
||||
name: string;
|
||||
result: JSONValue;
|
||||
isError: boolean;
|
||||
};
|
||||
|
||||
export const callToolToMessage = async (
|
||||
tools: BaseTool[],
|
||||
toolCall: ToolCall,
|
||||
logger: Logger,
|
||||
): Promise<ChatMessage<AdditionalMessageOptions> | null> => {
|
||||
): Promise<ChatMessage<{ toolResult: CallToolToMessageResult }>> => {
|
||||
const tool = tools?.find((t) => t.metadata.name === toolCall.name);
|
||||
|
||||
const toolOutput = await callTool(tool, toolCall, logger);
|
||||
|
||||
const toolResultMessage: ChatMessage<AdditionalMessageOptions> = {
|
||||
return {
|
||||
role: "user",
|
||||
content: stringifyJSONToMessageContent(toolOutput.output),
|
||||
options: {
|
||||
toolResult: {
|
||||
id: toolCall.id,
|
||||
name: toolCall.name,
|
||||
result: toolOutput.output,
|
||||
isError: toolOutput.isError,
|
||||
},
|
||||
} as AdditionalMessageOptions,
|
||||
},
|
||||
};
|
||||
|
||||
return toolResultMessage;
|
||||
};
|
||||
|
||||
@@ -99,18 +99,22 @@ export type ChatResponseChunk<
|
||||
|
||||
export interface ExecResponse<
|
||||
AdditionalMessageOptions extends object = object,
|
||||
O = JSONObject,
|
||||
> {
|
||||
newMessages: ChatMessage<AdditionalMessageOptions>[];
|
||||
toolCalls: ToolCall[];
|
||||
object?: O | undefined;
|
||||
}
|
||||
|
||||
export interface ExecStreamResponse<
|
||||
AdditionalMessageOptions extends object = object,
|
||||
O = JSONObject,
|
||||
> {
|
||||
stream: AsyncIterable<ChatResponseChunk<AdditionalMessageOptions>>;
|
||||
// this is a function as while streaming, the assistant message is not ready yet - can be called after the stream is done
|
||||
newMessages(): ChatMessage<AdditionalMessageOptions>[];
|
||||
toolCalls: ToolCall[];
|
||||
object?: O | undefined;
|
||||
}
|
||||
|
||||
export interface CompletionResponse {
|
||||
@@ -136,25 +140,36 @@ export type LLMMetadata = {
|
||||
export interface LLMChatParamsBase<
|
||||
AdditionalChatOptions extends object = object,
|
||||
AdditionalMessageOptions extends object = object,
|
||||
Schema extends ZodSchema = ZodSchema,
|
||||
> {
|
||||
messages: ChatMessage<AdditionalMessageOptions>[];
|
||||
additionalChatOptions?: AdditionalChatOptions | undefined;
|
||||
tools?: BaseTool[] | undefined;
|
||||
responseFormat?: ZodSchema | object | undefined;
|
||||
responseFormat?: Schema | object | undefined;
|
||||
logger?: Logger | undefined;
|
||||
}
|
||||
|
||||
export interface LLMChatParamsStreaming<
|
||||
AdditionalChatOptions extends object = object,
|
||||
AdditionalMessageOptions extends object = object,
|
||||
> extends LLMChatParamsBase<AdditionalChatOptions, AdditionalMessageOptions> {
|
||||
Schema extends ZodSchema = ZodSchema,
|
||||
> extends LLMChatParamsBase<
|
||||
AdditionalChatOptions,
|
||||
AdditionalMessageOptions,
|
||||
Schema
|
||||
> {
|
||||
stream: true;
|
||||
}
|
||||
|
||||
export interface LLMChatParamsNonStreaming<
|
||||
AdditionalChatOptions extends object = object,
|
||||
AdditionalMessageOptions extends object = object,
|
||||
> extends LLMChatParamsBase<AdditionalChatOptions, AdditionalMessageOptions> {
|
||||
Schema extends ZodSchema = ZodSchema,
|
||||
> extends LLMChatParamsBase<
|
||||
AdditionalChatOptions,
|
||||
AdditionalMessageOptions,
|
||||
Schema
|
||||
> {
|
||||
stream?: false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { MockLLM } from "@llamaindex/core/llms/mock";
|
||||
import { tool } from "@llamaindex/core/tools";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod/v3";
|
||||
|
||||
// TODO: add tests for tool calls
|
||||
describe("BaseLLM exec", () => {
|
||||
it("should stream text response when no tool call is made", async () => {
|
||||
const responseMessage = "This is a response message while streaming";
|
||||
@@ -40,4 +41,89 @@ describe("BaseLLM exec", () => {
|
||||
]);
|
||||
expect(toolCalls).toEqual([]);
|
||||
});
|
||||
|
||||
it("should handle tool calls with weather tool", async () => {
|
||||
const weatherTool = tool({
|
||||
name: "get_weather",
|
||||
description: "Get the current weather for a location",
|
||||
parameters: z.object({
|
||||
address: z.string().describe("The address"),
|
||||
}),
|
||||
execute: ({ address }) => {
|
||||
return `It's sunny in ${address}!`;
|
||||
},
|
||||
});
|
||||
|
||||
const mockToolCallInput = { address: "San Francisco" };
|
||||
const expectedWeatherResult = "It's sunny in San Francisco!";
|
||||
|
||||
const llm = new MockLLM({
|
||||
mockToolCallResponse: {
|
||||
toolCalls: [
|
||||
{
|
||||
id: "weather-tool-call-id",
|
||||
name: "get_weather",
|
||||
input: mockToolCallInput,
|
||||
},
|
||||
],
|
||||
responseMessage: "",
|
||||
},
|
||||
});
|
||||
|
||||
const { newMessages, toolCalls } = await llm.exec({
|
||||
messages: [
|
||||
{ content: "What's the weather in San Francisco?", role: "user" },
|
||||
],
|
||||
tools: [weatherTool],
|
||||
});
|
||||
|
||||
expect(toolCalls).toHaveLength(1);
|
||||
expect(toolCalls[0]!.name).toBe("get_weather");
|
||||
expect(toolCalls[0]!.input).toEqual(mockToolCallInput);
|
||||
expect(newMessages).toHaveLength(2); // assistant message + tool result message
|
||||
|
||||
// Check that the tool was executed and result is in the tool result message
|
||||
const toolResultMessage = newMessages[1];
|
||||
expect(toolResultMessage!.content).toBe(expectedWeatherResult);
|
||||
expect(toolResultMessage!.role).toBe("user");
|
||||
expect(toolResultMessage!.options).toHaveProperty("toolResult");
|
||||
});
|
||||
|
||||
it("should return structured output with responseFormat", async () => {
|
||||
const schema = z.object({
|
||||
title: z.string(),
|
||||
author: z.string(),
|
||||
year: z.number(),
|
||||
});
|
||||
|
||||
const mockObject = {
|
||||
title: "La Divina Commedia",
|
||||
author: "Dante Alighieri",
|
||||
year: 1321,
|
||||
};
|
||||
|
||||
const llm = new MockLLM({
|
||||
mockToolCallResponse: {
|
||||
toolCalls: [
|
||||
{
|
||||
id: "test-tool-call-id",
|
||||
name: "format_output",
|
||||
input: mockObject,
|
||||
},
|
||||
],
|
||||
responseMessage: "",
|
||||
},
|
||||
});
|
||||
|
||||
const { newMessages, toolCalls, object } = await llm.exec({
|
||||
messages: [{ content: "Extract book info", role: "user" }],
|
||||
responseFormat: schema,
|
||||
});
|
||||
|
||||
expect(toolCalls).toHaveLength(1);
|
||||
expect(toolCalls[0]!.name).toBe("format_output");
|
||||
expect(object).toBeDefined();
|
||||
expect(object).toEqual(mockObject);
|
||||
expect(newMessages).toHaveLength(2); // assistant message + tool result message
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @llamaindex/experimental
|
||||
|
||||
## 0.0.207
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.0.206
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/experimental",
|
||||
"description": "Experimental package for LlamaIndexTS",
|
||||
"version": "0.0.206",
|
||||
"version": "0.0.207",
|
||||
"type": "module",
|
||||
"types": "dist/type/index.d.ts",
|
||||
"main": "dist/cjs/index.js",
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
# llamaindex
|
||||
|
||||
## 0.12.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- d493015: remove export cloud package from llamaindex
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [06f884a]
|
||||
- Updated dependencies [06f884a]
|
||||
- @llamaindex/core@0.6.22
|
||||
- @llamaindex/workflow@1.1.24
|
||||
- @llamaindex/node-parser@2.0.22
|
||||
|
||||
## 0.11.29
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -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,6 +1,6 @@
|
||||
{
|
||||
"name": "llamaindex",
|
||||
"version": "0.11.29",
|
||||
"version": "0.12.0",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
@@ -20,7 +20,6 @@
|
||||
"llamaindex"
|
||||
],
|
||||
"dependencies": {
|
||||
"@llamaindex/cloud": "workspace:*",
|
||||
"@llamaindex/core": "workspace:*",
|
||||
"@llamaindex/env": "workspace:*",
|
||||
"@llamaindex/node-parser": "workspace:*",
|
||||
@@ -73,17 +72,6 @@
|
||||
},
|
||||
"default": "./agent/dist/index.js"
|
||||
},
|
||||
"./cloud": {
|
||||
"require": {
|
||||
"types": "./cloud/dist/index.d.cts",
|
||||
"default": "./cloud/dist/index.cjs"
|
||||
},
|
||||
"import": {
|
||||
"types": "./cloud/dist/index.d.ts",
|
||||
"default": "./cloud/dist/index.js"
|
||||
},
|
||||
"default": "./cloud/dist/index.js"
|
||||
},
|
||||
"./engines": {
|
||||
"require": {
|
||||
"types": "./engines/dist/index.d.cts",
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
import {
|
||||
addFilesToPipelineApiApiV1PipelinesPipelineIdFilesPut,
|
||||
getPipelineFileStatusApiV1PipelinesPipelineIdFilesFileIdStatusGet,
|
||||
listPipelineFilesApiV1PipelinesPipelineIdFilesGet,
|
||||
listProjectsApiV1ProjectsGet,
|
||||
readFileContentApiV1FilesIdContentGet,
|
||||
searchPipelinesApiV1PipelinesGet,
|
||||
uploadFileApiV1FilesPost,
|
||||
} from "@llamaindex/cloud/api";
|
||||
import { initService } from "./utils.js";
|
||||
|
||||
export class LLamaCloudFileService {
|
||||
/**
|
||||
* Get list of projects, each project contains a list of pipelines
|
||||
*/
|
||||
public static async getAllProjectsWithPipelines() {
|
||||
initService();
|
||||
try {
|
||||
const { data: projects } = await listProjectsApiV1ProjectsGet({
|
||||
throwOnError: true,
|
||||
});
|
||||
const { data: pipelines } = await searchPipelinesApiV1PipelinesGet({
|
||||
throwOnError: true,
|
||||
});
|
||||
return projects.map((project) => ({
|
||||
...project,
|
||||
pipelines: pipelines.filter((p) => p.project_id === project.id),
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error("Error listing projects and pipelines:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a file to a pipeline in LlamaCloud
|
||||
*/
|
||||
public static async addFileToPipeline(
|
||||
projectId: string,
|
||||
pipelineId: string,
|
||||
uploadFile: File | Blob,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
customMetadata: Record<string, any> = {},
|
||||
) {
|
||||
initService();
|
||||
const { data: file } = await uploadFileApiV1FilesPost({
|
||||
query: { project_id: projectId },
|
||||
body: {
|
||||
upload_file: uploadFile,
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
const files = [
|
||||
{
|
||||
file_id: file.id,
|
||||
custom_metadata: { file_id: file.id, ...customMetadata },
|
||||
},
|
||||
];
|
||||
await addFilesToPipelineApiApiV1PipelinesPipelineIdFilesPut({
|
||||
path: {
|
||||
pipeline_id: pipelineId,
|
||||
},
|
||||
body: files,
|
||||
});
|
||||
|
||||
// Wait 2s for the file to be processed
|
||||
const maxAttempts = 20;
|
||||
let attempt = 0;
|
||||
while (attempt < maxAttempts) {
|
||||
const { data: result } =
|
||||
await getPipelineFileStatusApiV1PipelinesPipelineIdFilesFileIdStatusGet(
|
||||
{
|
||||
path: {
|
||||
pipeline_id: pipelineId,
|
||||
file_id: file.id,
|
||||
},
|
||||
throwOnError: true,
|
||||
},
|
||||
);
|
||||
if (result.status === "ERROR") {
|
||||
throw new Error(`File processing failed: ${JSON.stringify(result)}`);
|
||||
}
|
||||
if (result.status === "SUCCESS") {
|
||||
// File is ingested - return the file id
|
||||
return file.id;
|
||||
}
|
||||
attempt += 1;
|
||||
await new Promise((resolve) => setTimeout(resolve, 100)); // Sleep for 100ms
|
||||
}
|
||||
throw new Error(
|
||||
`File processing did not complete after ${maxAttempts} attempts. Check your LlamaCloud index at https://cloud.llamaindex.ai/project/${projectId}/deploy/${pipelineId} for more details.`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get download URL for a file in LlamaCloud
|
||||
*/
|
||||
public static async getFileUrl(pipelineId: string, filename: string) {
|
||||
initService();
|
||||
const { data: allPipelineFiles } =
|
||||
await listPipelineFilesApiV1PipelinesPipelineIdFilesGet({
|
||||
path: {
|
||||
pipeline_id: pipelineId,
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
const file = allPipelineFiles.find((file) => file.name === filename);
|
||||
if (!file?.file_id) return null;
|
||||
const { data: fileContent } = await readFileContentApiV1FilesIdContentGet({
|
||||
path: {
|
||||
id: file.file_id,
|
||||
},
|
||||
query: {
|
||||
project_id: file.project_id,
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
return fileContent.url;
|
||||
}
|
||||
}
|
||||
@@ -1,414 +0,0 @@
|
||||
import type { BaseNodePostprocessor } from "@llamaindex/core/postprocessor";
|
||||
import type { BaseQueryEngine } from "@llamaindex/core/query-engine";
|
||||
import type { BaseSynthesizer } from "@llamaindex/core/response-synthesizers";
|
||||
import type { Document } from "@llamaindex/core/schema";
|
||||
import { RetrieverQueryEngine } from "../engines/query/RetrieverQueryEngine.js";
|
||||
import type { CloudRetrieveParams } from "./LlamaCloudRetriever.js";
|
||||
import { LlamaCloudRetriever } from "./LlamaCloudRetriever.js";
|
||||
import type { CloudConstructorParams } from "./type.js";
|
||||
import {
|
||||
getAppBaseUrl,
|
||||
getPipelineId,
|
||||
getProjectId,
|
||||
initService,
|
||||
} from "./utils.js";
|
||||
|
||||
import {
|
||||
createBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPost,
|
||||
deletePipelineDocumentApiV1PipelinesPipelineIdDocumentsDocumentIdDelete,
|
||||
getPipelineDocumentStatusApiV1PipelinesPipelineIdDocumentsDocumentIdStatusGet,
|
||||
getPipelineStatusApiV1PipelinesPipelineIdStatusGet,
|
||||
type PipelineCreateReadable,
|
||||
searchPipelinesApiV1PipelinesGet,
|
||||
upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut,
|
||||
upsertPipelineApiV1PipelinesPut,
|
||||
} from "@llamaindex/cloud/api";
|
||||
import type { BaseRetriever } from "@llamaindex/core/retriever";
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import type { QueryToolParams } from "../indices/BaseIndex.js";
|
||||
import { Settings } from "../Settings.js";
|
||||
import { QueryEngineTool } from "../tools/QueryEngineTool.js";
|
||||
|
||||
export class LlamaCloudIndex {
|
||||
params: CloudConstructorParams;
|
||||
|
||||
constructor(params: CloudConstructorParams) {
|
||||
this.params = params;
|
||||
initService(this.params);
|
||||
}
|
||||
|
||||
private async waitForPipelineIngestion(
|
||||
verbose = Settings.debug,
|
||||
raiseOnError = false,
|
||||
): Promise<void> {
|
||||
const pipelineId = await this.getPipelineId();
|
||||
|
||||
if (verbose) {
|
||||
console.log("Waiting for pipeline ingestion: ");
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const { data: pipelineStatus } =
|
||||
await getPipelineStatusApiV1PipelinesPipelineIdStatusGet({
|
||||
path: {
|
||||
pipeline_id: pipelineId,
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
|
||||
if (pipelineStatus.status === "SUCCESS") {
|
||||
if (verbose) {
|
||||
console.log("Pipeline ingestion completed successfully");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (pipelineStatus.status === "ERROR") {
|
||||
if (verbose) {
|
||||
console.error("Pipeline ingestion failed");
|
||||
}
|
||||
|
||||
if (raiseOnError) {
|
||||
throw new Error("Pipeline ingestion failed");
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
process.stdout.write(".");
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
private async waitForDocumentIngestion(
|
||||
docIds: string[],
|
||||
verbose = Settings.debug,
|
||||
raiseOnError = false,
|
||||
): Promise<void> {
|
||||
const pipelineId = await this.getPipelineId();
|
||||
|
||||
if (verbose) {
|
||||
console.log("Loading data: ");
|
||||
}
|
||||
|
||||
const pendingDocs = new Set(docIds);
|
||||
|
||||
while (pendingDocs.size) {
|
||||
const docsToRemove = new Set<string>();
|
||||
|
||||
for (const doc of pendingDocs) {
|
||||
const {
|
||||
data: { status },
|
||||
} =
|
||||
await getPipelineDocumentStatusApiV1PipelinesPipelineIdDocumentsDocumentIdStatusGet(
|
||||
{
|
||||
path: { pipeline_id: pipelineId, document_id: doc },
|
||||
throwOnError: true,
|
||||
},
|
||||
);
|
||||
|
||||
if (status === "NOT_STARTED" || status === "IN_PROGRESS") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (status === "ERROR") {
|
||||
if (verbose) {
|
||||
console.error(`Document ingestion failed for ${doc}`);
|
||||
}
|
||||
|
||||
if (raiseOnError) {
|
||||
throw new Error(`Document ingestion failed for ${doc}`);
|
||||
}
|
||||
}
|
||||
|
||||
docsToRemove.add(doc);
|
||||
}
|
||||
|
||||
for (const doc of docsToRemove) {
|
||||
pendingDocs.delete(doc);
|
||||
}
|
||||
|
||||
if (pendingDocs.size) {
|
||||
if (verbose) {
|
||||
process.stdout.write(".");
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
console.log("Done!");
|
||||
}
|
||||
|
||||
await this.waitForPipelineIngestion(verbose, raiseOnError);
|
||||
}
|
||||
|
||||
public async getPipelineId(
|
||||
name?: string,
|
||||
projectName?: string,
|
||||
organizationId?: string,
|
||||
): Promise<string> {
|
||||
return await getPipelineId(
|
||||
name ?? this.params.name,
|
||||
projectName ?? this.params.projectName,
|
||||
organizationId ?? this.params.organizationId,
|
||||
);
|
||||
}
|
||||
|
||||
public async getProjectId(
|
||||
projectName?: string,
|
||||
organizationId?: string,
|
||||
): Promise<string> {
|
||||
return await getProjectId(
|
||||
projectName ?? this.params.projectName,
|
||||
organizationId ?? this.params.organizationId,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds documents to the given index parameters. If the index does not exist, it will be created.
|
||||
*
|
||||
* @param params - An object containing the following properties:
|
||||
* - documents: An array of Document objects to be added to the index.
|
||||
* - verbose: Optional boolean to enable verbose logging.
|
||||
* - Additional properties from CloudConstructorParams.
|
||||
* @returns A Promise that resolves to a new LlamaCloudIndex instance.
|
||||
*/
|
||||
static async fromDocuments(
|
||||
params: {
|
||||
documents: Document[];
|
||||
verbose?: boolean;
|
||||
} & CloudConstructorParams,
|
||||
config?: {
|
||||
embedding: PipelineCreateReadable["embedding_config"];
|
||||
transform: PipelineCreateReadable["transform_config"];
|
||||
},
|
||||
): Promise<LlamaCloudIndex> {
|
||||
const index = new LlamaCloudIndex({ ...params });
|
||||
await index.ensureIndex({ ...config, verbose: params.verbose ?? false });
|
||||
await index.addDocuments(params.documents, params.verbose);
|
||||
return index;
|
||||
}
|
||||
|
||||
async addDocuments(documents: Document[], verbose?: boolean): Promise<void> {
|
||||
const apiUrl = getAppBaseUrl();
|
||||
const projectId = await this.getProjectId();
|
||||
const pipelineId = await this.getPipelineId();
|
||||
|
||||
await upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut({
|
||||
path: {
|
||||
pipeline_id: pipelineId,
|
||||
},
|
||||
body: documents.map((doc) => ({
|
||||
metadata: doc.metadata,
|
||||
text: doc.text,
|
||||
excluded_embed_metadata_keys: doc.excludedEmbedMetadataKeys,
|
||||
excluded_llm_metadata_keys: doc.excludedEmbedMetadataKeys,
|
||||
id: doc.id_,
|
||||
})),
|
||||
});
|
||||
|
||||
while (true) {
|
||||
const { data: pipelineStatus } =
|
||||
await getPipelineStatusApiV1PipelinesPipelineIdStatusGet({
|
||||
path: { pipeline_id: pipelineId },
|
||||
throwOnError: true,
|
||||
});
|
||||
|
||||
if (pipelineStatus.status === "SUCCESS") {
|
||||
console.info(
|
||||
"Documents ingested successfully, pipeline is ready to use",
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
if (pipelineStatus.status === "ERROR") {
|
||||
console.error(
|
||||
`Some documents failed to ingest, check your pipeline logs at ${apiUrl}/project/${projectId}/deploy/${pipelineId}`,
|
||||
);
|
||||
throw new Error("Some documents failed to ingest");
|
||||
}
|
||||
|
||||
if (pipelineStatus.status === "PARTIAL_SUCCESS") {
|
||||
console.info(
|
||||
`Documents ingestion partially succeeded, to check a more complete status check your pipeline at ${apiUrl}/project/${projectId}/deploy/${pipelineId}`,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
process.stdout.write(".");
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
console.info(
|
||||
`Ingestion completed, find your index at ${apiUrl}/project/${projectId}/deploy/${pipelineId}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
asRetriever(params: CloudRetrieveParams = {}): BaseRetriever {
|
||||
return new LlamaCloudRetriever({ ...this.params, ...params });
|
||||
}
|
||||
|
||||
asQueryEngine(
|
||||
params?: {
|
||||
responseSynthesizer?: BaseSynthesizer;
|
||||
preFilters?: unknown;
|
||||
nodePostprocessors?: BaseNodePostprocessor[];
|
||||
} & CloudRetrieveParams,
|
||||
): BaseQueryEngine {
|
||||
const retriever = new LlamaCloudRetriever({
|
||||
...this.params,
|
||||
...params,
|
||||
});
|
||||
return new RetrieverQueryEngine(
|
||||
retriever,
|
||||
params?.responseSynthesizer,
|
||||
params?.nodePostprocessors,
|
||||
);
|
||||
}
|
||||
|
||||
asQueryTool(params: QueryToolParams): QueryEngineTool {
|
||||
if (params.options) {
|
||||
params.retriever = this.asRetriever(params.options);
|
||||
}
|
||||
|
||||
return new QueryEngineTool({
|
||||
queryEngine: this.asQueryEngine(params),
|
||||
metadata: params?.metadata,
|
||||
includeSourceNodes: params?.includeSourceNodes ?? false,
|
||||
});
|
||||
}
|
||||
|
||||
queryTool(params: QueryToolParams): QueryEngineTool {
|
||||
return this.asQueryTool(params);
|
||||
}
|
||||
|
||||
async insert(document: Document) {
|
||||
const pipelineId = await this.getPipelineId();
|
||||
|
||||
await createBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPost({
|
||||
path: {
|
||||
pipeline_id: pipelineId,
|
||||
},
|
||||
body: [
|
||||
{
|
||||
metadata: document.metadata,
|
||||
text: document.text,
|
||||
excluded_embed_metadata_keys: document.excludedLlmMetadataKeys,
|
||||
excluded_llm_metadata_keys: document.excludedEmbedMetadataKeys,
|
||||
id: document.id_,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await this.waitForDocumentIngestion([document.id_]);
|
||||
}
|
||||
|
||||
async delete(document: Document) {
|
||||
const pipelineId = await this.getPipelineId();
|
||||
|
||||
await deletePipelineDocumentApiV1PipelinesPipelineIdDocumentsDocumentIdDelete(
|
||||
{
|
||||
path: {
|
||||
pipeline_id: pipelineId,
|
||||
document_id: document.id_,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
await this.waitForPipelineIngestion();
|
||||
}
|
||||
|
||||
async refreshDoc(document: Document) {
|
||||
const pipelineId = await this.getPipelineId();
|
||||
|
||||
await upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut({
|
||||
path: {
|
||||
pipeline_id: pipelineId,
|
||||
},
|
||||
body: [
|
||||
{
|
||||
metadata: document.metadata,
|
||||
text: document.text,
|
||||
excluded_embed_metadata_keys: document.excludedLlmMetadataKeys,
|
||||
excluded_llm_metadata_keys: document.excludedEmbedMetadataKeys,
|
||||
id: document.id_,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await this.waitForDocumentIngestion([document.id_]);
|
||||
}
|
||||
|
||||
public async ensureIndex(config?: {
|
||||
embedding?: PipelineCreateReadable["embedding_config"];
|
||||
transform?: PipelineCreateReadable["transform_config"];
|
||||
verbose?: boolean;
|
||||
}): Promise<void> {
|
||||
const projectId = await this.getProjectId();
|
||||
|
||||
const { data: pipelines } = await searchPipelinesApiV1PipelinesGet({
|
||||
query: {
|
||||
project_id: projectId,
|
||||
pipeline_name: this.params.name,
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
|
||||
if (pipelines.length === 0) {
|
||||
// no pipeline found, create a new one
|
||||
let embeddingConfig = config?.embedding;
|
||||
if (!embeddingConfig) {
|
||||
// no embedding config provided, use OpenAI as default
|
||||
const openAIApiKey = getEnv("OPENAI_API_KEY");
|
||||
const embeddingModel = getEnv("EMBEDDING_MODEL");
|
||||
if (!openAIApiKey || !embeddingModel) {
|
||||
throw new Error(
|
||||
"No embedding configuration provided. Fallback to OpenAI embedding model. OPENAI_API_KEY and EMBEDDING_MODEL environment variables must be set.",
|
||||
);
|
||||
}
|
||||
embeddingConfig = {
|
||||
type: "OPENAI_EMBEDDING",
|
||||
component: {
|
||||
api_key: openAIApiKey,
|
||||
model_name: embeddingModel,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
let transformConfig = config?.transform;
|
||||
if (!transformConfig) {
|
||||
transformConfig = {
|
||||
mode: "auto",
|
||||
chunk_size: 1024,
|
||||
chunk_overlap: 200,
|
||||
};
|
||||
}
|
||||
|
||||
const { data: pipeline } = await upsertPipelineApiV1PipelinesPut({
|
||||
query: {
|
||||
project_id: projectId,
|
||||
},
|
||||
body: {
|
||||
name: this.params.name,
|
||||
embedding_config: embeddingConfig,
|
||||
transform_config: transformConfig,
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
|
||||
if (config?.verbose) {
|
||||
console.log(
|
||||
`Created pipeline ${pipeline.id} with name ${pipeline.name}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
import {
|
||||
type MetadataFilter,
|
||||
type MetadataFilters,
|
||||
type RetrievalParams,
|
||||
runSearchApiV1PipelinesPipelineIdRetrievePost,
|
||||
type TextNodeWithScore,
|
||||
} from "@llamaindex/cloud/api";
|
||||
import { DEFAULT_PROJECT_NAME } from "@llamaindex/core/global";
|
||||
import type { QueryBundle } from "@llamaindex/core/query-engine";
|
||||
import { BaseRetriever } from "@llamaindex/core/retriever";
|
||||
import type { NodeWithScore } from "@llamaindex/core/schema";
|
||||
import { jsonToNode, ObjectType } from "@llamaindex/core/schema";
|
||||
import { extractText } from "@llamaindex/core/utils";
|
||||
import type { ClientParams, CloudConstructorParams } from "./type.js";
|
||||
import { getPipelineId, initService } from "./utils.js";
|
||||
|
||||
export type CloudRetrieveParams = Omit<
|
||||
RetrievalParams,
|
||||
"query" | "search_filters" | "dense_similarity_top_k"
|
||||
> & { similarityTopK?: number; filters?: MetadataFilters };
|
||||
|
||||
export class LlamaCloudRetriever extends BaseRetriever {
|
||||
clientParams: ClientParams;
|
||||
retrieveParams: CloudRetrieveParams;
|
||||
organizationId?: string;
|
||||
projectName: string = DEFAULT_PROJECT_NAME;
|
||||
pipelineName: 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, // append LlamaCloud extra_info to node metadata (file_name, pipeline_id, etc.)
|
||||
};
|
||||
return {
|
||||
// Currently LlamaCloud only supports text nodes
|
||||
node: textNode,
|
||||
score: node.score ?? undefined,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// LlamaCloud expects null values for filters, but LlamaIndexTS uses undefined for empty values
|
||||
// This function converts the undefined values to null
|
||||
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: CloudConstructorParams & CloudRetrieveParams) {
|
||||
super();
|
||||
this.clientParams = { apiKey: params.apiKey, baseUrl: params.baseUrl };
|
||||
initService(this.clientParams);
|
||||
this.retrieveParams = params;
|
||||
this.pipelineName = params.name;
|
||||
if (params.projectName) {
|
||||
this.projectName = params.projectName;
|
||||
}
|
||||
if (params.organizationId) {
|
||||
this.organizationId = params.organizationId;
|
||||
}
|
||||
}
|
||||
|
||||
async _retrieve(query: QueryBundle): Promise<NodeWithScore[]> {
|
||||
const pipelineId = await getPipelineId(
|
||||
this.pipelineName,
|
||||
this.projectName,
|
||||
this.organizationId,
|
||||
);
|
||||
|
||||
const filters = this.convertFilter(this.retrieveParams.filters);
|
||||
|
||||
const { data: results } =
|
||||
await runSearchApiV1PipelinesPipelineIdRetrievePost({
|
||||
throwOnError: true,
|
||||
path: {
|
||||
pipeline_id: pipelineId,
|
||||
},
|
||||
body: {
|
||||
...this.retrieveParams,
|
||||
query: extractText(query),
|
||||
search_filters: filters,
|
||||
dense_similarity_top_k: this.retrieveParams.similarityTopK!,
|
||||
},
|
||||
});
|
||||
|
||||
return this.resultNodesToNodeWithScore(results.retrieval_nodes);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
console.warn(`
|
||||
The classes LlamaCloudFileService, LlamaCloudIndex and LlamaCloudRetriever have been moved to the package llama-cloud-services.
|
||||
* Please migrate your imports to llama-cloud-services, e.g. import { LlamaCloudIndex } from "llama-cloud-services";
|
||||
* See the documentation: https://docs.cloud.llamaindex.ai
|
||||
`);
|
||||
|
||||
export { LLamaCloudFileService } from "./LLamaCloudFileService.js";
|
||||
export { LlamaCloudIndex } from "./LlamaCloudIndex.js";
|
||||
export {
|
||||
LlamaCloudRetriever,
|
||||
type CloudRetrieveParams,
|
||||
} from "./LlamaCloudRetriever.js";
|
||||
export type { CloudConstructorParams } from "./type.js";
|
||||
@@ -1,10 +0,0 @@
|
||||
export type ClientParams = {
|
||||
apiKey?: string | undefined;
|
||||
baseUrl?: string | undefined;
|
||||
};
|
||||
|
||||
export type CloudConstructorParams = {
|
||||
name: string;
|
||||
projectName: string;
|
||||
organizationId?: string | undefined;
|
||||
} & ClientParams;
|
||||
@@ -1,97 +0,0 @@
|
||||
import {
|
||||
client,
|
||||
listProjectsApiV1ProjectsGet,
|
||||
searchPipelinesApiV1PipelinesGet,
|
||||
} from "@llamaindex/cloud/api";
|
||||
import { DEFAULT_BASE_URL } from "@llamaindex/core/global";
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import type { ClientParams } from "./type.js";
|
||||
|
||||
function getBaseUrl(baseUrl?: string): string {
|
||||
return baseUrl ?? getEnv("LLAMA_CLOUD_BASE_URL") ?? DEFAULT_BASE_URL;
|
||||
}
|
||||
|
||||
export function getAppBaseUrl(): string {
|
||||
return client.getConfig().baseUrl?.replace(/api\./, "") ?? "";
|
||||
}
|
||||
|
||||
// fixme: refactor this to init at the top level or module level
|
||||
let initOnce = false;
|
||||
export function initService({ apiKey, baseUrl }: ClientParams = {}) {
|
||||
if (initOnce) {
|
||||
return;
|
||||
}
|
||||
initOnce = true;
|
||||
client.setConfig({
|
||||
baseUrl: getBaseUrl(baseUrl),
|
||||
throwOnError: true,
|
||||
});
|
||||
const token = apiKey ?? getEnv("LLAMA_CLOUD_API_KEY");
|
||||
client.interceptors.request.use((request) => {
|
||||
request.headers.set("Authorization", `Bearer ${token}`);
|
||||
return request;
|
||||
});
|
||||
client.interceptors.error.use((error) => {
|
||||
throw new Error(
|
||||
`LlamaCloud API request failed. Error details: ${JSON.stringify(error)}`,
|
||||
);
|
||||
});
|
||||
if (!token) {
|
||||
throw new Error(
|
||||
"API Key is required for LlamaCloudIndex. Please pass the apiKey parameter",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getProjectId(
|
||||
projectName: string,
|
||||
organizationId?: string,
|
||||
): Promise<string> {
|
||||
const { data: projects } = await listProjectsApiV1ProjectsGet({
|
||||
query: {
|
||||
project_name: projectName,
|
||||
organization_id: organizationId ?? null,
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
|
||||
if (projects.length === 0) {
|
||||
throw new Error(
|
||||
`Unknown project name ${projectName}. Please confirm a managed project with this name exists.`,
|
||||
);
|
||||
} else if (projects.length > 1) {
|
||||
throw new Error(
|
||||
`Multiple projects found with name ${projectName}. Please specify organization_id.`,
|
||||
);
|
||||
}
|
||||
|
||||
const project = projects[0]!;
|
||||
|
||||
if (!project.id) {
|
||||
throw new Error(`No project found with name ${projectName}`);
|
||||
}
|
||||
|
||||
return project.id;
|
||||
}
|
||||
|
||||
export async function getPipelineId(
|
||||
name: string,
|
||||
projectName: string,
|
||||
organizationId?: string,
|
||||
): Promise<string> {
|
||||
const { data: pipelines } = await searchPipelinesApiV1PipelinesGet({
|
||||
query: {
|
||||
project_id: await getProjectId(projectName, organizationId),
|
||||
pipeline_name: name,
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
|
||||
if (pipelines.length === 0 || !pipelines[0]!.id) {
|
||||
throw new Error(
|
||||
`No pipeline found with name ${name} in project ${projectName}`,
|
||||
);
|
||||
}
|
||||
|
||||
return pipelines[0]!.id;
|
||||
}
|
||||
@@ -3,11 +3,6 @@ import { Settings } from "./Settings.js";
|
||||
|
||||
//#endregion
|
||||
|
||||
export {
|
||||
LlamaParseReader,
|
||||
type Language,
|
||||
type ResultType,
|
||||
} from "@llamaindex/cloud/reader";
|
||||
export * from "@llamaindex/core/agent";
|
||||
export * from "@llamaindex/core/chat-engine";
|
||||
export * from "@llamaindex/core/data-structs";
|
||||
@@ -57,7 +52,6 @@ export * from "@llamaindex/core/storage/index-store";
|
||||
export * from "@llamaindex/core/storage/kv-store";
|
||||
export * from "@llamaindex/core/utils";
|
||||
export * from "./agent/index.js";
|
||||
export * from "./cloud/index.js";
|
||||
export * from "./engines/index.js";
|
||||
export * from "./evaluation/index.js";
|
||||
export * from "./extractors/index.js";
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user