Compare commits

..

8 Commits

Author SHA1 Message Date
github-actions[bot] 4c7b891446 Release 0.8.13 (#1480)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: himself65 <himself65@users.noreply.github.com>
2024-11-14 18:25:19 -08:00
Alex Yang a9c5b4899b docs: update docusaurus.config.js (#1489) 2024-11-14 17:36:52 -08:00
Alex Yang a7b0ac3cb7 feat(anthropic): support prompt caching (#1488) 2024-11-14 17:35:21 -08:00
Alex Yang a7540ff47b docs: update (#1486) 2024-11-14 15:46:48 -08:00
Aman Rao c69605f406 feat: add async support to BaseChatStore and BaseChatStoreMemory (#1483)
Co-authored-by: Alex Yang <himself65@outlook.com>
2024-11-14 13:45:50 -08:00
Alex Yang ee20c44d9b feat(workflow): allow send event with no output (#1479) 2024-11-14 00:17:53 -08:00
Alex Yang 1d470363df docs: add banner for legacy (#1478) 2024-11-13 18:16:13 -08:00
github-actions[bot] b39f40dbd8 Release (#1477)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: himself65 <himself65@users.noreply.github.com>
2024-11-13 01:25:40 -08:00
84 changed files with 758 additions and 1959 deletions
-5
View File
@@ -1,5 +0,0 @@
---
"@llamaindex/workflow": patch
---
fix: output event check
-5
View File
@@ -1,5 +0,0 @@
---
"@llamaindex/workflow": patch
---
feat: recoverable context with error handling
+7 -3
View File
@@ -1,12 +1,16 @@
# LlamaIndex.TS
<p align="center">
<img height="100" width="100" alt="LlamaIndex logo" src="https://ts.llamaindex.ai/square.svg" />
</p>
<h1 align="center">LlamaIndex.TS</h1>
<h3 align="center">
Data framework for your LLM application.
</h3>
[![NPM Version](https://img.shields.io/npm/v/llamaindex)](https://www.npmjs.com/package/llamaindex)
[![NPM License](https://img.shields.io/npm/l/llamaindex)](https://www.npmjs.com/package/llamaindex)
[![NPM Downloads](https://img.shields.io/npm/dm/llamaindex)](https://www.npmjs.com/package/llamaindex)
[![Discord](https://img.shields.io/discord/1059199217496772688)](https://discord.com/invite/eN6D2HQ4aX)
LlamaIndex is a data framework for your LLM application.
Use your own data with large language models (LLMs, OpenAI ChatGPT and others) in JS runtime environments with TypeScript support.
Documentation: https://ts.llamaindex.ai/
+13
View File
@@ -1,5 +1,18 @@
# docs
## 0.0.118
### Patch Changes
- llamaindex@0.8.13
- @llamaindex/examples@0.0.16
## 0.0.117
### Patch Changes
- @llamaindex/examples@0.0.15
## 0.0.116
### Patch Changes
+6
View File
@@ -62,6 +62,12 @@ const config = {
({
// Replace with your project's social card
image: "img/favicon.png", // TODO change this
announcementBar: {
id: "migrate_to_next",
content:
'We are migrating to Next.js based documentation. Check it out <a href="https://ts.llamaindex.ai/docs/llamaindex">here</a>!',
isCloseable: false,
},
navbar: {
title: "LlamaIndex.TS",
logo: {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.0.116",
"version": "0.0.118",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
+23
View File
@@ -1,5 +1,28 @@
# @llamaindex/doc
## 0.0.16
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [ee20c44]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
- @llamaindex/workflow@0.0.6
- llamaindex@0.8.13
- @llamaindex/cloud@2.0.10
- @llamaindex/node-parser@0.0.11
- @llamaindex/openai@0.1.35
- @llamaindex/readers@1.0.11
## 0.0.15
### Patch Changes
- Updated dependencies [ea92b69]
- Updated dependencies [fadc8b8]
- @llamaindex/workflow@0.0.5
## 0.0.14
### Patch Changes
-10
View File
@@ -6,16 +6,6 @@ const withMDX = createMDX();
const config = {
reactStrictMode: true,
transpilePackages: ["monaco-editor"],
images: {
remotePatterns: [
{
protocol: "https",
hostname: "mermaid.ink",
port: "",
pathname: "/**",
},
],
},
webpack: (config, { isServer }) => {
if (Array.isArray(config.target) && config.target.includes("web")) {
config.target = ["web", "es2020"];
+1 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/doc",
"version": "0.0.14",
"version": "0.0.16",
"private": true,
"scripts": {
"build": "pnpm run build:docs && next build",
@@ -24,8 +24,6 @@
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-icons": "^1.3.1",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slider": "^1.2.1",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.3",
@@ -54,7 +52,6 @@
"react-text-transition": "^3.1.0",
"react-use-measure": "^2.1.1",
"rehype-katex": "^7.0.1",
"rehype-mermaid": "^3.0.0",
"remark-math": "^6.0.0",
"rimraf": "^6.0.1",
"shiki": "^1.22.2",
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.3 KiB

-213
View File
@@ -1,213 +0,0 @@
"use client";
import type { ShippingInfo } from "@/components/demo/checkout/shpping";
import {
StartEvent,
StopEvent,
Workflow,
WorkflowContext,
WorkflowEvent,
} from "@llamaindex/workflow";
import { ReactNode, useCallback, useState } from "react";
import { Button } from "../ui/button";
import {
Card,
CardContent,
CardFooter,
CardHeader,
CardTitle,
} from "../ui/card";
import { Separator } from "../ui/separator";
type Context = {
userId: string;
items: { name: string; price: number; quantity: number }[];
// utility functions with frontend
update: (ui: ReactNode) => void;
interrupt: () => void;
};
type UserInfo = {
id: string;
name: string;
email: string;
shippingAddress: ShippingInfo;
};
const getUser = async (userId: string): Promise<UserInfo | null> => {
await new Promise((resolve) => setTimeout(resolve, 1000));
const user = localStorage.getItem(`workflow-demo-user:${userId}`);
if (user !== null) {
return JSON.parse(user) as UserInfo;
} else {
return null;
}
};
const checkoutWorkflow = new Workflow<Context, void, void>({});
// 1. User click checkout button
// 2. Check if user has correct information
// - If not, show shipping information form
// 3. Proceed to payment
// 4. Confirm the order
// 5. Send confirmation email
class ShowShippingInformationFormEvent extends WorkflowEvent<void> {}
class ProceedToPaymentEvent extends WorkflowEvent<void> {}
class ConfirmOrderEvent extends WorkflowEvent<void> {}
class SendConfirmationEmailEvent extends WorkflowEvent<void> {}
checkoutWorkflow.addStep(
{
inputs: [StartEvent],
outputs: [ProceedToPaymentEvent, ShowShippingInformationFormEvent],
},
async ({ data }, _) => {
const user = await getUser(data.userId);
if (user === null) {
return new ShowShippingInformationFormEvent();
}
// todo
return new ProceedToPaymentEvent();
},
);
checkoutWorkflow.addStep(
{
inputs: [ShowShippingInformationFormEvent],
outputs: [ProceedToPaymentEvent],
},
async ({ data }) => {
const user = await getUser(data.userId);
if (user === null) {
data.update("TODO");
data.interrupt();
}
return new ProceedToPaymentEvent();
},
);
checkoutWorkflow.addStep(
{
inputs: [ProceedToPaymentEvent],
outputs: [ConfirmOrderEvent],
},
async () => {
return new ConfirmOrderEvent();
},
);
checkoutWorkflow.addStep(
{
inputs: [ConfirmOrderEvent],
outputs: [SendConfirmationEmailEvent],
},
async () => {
return new SendConfirmationEmailEvent();
},
);
checkoutWorkflow.addStep(
{
inputs: [SendConfirmationEmailEvent],
outputs: [StopEvent<void>],
},
async () => {
return new StopEvent(void 0);
},
);
async function runContext(context: WorkflowContext<void, void, Context>) {
try {
await context;
} catch (e) {
if (e instanceof Error && e.message === "Interrupted") {
const snapshot = context.snapshot();
// for each step, save the snapshot into the local storage
localStorage.setItem(
"workflow-snapshot",
new TextDecoder().decode(snapshot),
);
} else {
throw e;
}
}
}
export const CheckoutDemo = () => {
const items = [
{ name: "T-Shirt", price: 19.99, quantity: 2 },
{ name: "Jeans", price: 49.99, quantity: 1 },
{ name: "Sneakers", price: 79.99, quantity: 1 },
];
const [ui, setUI] = useState<ReactNode>(null);
const [contextData, setContextData] = useState<Context>({
userId: "1",
items: items,
update: (ui) => setUI(ui),
interrupt: () => {
throw new Error("Interrupted");
},
});
const subtotal = items.reduce(
(acc, item) => acc + item.price * item.quantity,
0,
);
const tax = subtotal * 0.1; // Assuming 10% tax
const total = subtotal + tax;
const onClickStartCheckout = useCallback(() => {
const context = checkoutWorkflow.run().with(contextData);
runContext(context);
}, []);
return (
<div>
{ui}
<Card className="w-full max-w-md mx-auto">
<CardHeader>
<CardTitle>Your Order</CardTitle>
</CardHeader>
<CardContent>
<ul className="space-y-2">
{items.map((item, index) => (
<li key={index} className="flex justify-between items-center">
<span>
{item.name} x{item.quantity}
</span>
<span>${(item.price * item.quantity).toFixed(2)}</span>
</li>
))}
</ul>
<Separator className="my-4" />
<div className="space-y-2">
<div className="flex justify-between">
<span>Subtotal</span>
<span>${subtotal.toFixed(2)}</span>
</div>
<div className="flex justify-between">
<span>Tax</span>
<span>${tax.toFixed(2)}</span>
</div>
<div className="flex justify-between font-bold">
<span>Total</span>
<span>${total.toFixed(2)}</span>
</div>
</div>
</CardContent>
<CardFooter>
<Button className="w-full" onClick={onClickStartCheckout}>
Proceed to Checkout
</Button>
</CardFooter>
</Card>
</div>
);
};
@@ -1,126 +0,0 @@
"use client";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { useState } from "react";
export function ShippingForm({
onSubmit,
}: {
onSubmit: (data: ShippingInfo) => void;
}) {
const [formData, setFormData] = useState<ShippingInfo>({
fullName: "",
address: "",
city: "",
state: "",
zipCode: "",
country: "",
});
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
setFormData((prev) => ({ ...prev, [name]: value }));
};
const handleCountryChange = (value: string) => {
setFormData((prev) => ({ ...prev, country: value }));
};
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
onSubmit(formData);
};
return (
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<Label htmlFor="fullName">Full Name</Label>
<Input
id="fullName"
name="fullName"
value={formData.fullName}
onChange={handleChange}
required
/>
</div>
<div>
<Label htmlFor="address">Address</Label>
<Input
id="address"
name="address"
value={formData.address}
onChange={handleChange}
required
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div>
<Label htmlFor="city">City</Label>
<Input
id="city"
name="city"
value={formData.city}
onChange={handleChange}
required
/>
</div>
<div>
<Label htmlFor="state">State</Label>
<Input
id="state"
name="state"
value={formData.state}
onChange={handleChange}
required
/>
</div>
</div>
<div className="grid grid-cols-2 gap-4">
<div>
<Label htmlFor="zipCode">ZIP Code</Label>
<Input
id="zipCode"
name="zipCode"
value={formData.zipCode}
onChange={handleChange}
required
/>
</div>
<div>
<Label htmlFor="country">Country</Label>
<Select onValueChange={handleCountryChange} value={formData.country}>
<SelectTrigger id="country">
<SelectValue placeholder="Select country" />
</SelectTrigger>
<SelectContent>
<SelectItem value="us">United States</SelectItem>
<SelectItem value="ca">Canada</SelectItem>
<SelectItem value="uk">United Kingdom</SelectItem>
{/* Add more countries as needed */}
</SelectContent>
</Select>
</div>
</div>
<Button type="submit" className="w-full">
Save Shipping Information
</Button>
</form>
);
}
export interface ShippingInfo {
fullName: string;
address: string;
city: string;
state: string;
zipCode: string;
country: string;
}
-83
View File
@@ -1,83 +0,0 @@
import * as React from "react";
import { cn } from "@/lib/utils";
const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-xl border bg-card text-card-foreground shadow",
className,
)}
{...props}
/>
));
Card.displayName = "Card";
const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6", className)}
{...props}
/>
));
CardHeader.displayName = "CardHeader";
const CardTitle = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("font-semibold leading-none tracking-tight", className)}
{...props}
/>
));
CardTitle.displayName = "CardTitle";
const CardDescription = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
));
CardDescription.displayName = "CardDescription";
const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
));
CardContent.displayName = "CardContent";
const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex items-center p-6 pt-0", className)}
{...props}
/>
));
CardFooter.displayName = "CardFooter";
export {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
};
-162
View File
@@ -1,162 +0,0 @@
"use client";
import { cn } from "@/lib/utils";
import {
CheckIcon,
ChevronDownIcon,
ChevronUpIcon,
} from "@radix-ui/react-icons";
import * as SelectPrimitive from "@radix-ui/react-select";
import * as React from "react";
const Select = SelectPrimitive.Root;
const SelectGroup = SelectPrimitive.Group;
const SelectValue = SelectPrimitive.Value;
const SelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<SelectPrimitive.Trigger
ref={ref}
className={cn(
"flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
className,
)}
{...props}
>
{children}
<SelectPrimitive.Icon asChild>
<ChevronDownIcon className="h-4 w-4 opacity-50" />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
));
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
const SelectScrollUpButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollUpButton
ref={ref}
className={cn(
"flex cursor-default items-center justify-center py-1",
className,
)}
{...props}
>
<ChevronUpIcon className="h-4 w-4" />
</SelectPrimitive.ScrollUpButton>
));
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
const SelectScrollDownButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollDownButton
ref={ref}
className={cn(
"flex cursor-default items-center justify-center py-1",
className,
)}
{...props}
>
<ChevronDownIcon className="h-4 w-4" />
</SelectPrimitive.ScrollDownButton>
));
SelectScrollDownButton.displayName =
SelectPrimitive.ScrollDownButton.displayName;
const SelectContent = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
>(({ className, children, position = "popper", ...props }, ref) => (
<SelectPrimitive.Portal>
<SelectPrimitive.Content
ref={ref}
className={cn(
"relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
position === "popper" &&
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
className,
)}
position={position}
{...props}
>
<SelectScrollUpButton />
<SelectPrimitive.Viewport
className={cn(
"p-1",
position === "popper" &&
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]",
)}
>
{children}
</SelectPrimitive.Viewport>
<SelectScrollDownButton />
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
));
SelectContent.displayName = SelectPrimitive.Content.displayName;
const SelectLabel = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Label>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
>(({ className, ...props }, ref) => (
<SelectPrimitive.Label
ref={ref}
className={cn("px-2 py-1.5 text-sm font-semibold", className)}
{...props}
/>
));
SelectLabel.displayName = SelectPrimitive.Label.displayName;
const SelectItem = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
>(({ className, children, ...props }, ref) => (
<SelectPrimitive.Item
ref={ref}
className={cn(
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
className,
)}
{...props}
>
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
<SelectPrimitive.ItemIndicator>
<CheckIcon className="h-4 w-4" />
</SelectPrimitive.ItemIndicator>
</span>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
));
SelectItem.displayName = SelectPrimitive.Item.displayName;
const SelectSeparator = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
>(({ className, ...props }, ref) => (
<SelectPrimitive.Separator
ref={ref}
className={cn("-mx-1 my-1 h-px bg-muted", className)}
{...props}
/>
));
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
export {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectScrollDownButton,
SelectScrollUpButton,
SelectSeparator,
SelectTrigger,
SelectValue,
};
-31
View File
@@ -1,31 +0,0 @@
"use client";
import * as SeparatorPrimitive from "@radix-ui/react-separator";
import * as React from "react";
import { cn } from "@/lib/utils";
const Separator = React.forwardRef<
React.ElementRef<typeof SeparatorPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
>(
(
{ className, orientation = "horizontal", decorative = true, ...props },
ref,
) => (
<SeparatorPrimitive.Root
ref={ref}
decorative={decorative}
orientation={orientation}
className={cn(
"shrink-0 bg-border",
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
className,
)}
{...props}
/>
),
);
Separator.displayName = SeparatorPrimitive.Root.displayName;
export { Separator };
@@ -1,19 +0,0 @@
---
title: Event Step Handler
description: Learn how to design a good event handler for your workflow.
---
import { CheckoutDemo } from '../../../../../components/demo/checkout'
Let's start an checkout workflow.
<div className='grid grid-cols-2 gap-4'>
<CheckoutDemo/>
<div
className='border p-4'
style={{
borderColor: 'hsl(var(--border))'
}}
>
[![](https://mermaid.ink/img/pako:eNptkd9ugyAUxl-FcN2-gEu2zD9t7dKtmcuSDXtB5KikCgaPWxrruw_RtmkyruB8Pz7O4etppgVQjxaGNyX5CB9SRex6ZglygyQoITvqDg9kuXwkPvuU8EsCqxwmznf1gEUKwZCklE0jVUFilWtTc5RazWDgwJAlUEGGN3IHWGoxQ6GDotltz081KPzHLHLcir3Dz9jPmxFgZmnlpHUft1OZBNoY--LTMOnrUT9_QXsmG7aveAZ31yf5VZ-JPxU2zi9mFzOVy_teYgds7WBK3OkkqrmsZmrrqBc7mbj9aarogtZgeSlsBP2IphRLqCGlnt0Kbo4pTdVgOd6hTk4qox6aDhbU6K4oqZfzqrWnrhEcIZTc5lhfkIarb62vRxAStdlNebvYhz_ob6Ka?type=png)](https://mermaid.live/edit#pako:eNptkd9ugyAUxl-FcN2-gEu2zD9t7dKtmcuSDXtB5KikCgaPWxrruw_RtmkyruB8Pz7O4etppgVQjxaGNyX5CB9SRex6ZglygyQoITvqDg9kuXwkPvuU8EsCqxwmznf1gEUKwZCklE0jVUFilWtTc5RazWDgwJAlUEGGN3IHWGoxQ6GDotltz081KPzHLHLcir3Dz9jPmxFgZmnlpHUft1OZBNoY--LTMOnrUT9_QXsmG7aveAZ31yf5VZ-JPxU2zi9mFzOVy_teYgds7WBK3OkkqrmsZmrrqBc7mbj9aarogtZgeSlsBP2IphRLqCGlnt0Kbo4pTdVgOd6hTk4qox6aDhbU6K4oqZfzqrWnrhEcIZTc5lhfkIarb62vRxAStdlNebvYhz_ob6Ka)
</div>
</div>
@@ -2,12 +2,5 @@
"title": "Workflow",
"description": "See how to use @llamaindex/workflow",
"defaultOpen": false,
"pages": [
"index",
"different-inputs-outputs",
"streaming",
"---Advanced concept---",
"handler",
"..."
]
"pages": ["index", "different-inputs-outputs", "streaming"]
}
@@ -1,5 +1,11 @@
# @llamaindex/cloudflare-worker-agent-test
## 0.0.109
### Patch Changes
- llamaindex@0.8.13
## 0.0.108
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/cloudflare-worker-agent-test",
"version": "0.0.108",
"version": "0.0.109",
"type": "module",
"private": true,
"scripts": {
@@ -1,5 +1,11 @@
# @llamaindex/llama-parse-browser-test
## 0.0.30
### Patch Changes
- @llamaindex/cloud@2.0.10
## 0.0.29
### Patch Changes
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/llama-parse-browser-test",
"private": true,
"version": "0.0.29",
"version": "0.0.30",
"type": "module",
"scripts": {
"dev": "vite",
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/next-agent-test
## 0.1.109
### Patch Changes
- llamaindex@0.8.13
## 0.1.108
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-agent-test",
"version": "0.1.108",
"version": "0.1.109",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,11 @@
# test-edge-runtime
## 0.1.108
### Patch Changes
- llamaindex@0.8.13
## 0.1.107
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/nextjs-edge-runtime-test",
"version": "0.1.107",
"version": "0.1.108",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,11 @@
# @llamaindex/next-node-runtime
## 0.0.90
### Patch Changes
- llamaindex@0.8.13
## 0.0.89
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-node-runtime-test",
"version": "0.0.89",
"version": "0.0.90",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,11 @@
# @llamaindex/waku-query-engine-test
## 0.0.109
### Patch Changes
- llamaindex@0.8.13
## 0.0.108
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/waku-query-engine-test",
"version": "0.0.108",
"version": "0.0.109",
"type": "module",
"private": true,
"scripts": {
+20
View File
@@ -1,5 +1,25 @@
# examples
## 0.0.16
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [ee20c44]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
- @llamaindex/workflow@0.0.6
- llamaindex@0.8.13
- @llamaindex/readers@1.0.11
## 0.0.15
### Patch Changes
- Updated dependencies [ea92b69]
- Updated dependencies [fadc8b8]
- @llamaindex/workflow@0.0.5
## 0.0.14
### Patch Changes
+38
View File
@@ -0,0 +1,38 @@
import { Anthropic } from "llamaindex";
async function main() {
const anthropic = new Anthropic({
model: "claude-3-5-sonnet-20241022",
});
const entireBook = await fetch(
"https://www.gutenberg.org/files/1342/1342-0.txt",
).then((response) => response.text());
const response = await anthropic.chat({
messages: [
{
content:
"You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.\n",
role: "system",
},
{
content: entireBook,
role: "system",
options: {
cache_control: {
type: "ephemeral",
},
},
},
{
content: "analyze the major themes in Pride and Prejudice.",
role: "user",
},
],
});
console.log(response.message.content);
}
main().catch(console.error);
+5 -5
View File
@@ -1,15 +1,15 @@
{
"name": "@llamaindex/examples",
"private": true,
"version": "0.0.14",
"version": "0.0.16",
"dependencies": {
"@aws-crypto/sha256-js": "^5.2.0",
"@azure/cosmos": "^4.1.1",
"@azure/identity": "^4.4.1",
"@datastax/astra-db-ts": "^1.4.1",
"@llamaindex/core": "^0.4.7",
"@llamaindex/readers": "^1.0.8",
"@llamaindex/workflow": "^0.0.4",
"@llamaindex/core": "^0.4.10",
"@llamaindex/readers": "^1.0.11",
"@llamaindex/workflow": "^0.0.6",
"@notionhq/client": "^2.2.15",
"@pinecone-database/pinecone": "^3.0.2",
"@vercel/postgres": "^0.10.0",
@@ -18,7 +18,7 @@
"commander": "^12.1.0",
"dotenv": "^16.4.5",
"js-tiktoken": "^1.0.14",
"llamaindex": "^0.8.10",
"llamaindex": "^0.8.13",
"mongodb": "^6.7.0",
"pathe": "^1.1.2",
"postgres": "^3.4.4"
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/autotool
## 5.0.13
### Patch Changes
- llamaindex@0.8.13
## 5.0.12
### Patch Changes
@@ -1,5 +1,12 @@
# @llamaindex/autotool-01-node-example
## 0.0.56
### Patch Changes
- llamaindex@0.8.13
- @llamaindex/autotool@5.0.13
## 0.0.55
### Patch Changes
@@ -13,5 +13,5 @@
"scripts": {
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
},
"version": "0.0.55"
"version": "0.0.56"
}
@@ -1,5 +1,12 @@
# @llamaindex/autotool-02-next-example
## 0.1.100
### Patch Changes
- llamaindex@0.8.13
- @llamaindex/autotool@5.0.13
## 0.1.99
### Patch Changes
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/autotool-02-next-example",
"private": true,
"version": "0.1.99",
"version": "0.1.100",
"scripts": {
"dev": "next dev",
"build": "next build",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/autotool",
"type": "module",
"version": "5.0.12",
"version": "5.0.13",
"description": "auto transpile your JS function to LLM Agent compatible",
"files": [
"dist",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/cloud
## 2.0.10
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
## 2.0.9
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/cloud",
"version": "2.0.9",
"version": "2.0.10",
"type": "module",
"license": "MIT",
"scripts": {
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/community
## 0.0.68
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
## 0.0.67
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/community",
"description": "Community package for LlamaIndexTS",
"version": "0.0.67",
"version": "0.0.68",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
+7
View File
@@ -1,5 +1,12 @@
# @llamaindex/core
## 0.4.10
### Patch Changes
- a7b0ac3: fix: update tool call llm type
- c69605f: feat: add async support to BaseChatStore and BaseChatStoreMemory
## 0.4.9
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/core",
"type": "module",
"version": "0.4.9",
"version": "0.4.10",
"description": "LlamaIndex Core Module",
"exports": {
"./agent": {
+3 -1
View File
@@ -66,6 +66,8 @@ export abstract class BaseLLM<
export abstract class ToolCallLLM<
AdditionalChatOptions extends object = object,
> extends BaseLLM<AdditionalChatOptions, ToolCallLLMMessageOptions> {
AdditionalMessageOptions extends
ToolCallLLMMessageOptions = ToolCallLLMMessageOptions,
> extends BaseLLM<AdditionalChatOptions, AdditionalMessageOptions> {
abstract supportToolCall: boolean;
}
+3 -3
View File
@@ -71,15 +71,15 @@ export abstract class BaseChatStoreMemory<
return this.chatStore.getMessages(this.chatStoreKey);
}
put(messages: ChatMessage<AdditionalMessageOptions>) {
put(messages: ChatMessage<AdditionalMessageOptions>): void | Promise<void> {
this.chatStore.addMessage(this.chatStoreKey, messages);
}
set(messages: ChatMessage<AdditionalMessageOptions>[]) {
set(messages: ChatMessage<AdditionalMessageOptions>[]): void | Promise<void> {
this.chatStore.setMessages(this.chatStoreKey, messages);
}
reset() {
reset(): void | Promise<void> {
this.chatStore.deleteMessages(this.chatStoreKey);
}
}
@@ -19,5 +19,7 @@ export abstract class BaseChatStore<
): void;
abstract deleteMessages(key: string): void;
abstract deleteMessage(key: string, idx: number): void;
abstract getKeys(): IterableIterator<string>;
abstract getKeys():
| IterableIterator<string>
| Promise<IterableIterator<string>>;
}
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/experimental
## 0.0.125
### Patch Changes
- llamaindex@0.8.13
## 0.0.124
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/experimental",
"description": "Experimental package for LlamaIndexTS",
"version": "0.0.124",
"version": "0.0.125",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
+22
View File
@@ -1,5 +1,27 @@
# llamaindex
## 0.8.13
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/anthropic@0.0.19
- @llamaindex/core@0.4.10
- @llamaindex/cloud@2.0.10
- @llamaindex/node-parser@0.0.11
- @llamaindex/clip@0.0.19
- @llamaindex/deepinfra@0.0.19
- @llamaindex/huggingface@0.0.19
- @llamaindex/ollama@0.0.26
- @llamaindex/openai@0.1.35
- @llamaindex/portkey-ai@0.0.19
- @llamaindex/replicate@0.0.19
- @llamaindex/readers@1.0.11
- @llamaindex/groq@0.0.34
- @llamaindex/vllm@0.0.5
## 0.8.12
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "llamaindex",
"version": "0.8.12",
"version": "0.8.13",
"license": "MIT",
"type": "module",
"keywords": [
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/node-parser
## 0.0.11
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
## 0.0.10
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/node-parser",
"version": "0.0.10",
"version": "0.0.11",
"description": "Node parser for LlamaIndex",
"type": "module",
"exports": {
@@ -1,5 +1,14 @@
# @llamaindex/anthropic
## 0.0.19
### Patch Changes
- a7b0ac3: feat(anthropic): support prompt caching
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
## 0.0.18
### Patch Changes
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/anthropic",
"description": "Anthropic Adapter for LlamaIndex",
"version": "0.0.18",
"version": "0.0.19",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -33,7 +33,7 @@
"bunchee": "5.6.1"
},
"dependencies": {
"@anthropic-ai/sdk": "0.27.1",
"@anthropic-ai/sdk": "0.32.1",
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*",
"remeda": "^2.12.0"
+76 -23
View File
@@ -1,5 +1,9 @@
import type { ClientOptions } from "@anthropic-ai/sdk";
import { Anthropic as SDKAnthropic } from "@anthropic-ai/sdk";
import type {
BetaCacheControlEphemeral,
BetaTextBlockParam,
} from "@anthropic-ai/sdk/resources/beta/index";
import type {
TextBlock,
TextBlockParam,
@@ -8,6 +12,7 @@ import type {
ImageBlockParam,
MessageCreateParamsNonStreaming,
MessageParam,
Model,
Tool,
ToolResultBlockParam,
ToolUseBlock,
@@ -75,6 +80,9 @@ export const ALL_AVAILABLE_ANTHROPIC_LEGACY_MODELS = {
"claude-2.1": {
contextWindow: 200000,
},
"claude-2.0": {
contextWindow: 100000,
},
"claude-instant-1.2": {
contextWindow: 100000,
},
@@ -82,18 +90,30 @@ export const ALL_AVAILABLE_ANTHROPIC_LEGACY_MODELS = {
export const ALL_AVAILABLE_V3_MODELS = {
"claude-3-opus": { contextWindow: 200000 },
"claude-3-opus-latest": { contextWindow: 200000 },
"claude-3-opus-20240229": { contextWindow: 200000 },
"claude-3-sonnet": { contextWindow: 200000 },
"claude-3-sonnet-20240229": { contextWindow: 200000 },
"claude-3-haiku": { contextWindow: 200000 },
"claude-3-haiku-20240307": { contextWindow: 200000 },
};
export const ALL_AVAILABLE_V3_5_MODELS = {
"claude-3-5-sonnet": { contextWindow: 200000 },
"claude-3-5-sonnet-20241022": { contextWindow: 200000 },
"claude-3-5-sonnet-20240620": { contextWindow: 200000 },
"claude-3-5-sonnet-latest": { contextWindow: 200000 },
"claude-3-5-haiku": { contextWindow: 200000 },
"claude-3-5-haiku-latest": { contextWindow: 200000 },
"claude-3-5-haiku-20241022": { contextWindow: 200000 },
};
export const ALL_AVAILABLE_ANTHROPIC_MODELS = {
...ALL_AVAILABLE_ANTHROPIC_LEGACY_MODELS,
...ALL_AVAILABLE_V3_MODELS,
...ALL_AVAILABLE_V3_5_MODELS,
} satisfies {
[key in Model]: { contextWindow: number };
};
const AVAILABLE_ANTHROPIC_MODELS_WITHOUT_DATE: { [key: string]: string } = {
@@ -104,10 +124,16 @@ const AVAILABLE_ANTHROPIC_MODELS_WITHOUT_DATE: { [key: string]: string } = {
} as { [key in keyof typeof ALL_AVAILABLE_ANTHROPIC_MODELS]: string };
export type AnthropicAdditionalChatOptions = object;
export type AnthropicToolCallLLMMessageOptions = ToolCallLLMMessageOptions & {
cache_control?: BetaCacheControlEphemeral | null;
};
export class Anthropic extends ToolCallLLM<AnthropicAdditionalChatOptions> {
export class Anthropic extends ToolCallLLM<
AnthropicAdditionalChatOptions,
AnthropicToolCallLLMMessageOptions
> {
// Per completion Anthropic params
model: keyof typeof ALL_AVAILABLE_ANTHROPIC_MODELS;
model: keyof typeof ALL_AVAILABLE_ANTHROPIC_MODELS | ({} & string);
temperature: number;
topP: number;
maxTokens?: number | undefined;
@@ -147,7 +173,12 @@ export class Anthropic extends ToolCallLLM<AnthropicAdditionalChatOptions> {
temperature: this.temperature,
topP: this.topP,
maxTokens: this.maxTokens,
contextWindow: ALL_AVAILABLE_ANTHROPIC_MODELS[this.model].contextWindow,
contextWindow:
this.model in ALL_AVAILABLE_ANTHROPIC_MODELS
? ALL_AVAILABLE_ANTHROPIC_MODELS[
this.model as keyof typeof ALL_AVAILABLE_ANTHROPIC_MODELS
].contextWindow
: 200000,
tokenizer: undefined,
};
}
@@ -291,56 +322,74 @@ export class Anthropic extends ToolCallLLM<AnthropicAdditionalChatOptions> {
chat(
params: LLMChatParamsStreaming<
AnthropicAdditionalChatOptions,
ToolCallLLMMessageOptions
AnthropicToolCallLLMMessageOptions
>,
): Promise<AsyncIterable<ChatResponseChunk<ToolCallLLMMessageOptions>>>;
): Promise<
AsyncIterable<ChatResponseChunk<AnthropicToolCallLLMMessageOptions>>
>;
chat(
params: LLMChatParamsNonStreaming<
AnthropicAdditionalChatOptions,
ToolCallLLMMessageOptions
AnthropicToolCallLLMMessageOptions
>,
): Promise<ChatResponse<ToolCallLLMMessageOptions>>;
): Promise<ChatResponse<AnthropicToolCallLLMMessageOptions>>;
@wrapLLMEvent
async chat(
params:
| LLMChatParamsNonStreaming<
AnthropicAdditionalChatOptions,
ToolCallLLMMessageOptions
AnthropicToolCallLLMMessageOptions
>
| LLMChatParamsStreaming<
AnthropicAdditionalChatOptions,
ToolCallLLMMessageOptions
AnthropicToolCallLLMMessageOptions
>,
): Promise<
| ChatResponse<ToolCallLLMMessageOptions>
| AsyncIterable<ChatResponseChunk<ToolCallLLMMessageOptions>>
| ChatResponse<AnthropicToolCallLLMMessageOptions>
| AsyncIterable<ChatResponseChunk<AnthropicToolCallLLMMessageOptions>>
> {
let { messages } = params;
const { stream, tools } = params;
let systemPrompt: string | null = null;
let systemPrompt: string | Array<BetaTextBlockParam> | null = null;
const systemMessages = messages.filter(
(message) => message.role === "system",
);
if (systemMessages.length > 0) {
systemPrompt = systemMessages
.map((message) => message.content)
.join("\n");
systemPrompt = systemMessages.map((message) =>
message.options && "cache_control" in message.options
? {
type: "text",
text: extractText(message.content),
cache_control: message.options.cache_control,
}
: {
type: "text",
text: extractText(message.content),
},
);
messages = messages.filter((message) => message.role !== "system");
}
const beta =
systemPrompt?.find((message) => "cache_control" in message) !== undefined;
// case: Non-streaming
let anthropic = this.session.anthropic;
if (beta) {
// @ts-expect-error type casting
anthropic = anthropic.beta.promptCaching;
}
// case: Streaming
if (stream) {
if (tools) {
console.error("Tools are not supported in streaming mode");
}
return this.streamChat(messages, systemPrompt);
return this.streamChat(messages, systemPrompt, anthropic);
}
// case: Non-streaming
const anthropic = this.session.anthropic;
if (tools) {
const params: MessageCreateParamsNonStreaming = {
@@ -378,7 +427,10 @@ export class Anthropic extends ToolCallLLM<AnthropicAdditionalChatOptions> {
toolCall: toolUseBlock.map((block) => ({
id: block.id,
name: block.name,
input: block.input,
input:
typeof block.input === "object"
? JSON.stringify(block.input)
: `${block.input}`,
})),
}
: {},
@@ -411,10 +463,11 @@ export class Anthropic extends ToolCallLLM<AnthropicAdditionalChatOptions> {
}
protected async *streamChat(
messages: ChatMessage<ToolCallLLMMessageOptions>[],
systemPrompt?: string | null,
): AsyncIterable<ChatResponseChunk<ToolCallLLMMessageOptions>> {
const stream = await this.session.anthropic.messages.create({
messages: ChatMessage<AnthropicToolCallLLMMessageOptions>[],
systemPrompt: string | Array<BetaTextBlockParam> | null,
anthropic: SDKAnthropic,
): AsyncIterable<ChatResponseChunk<AnthropicToolCallLLMMessageOptions>> {
const stream = await anthropic.messages.create({
model: this.getModelName(this.model),
messages: this.formatMessages(messages),
max_tokens: this.maxTokens ?? 4096,
+9
View File
@@ -1,5 +1,14 @@
# @llamaindex/clip
## 0.0.19
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
- @llamaindex/openai@0.1.35
## 0.0.18
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/clip",
"description": "Clip Embedding Adapter for LlamaIndex",
"version": "0.0.18",
"version": "0.0.19",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
@@ -1,5 +1,14 @@
# @llamaindex/deepinfra
## 0.0.19
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
- @llamaindex/openai@0.1.35
## 0.0.18
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/deepinfra",
"description": "Deepinfra Adapter for LlamaIndex",
"version": "0.0.18",
"version": "0.0.19",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/groq
## 0.0.34
### Patch Changes
- @llamaindex/openai@0.1.35
## 0.0.33
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/groq",
"description": "Groq Adapter for LlamaIndex",
"version": "0.0.33",
"version": "0.0.34",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -1,5 +1,14 @@
# @llamaindex/huggingface
## 0.0.19
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
- @llamaindex/openai@0.1.35
## 0.0.18
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/huggingface",
"description": "Huggingface Adapter for LlamaIndex",
"version": "0.0.18",
"version": "0.0.19",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/ollama
## 0.0.26
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
## 0.0.25
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/ollama",
"description": "Ollama Adapter for LlamaIndex",
"version": "0.0.25",
"version": "0.0.26",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/openai
## 0.1.35
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
## 0.1.34
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/openai",
"description": "OpenAI Adapter for LlamaIndex",
"version": "0.1.34",
"version": "0.1.35",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -1,5 +1,13 @@
# @llamaindex/portkey-ai
## 0.0.19
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
## 0.0.18
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/portkey-ai",
"description": "Portkey Adapter for LlamaIndex",
"version": "0.0.18",
"version": "0.0.19",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -1,5 +1,13 @@
# @llamaindex/replicate
## 0.0.19
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
## 0.0.18
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/replicate",
"description": "Replicate Adapter for LlamaIndex",
"version": "0.0.18",
"version": "0.0.19",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/vllm
## 0.0.5
### Patch Changes
- @llamaindex/openai@0.1.35
## 0.0.4
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/vllm",
"description": "vLLM Adapter for LlamaIndex",
"version": "0.0.4",
"version": "0.0.5",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+8
View File
@@ -1,5 +1,13 @@
# @llamaindex/readers
## 1.0.11
### Patch Changes
- Updated dependencies [a7b0ac3]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
## 1.0.10
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/readers",
"description": "LlamaIndex Readers",
"version": "1.0.10",
"version": "1.0.11",
"type": "module",
"exports": {
"./node/hook": "./node/dist/hook.js",
+13
View File
@@ -1,5 +1,18 @@
# @llamaindex/workflow
## 0.0.6
### Patch Changes
- ee20c44: feat(workflow): allow send event with no output
## 0.0.5
### Patch Changes
- ea92b69: fix: output event check
- fadc8b8: feat: recoverable context with error handling
## 0.0.4
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/workflow",
"description": "Workflow API",
"version": "0.0.4",
"version": "0.0.6",
"type": "module",
"types": "dist/index.d.ts",
"module": "dist/index.js",
+103 -96
View File
@@ -13,19 +13,18 @@ export type StepHandler<
AnyWorkflowEventConstructor | StartEventConstructor,
...(AnyWorkflowEventConstructor | StopEventConstructor)[],
] = [AnyWorkflowEventConstructor | StartEventConstructor],
Out extends [
AnyWorkflowEventConstructor | StartEventConstructor,
...(AnyWorkflowEventConstructor | StopEventConstructor)[],
] = [AnyWorkflowEventConstructor | StopEventConstructor],
Out extends (AnyWorkflowEventConstructor | StopEventConstructor)[] = [],
> = (
context: HandlerContext<Data>,
...events: {
[K in keyof Inputs]: InstanceType<Inputs[K]>;
}
) => Promise<
{
[K in keyof Out]: InstanceType<Out[K]>;
}[number]
Out extends []
? void
: {
[K in keyof Out]: InstanceType<Out[K]>;
}[number]
>;
export type ReadonlyStepMap<Data> = ReadonlyMap<
@@ -275,7 +274,7 @@ export class WorkflowContext<Start = string, Stop = string, Data = unknown>
*/
#createStreamEvents(): AsyncIterableIterator<WorkflowEvent<unknown>> {
const isPendingEvents = new WeakSet<WorkflowEvent<unknown>>();
const pendingTasks = new Set<Promise<WorkflowEvent<unknown>>>();
const pendingTasks = new Set<Promise<WorkflowEvent<unknown> | void>>();
const enqueuedEvents = new Set<WorkflowEvent<unknown>>();
const stream = new ReadableStream<WorkflowEvent<unknown>>({
start: async (controller) => {
@@ -325,102 +324,104 @@ export class WorkflowContext<Start = string, Stop = string, Data = unknown>
}
const [steps, inputsMap, outputsMap] =
this.#getStepFunction(event);
const nextEventPromises: Promise<WorkflowEvent<unknown>>[] = [
...steps,
]
.map((step) => {
const inputs = [...(inputsMap.get(step) ?? [])];
const acceptableInputs: WorkflowEvent<unknown>[] =
this.#pendingInputQueue.filter((event) =>
inputs.some((input) => event instanceof input),
);
const events: WorkflowEvent<unknown>[] = flattenEvents(
inputs,
[event, ...acceptableInputs],
);
// remove the event from the queue, in case of infinite loop
events.forEach((event) => {
const protocolIdx = this.#queue.findIndex(
(protocol) =>
protocol.type === "event" &&
protocol.event === event,
);
if (protocolIdx !== -1) {
this.#queue.splice(protocolIdx, 1);
}
});
if (events.length !== inputs.length) {
if (this.#verbose) {
console.log(
`Not enough inputs for step ${step.name}, waiting for more events`,
const nextEventPromises: Promise<WorkflowEvent<unknown> | void>[] =
[...steps]
.map((step) => {
const inputs = [...(inputsMap.get(step) ?? [])];
const acceptableInputs: WorkflowEvent<unknown>[] =
this.#pendingInputQueue.filter((event) =>
inputs.some((input) => event instanceof input),
);
}
// not enough to run the step, push back to the queue
this.#sendEvent(event);
isPendingEvents.add(event);
return null;
}
if (isPendingEvents.has(event)) {
isPendingEvents.delete(event);
}
if (this.#verbose) {
console.log(
`Running step ${step.name} with inputs ${events}`,
const events: WorkflowEvent<unknown>[] = flattenEvents(
inputs,
[event, ...acceptableInputs],
);
}
const data = this.data;
return (step as StepHandler<Data>)
.call(
null,
{
get data() {
return data;
},
sendEvent: this.#sendEvent,
requireEvent: this.#requireEvent,
},
// @ts-expect-error IDK why
...events.sort((a, b) => {
const aIndex = inputs.indexOf(
a.constructor as AnyWorkflowEventConstructor,
);
const bIndex = inputs.indexOf(
b.constructor as AnyWorkflowEventConstructor,
);
return aIndex - bIndex;
}),
)
.then((nextEvent) => {
// remove the event from the queue, in case of infinite loop
events.forEach((event) => {
const protocolIdx = this.#queue.findIndex(
(protocol) =>
protocol.type === "event" &&
protocol.event === event,
);
if (protocolIdx !== -1) {
this.#queue.splice(protocolIdx, 1);
}
});
if (events.length !== inputs.length) {
if (this.#verbose) {
console.log(
`Step ${step.name} completed, next event is ${nextEvent}`,
`Not enough inputs for step ${step.name}, waiting for more events`,
);
}
const outputs = outputsMap.get(step) ?? [];
if (
!outputs.some(
(output) => nextEvent.constructor === output,
)
) {
if (this.#strict) {
const error = Error(
`Step ${step.name} returned an unexpected output event ${nextEvent}`,
// not enough to run the step, push back to the queue
this.#sendEvent(event);
isPendingEvents.add(event);
return null;
}
if (isPendingEvents.has(event)) {
isPendingEvents.delete(event);
}
if (this.#verbose) {
console.log(
`Running step ${step.name} with inputs ${events}`,
);
}
const data = this.data;
return (step as StepHandler<Data>)
.call(
null,
{
get data() {
return data;
},
sendEvent: this.#sendEvent,
requireEvent: this.#requireEvent,
},
// @ts-expect-error IDK why
...events.sort((a, b) => {
const aIndex = inputs.indexOf(
a.constructor as AnyWorkflowEventConstructor,
);
controller.error(error);
} else {
console.warn(
`Step ${step.name} returned an unexpected output event ${nextEvent}`,
const bIndex = inputs.indexOf(
b.constructor as AnyWorkflowEventConstructor,
);
return aIndex - bIndex;
}),
)
.then((nextEvent: void | WorkflowEvent<unknown>) => {
if (nextEvent === undefined) {
return;
}
if (this.#verbose) {
console.log(
`Step ${step.name} completed, next event is ${nextEvent}`,
);
}
}
if (!(nextEvent instanceof StopEvent)) {
this.#pendingInputQueue.unshift(nextEvent);
this.#sendEvent(nextEvent);
}
return nextEvent;
});
})
.filter((promise) => promise !== null);
const outputs = outputsMap.get(step) ?? [];
if (
!outputs.some(
(output) => nextEvent.constructor === output,
)
) {
if (this.#strict) {
const error = Error(
`Step ${step.name} returned an unexpected output event ${nextEvent}`,
);
controller.error(error);
} else {
console.warn(
`Step ${step.name} returned an unexpected output event ${nextEvent}`,
);
}
}
if (!(nextEvent instanceof StopEvent)) {
this.#pendingInputQueue.unshift(nextEvent);
this.#sendEvent(nextEvent);
}
return nextEvent;
});
})
.filter((promise) => promise !== null);
nextEventPromises.forEach((promise) => {
pendingTasks.add(promise);
promise
@@ -433,6 +434,9 @@ export class WorkflowContext<Start = string, Stop = string, Data = unknown>
});
Promise.race(nextEventPromises)
.then((fastestNextEvent) => {
if (fastestNextEvent === undefined) {
return;
}
if (!enqueuedEvents.has(fastestNextEvent)) {
controller.enqueue(fastestNextEvent);
enqueuedEvents.add(fastestNextEvent);
@@ -441,7 +445,10 @@ export class WorkflowContext<Start = string, Stop = string, Data = unknown>
})
.then(async (fastestNextEvent) =>
Promise.all(nextEventPromises).then((nextEvents) => {
for (const nextEvent of nextEvents) {
const events = nextEvents.filter(
(event) => event !== undefined,
);
for (const nextEvent of events) {
// do not enqueue the same event twice
if (fastestNextEvent !== nextEvent) {
if (!enqueuedEvents.has(nextEvent)) {
+6 -7
View File
@@ -57,10 +57,7 @@ export class Workflow<ContextData, Start, Stop> {
AnyWorkflowEventConstructor | StartEventConstructor,
...(AnyWorkflowEventConstructor | StopEventConstructor)[],
],
const Out extends [
AnyWorkflowEventConstructor | StopEventConstructor,
...(AnyWorkflowEventConstructor | StopEventConstructor)[],
],
const Out extends (AnyWorkflowEventConstructor | StopEventConstructor)[],
>(
parameters: StepParameters<In, Out>,
stepFn: (
@@ -69,9 +66,11 @@ export class Workflow<ContextData, Start, Stop> {
[K in keyof In]: InstanceType<In[K]>;
}
) => Promise<
{
[K in keyof Out]: InstanceType<Out[K]>;
}[number]
Out extends []
? void
: {
[K in keyof Out]: InstanceType<Out[K]>;
}[number]
>,
): this {
const { inputs, outputs } = parameters;
+147 -1124
View File
File diff suppressed because it is too large Load Diff
+24
View File
@@ -1,5 +1,29 @@
# @llamaindex/unit-test
## 0.0.23
### Patch Changes
- ee20c44: feat(workflow): allow send event with no output
- Updated dependencies [a7b0ac3]
- Updated dependencies [ee20c44]
- Updated dependencies [c69605f]
- @llamaindex/core@0.4.10
- @llamaindex/workflow@0.0.6
- llamaindex@0.8.13
- @llamaindex/cloud@2.0.10
- @llamaindex/node-parser@0.0.11
- @llamaindex/openai@0.1.35
- @llamaindex/readers@1.0.11
## 0.0.22
### Patch Changes
- Updated dependencies [ea92b69]
- Updated dependencies [fadc8b8]
- @llamaindex/workflow@0.0.5
## 0.0.21
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/unit-test",
"private": true,
"version": "0.0.21",
"version": "0.0.23",
"type": "module",
"scripts": {
"test": "vitest run"
+15
View File
@@ -531,6 +531,21 @@ describe("workflow basic", () => {
const result = await myWorkflow.run("start");
expect(result.data).toBe("query result");
});
test("allow output with send event", async () => {
const myFlow = new Workflow<unknown, string, string>({ verbose: true });
myFlow.addStep(
{
inputs: [StartEvent<string>],
outputs: [],
},
async (context, ev) => {
context.sendEvent(new StopEvent(`Hello ${ev.data}!`));
},
);
const result = myFlow.run("world");
expect((await result).data).toBe("Hello world!");
});
});
describe("workflow event loop", () => {