Compare commits

...

15 Commits

Author SHA1 Message Date
Alex Yang 733c0e3057 fix: interrupt 2024-11-13 11:01:28 -08:00
Alex Yang 628be9eb66 Merge remote-tracking branch 'origin/main' into himself65/20241113/warn 2024-11-13 01:18:19 -08:00
Alex Yang fadc8b8ea0 feat: recoverable data with error handling (#1476) 2024-11-13 01:15:50 -08:00
Alex Yang ea92b6986d chore: update changeset 2024-11-13 01:15:28 -08:00
Alex Yang 1c103921ae changeset 2024-11-13 01:09:30 -08:00
Alex Yang f4cf37b643 feat: recoverable data with error handling 2024-11-13 01:08:34 -08:00
Alex Yang 463bf8b630 fix: code 2024-11-13 00:48:03 -08:00
Alex Yang 236828a331 Merge remote-tracking branch 'origin/main' into himself65/20241113/warn 2024-11-13 00:47:03 -08:00
Alex Yang 17f9022d22 fix: output event check (#1475) 2024-11-13 00:46:35 -08:00
Alex Yang b86208b703 docs: update 2024-11-13 00:27:05 -08:00
github-actions[bot] 14792cd8b4 Release 0.8.12 (#1473)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-11-12 16:20:25 -08:00
Alex Yang 7ae6eaa0a2 chore: update changeset 2024-11-12 12:49:17 -08:00
Alex Yang dbb5bd9f23 feat: allow tool_choice for OpenAIAgent (#1472) 2024-11-12 12:46:57 -08:00
github-actions[bot] aacd606204 Release 0.8.11 (#1471)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-11-12 11:49:22 -08:00
Alex Yang f865c984d3 feat: async get message on chat store (#1470) 2024-11-12 10:59:44 -08:00
82 changed files with 2535 additions and 206 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/workflow": patch
---
fix: output event check
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/workflow": patch
---
feat: recoverable context with error handling
+12
View File
@@ -1,5 +1,17 @@
# docs
## 0.0.116
### Patch Changes
- llamaindex@0.8.12
## 0.0.115
### Patch Changes
- llamaindex@0.8.11
## 0.0.114
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.0.114",
"version": "0.0.116",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
+24
View File
@@ -1,5 +1,29 @@
# @llamaindex/doc
## 0.0.14
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
- @llamaindex/openai@0.1.34
- @llamaindex/cloud@2.0.9
- llamaindex@0.8.12
- @llamaindex/node-parser@0.0.10
- @llamaindex/readers@1.0.10
## 0.0.13
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
- @llamaindex/cloud@2.0.8
- llamaindex@0.8.11
- @llamaindex/node-parser@0.0.9
- @llamaindex/openai@0.1.33
- @llamaindex/readers@1.0.9
## 0.0.12
### Patch Changes
+10
View File
@@ -6,6 +6,16 @@ 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"];
+4 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/doc",
"version": "0.0.12",
"version": "0.0.14",
"private": true,
"scripts": {
"build": "pnpm run build:docs && next build",
@@ -24,6 +24,8 @@
"@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",
@@ -52,6 +54,7 @@
"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",
+213
View File
@@ -0,0 +1,213 @@
"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>
);
};
@@ -0,0 +1,126 @@
"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
@@ -0,0 +1,83 @@
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
@@ -0,0 +1,162 @@
"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
@@ -0,0 +1,31 @@
"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 };
@@ -0,0 +1,19 @@
---
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,5 +2,12 @@
"title": "Workflow",
"description": "See how to use @llamaindex/workflow",
"defaultOpen": false,
"pages": ["index", "different-inputs-outputs", "streaming"]
"pages": [
"index",
"different-inputs-outputs",
"streaming",
"---Advanced concept---",
"handler",
"..."
]
}
@@ -1,5 +1,17 @@
# @llamaindex/cloudflare-worker-agent-test
## 0.0.108
### Patch Changes
- llamaindex@0.8.12
## 0.0.107
### Patch Changes
- llamaindex@0.8.11
## 0.0.106
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/cloudflare-worker-agent-test",
"version": "0.0.106",
"version": "0.0.108",
"type": "module",
"private": true,
"scripts": {
@@ -1,5 +1,17 @@
# @llamaindex/llama-parse-browser-test
## 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
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/llama-parse-browser-test",
"private": true,
"version": "0.0.27",
"version": "0.0.29",
"type": "module",
"scripts": {
"dev": "vite",
+12
View File
@@ -1,5 +1,17 @@
# @llamaindex/next-agent-test
## 0.1.108
### Patch Changes
- llamaindex@0.8.12
## 0.1.107
### Patch Changes
- llamaindex@0.8.11
## 0.1.106
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-agent-test",
"version": "0.1.106",
"version": "0.1.108",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,17 @@
# test-edge-runtime
## 0.1.107
### Patch Changes
- llamaindex@0.8.12
## 0.1.106
### Patch Changes
- llamaindex@0.8.11
## 0.1.105
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/nextjs-edge-runtime-test",
"version": "0.1.105",
"version": "0.1.107",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,17 @@
# @llamaindex/next-node-runtime
## 0.0.89
### Patch Changes
- llamaindex@0.8.12
## 0.0.88
### Patch Changes
- llamaindex@0.8.11
## 0.0.87
### Patch Changes
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/next-node-runtime-test",
"version": "0.0.87",
"version": "0.0.89",
"private": true,
"scripts": {
"dev": "next dev",
@@ -1,5 +1,17 @@
# @llamaindex/waku-query-engine-test
## 0.0.108
### Patch Changes
- llamaindex@0.8.12
## 0.0.107
### Patch Changes
- llamaindex@0.8.11
## 0.0.106
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/waku-query-engine-test",
"version": "0.0.106",
"version": "0.0.108",
"type": "module",
"private": true,
"scripts": {
+12
View File
@@ -1,5 +1,17 @@
# @llamaindex/autotool
## 5.0.12
### Patch Changes
- llamaindex@0.8.12
## 5.0.11
### Patch Changes
- llamaindex@0.8.11
## 5.0.10
### Patch Changes
@@ -1,5 +1,19 @@
# @llamaindex/autotool-01-node-example
## 0.0.55
### Patch Changes
- llamaindex@0.8.12
- @llamaindex/autotool@5.0.12
## 0.0.54
### Patch Changes
- llamaindex@0.8.11
- @llamaindex/autotool@5.0.11
## 0.0.53
### Patch Changes
@@ -13,5 +13,5 @@
"scripts": {
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
},
"version": "0.0.53"
"version": "0.0.55"
}
@@ -1,5 +1,19 @@
# @llamaindex/autotool-02-next-example
## 0.1.99
### Patch Changes
- llamaindex@0.8.12
- @llamaindex/autotool@5.0.12
## 0.1.98
### Patch Changes
- llamaindex@0.8.11
- @llamaindex/autotool@5.0.11
## 0.1.97
### Patch Changes
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/autotool-02-next-example",
"private": true,
"version": "0.1.97",
"version": "0.1.99",
"scripts": {
"dev": "next dev",
"build": "next build",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/autotool",
"type": "module",
"version": "5.0.10",
"version": "5.0.12",
"description": "auto transpile your JS function to LLM Agent compatible",
"files": [
"dist",
+14
View File
@@ -1,5 +1,19 @@
# @llamaindex/cloud
## 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
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/cloud",
"version": "2.0.7",
"version": "2.0.9",
"type": "module",
"license": "MIT",
"scripts": {
+14
View File
@@ -1,5 +1,19 @@
# @llamaindex/community
## 0.0.67
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
## 0.0.66
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
## 0.0.65
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/community",
"description": "Community package for LlamaIndexTS",
"version": "0.0.65",
"version": "0.0.67",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
+12
View File
@@ -1,5 +1,17 @@
# @llamaindex/core
## 0.4.9
### Patch Changes
- 7ae6eaa: feat: allow pass `additionalChatOptions` to agent
## 0.4.8
### Patch Changes
- f865c98: feat: async get message on chat store
## 0.4.7
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/core",
"type": "module",
"version": "0.4.7",
"version": "0.4.9",
"description": "LlamaIndex Core Module",
"exports": {
"./agent": {
+71 -14
View File
@@ -106,11 +106,17 @@ export type AgentRunnerParams<
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> = {
llm: AI;
chatHistory: ChatMessage<AdditionalMessageOptions>[];
systemPrompt: MessageContent | null;
runner: AgentWorker<AI, Store, AdditionalMessageOptions>;
runner: AgentWorker<
AI,
Store,
AdditionalMessageOptions,
AdditionalChatOptions
>;
tools:
| BaseToolWithCall[]
| ((query: MessageContent) => Promise<BaseToolWithCall[]>);
@@ -125,6 +131,7 @@ export type AgentParamsBase<
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> =
| {
llm?: AI;
@@ -132,6 +139,7 @@ export type AgentParamsBase<
systemPrompt?: MessageContent;
verbose?: boolean;
tools: BaseToolWithCall[];
additionalChatOptions?: AdditionalChatOptions;
}
| {
llm?: AI;
@@ -139,6 +147,7 @@ export type AgentParamsBase<
systemPrompt?: MessageContent;
verbose?: boolean;
toolRetriever: ObjectRetriever<BaseToolWithCall>;
additionalChatOptions?: AdditionalChatOptions;
};
/**
@@ -153,21 +162,36 @@ export abstract class AgentWorker<
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> {
#taskSet = new Set<TaskStep<AI, Store, AdditionalMessageOptions>>();
abstract taskHandler: TaskHandler<AI, Store, AdditionalMessageOptions>;
#taskSet = new Set<
TaskStep<AI, Store, AdditionalMessageOptions, AdditionalChatOptions>
>();
abstract taskHandler: TaskHandler<
AI,
Store,
AdditionalMessageOptions,
AdditionalChatOptions
>;
public createTask(
query: MessageContent,
context: AgentTaskContext<AI, Store, AdditionalMessageOptions>,
): ReadableStream<TaskStepOutput<AI, Store, AdditionalMessageOptions>> {
context: AgentTaskContext<
AI,
Store,
AdditionalMessageOptions,
AdditionalChatOptions
>,
): ReadableStream<
TaskStepOutput<AI, Store, AdditionalMessageOptions, AdditionalChatOptions>
> {
context.store.messages.push({
role: "user",
content: query,
});
const taskOutputStream = createTaskOutputStream(this.taskHandler, context);
return new ReadableStream<
TaskStepOutput<AI, Store, AdditionalMessageOptions>
TaskStepOutput<AI, Store, AdditionalMessageOptions, AdditionalChatOptions>
>({
start: async (controller) => {
for await (const stepOutput of taskOutputStream) {
@@ -176,7 +200,8 @@ export abstract class AgentWorker<
let currentStep: TaskStep<
AI,
Store,
AdditionalMessageOptions
AdditionalMessageOptions,
AdditionalChatOptions
> | null = stepOutput.taskStep;
while (currentStep) {
this.#taskSet.delete(currentStep);
@@ -227,6 +252,7 @@ export abstract class AgentRunner<
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> extends BaseChatEngine {
readonly #llm: AI;
readonly #tools:
@@ -234,7 +260,12 @@ export abstract class AgentRunner<
| ((query: MessageContent) => Promise<BaseToolWithCall[]>);
readonly #systemPrompt: MessageContent | null = null;
#chatHistory: ChatMessage<AdditionalMessageOptions>[];
readonly #runner: AgentWorker<AI, Store, AdditionalMessageOptions>;
readonly #runner: AgentWorker<
AI,
Store,
AdditionalMessageOptions,
AdditionalChatOptions
>;
readonly #verbose: boolean;
// create extra store
@@ -245,7 +276,7 @@ export abstract class AgentRunner<
}
static defaultTaskHandler: TaskHandler<LLM> = async (step, enqueueOutput) => {
const { llm, getTools, stream } = step.context;
const { llm, getTools, stream, additionalChatOptions } = step.context;
const lastMessage = step.context.store.messages.at(-1)!.content;
const tools = await getTools(lastMessage);
if (!stream) {
@@ -253,8 +284,9 @@ export abstract class AgentRunner<
stream,
tools,
messages: [...step.context.store.messages],
additionalChatOptions,
});
await stepTools<LLM>({
await stepTools({
response,
tools,
step,
@@ -265,6 +297,7 @@ export abstract class AgentRunner<
stream,
tools,
messages: [...step.context.store.messages],
additionalChatOptions,
});
await stepToolsStreaming<LLM>({
response,
@@ -276,7 +309,12 @@ export abstract class AgentRunner<
};
protected constructor(
params: AgentRunnerParams<AI, Store, AdditionalMessageOptions>,
params: AgentRunnerParams<
AI,
Store,
AdditionalMessageOptions,
AdditionalChatOptions
>,
) {
super();
const { llm, chatHistory, systemPrompt, runner, tools, verbose } = params;
@@ -330,6 +368,7 @@ export abstract class AgentRunner<
stream: boolean = false,
verbose: boolean | undefined = undefined,
chatHistory?: ChatMessage<AdditionalMessageOptions>[],
additionalChatOptions?: AdditionalChatOptions,
) {
const initialMessages = [...(chatHistory ?? this.#chatHistory)];
if (this.#systemPrompt !== null) {
@@ -348,6 +387,7 @@ export abstract class AgentRunner<
stream,
toolCallCount: 0,
llm: this.#llm,
additionalChatOptions: additionalChatOptions ?? {},
getTools: (message) => this.getTools(message),
store: {
...this.createStore(),
@@ -365,13 +405,29 @@ export abstract class AgentRunner<
});
}
async chat(params: NonStreamingChatEngineParams): Promise<EngineResponse>;
async chat(
params: StreamingChatEngineParams,
params: NonStreamingChatEngineParams<
AdditionalMessageOptions,
AdditionalChatOptions
>,
): Promise<EngineResponse>;
async chat(
params: StreamingChatEngineParams<
AdditionalMessageOptions,
AdditionalChatOptions
>,
): Promise<ReadableStream<EngineResponse>>;
@wrapEventCaller
async chat(
params: NonStreamingChatEngineParams | StreamingChatEngineParams,
params:
| NonStreamingChatEngineParams<
AdditionalMessageOptions,
AdditionalChatOptions
>
| StreamingChatEngineParams<
AdditionalMessageOptions,
AdditionalChatOptions
>,
): Promise<EngineResponse | ReadableStream<EngineResponse>> {
let chatHistory: ChatMessage<AdditionalMessageOptions>[] = [];
@@ -388,6 +444,7 @@ export abstract class AgentRunner<
!!params.stream,
false,
chatHistory,
params.chatOptions,
);
for await (const stepOutput of task) {
// update chat history for each round
+47 -5
View File
@@ -4,24 +4,66 @@ import { ObjectRetriever } from "../objects";
import { AgentRunner, AgentWorker, type AgentParamsBase } from "./base.js";
import { validateAgentParams } from "./utils.js";
type LLMParamsBase = AgentParamsBase<LLM>;
type LLMParamsBase<
AI extends LLM,
AdditionalMessageOptions extends object = AI extends LLM<
object,
infer AdditionalMessageOptions
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> = AgentParamsBase<AI, AdditionalMessageOptions, AdditionalChatOptions>;
type LLMParamsWithTools = LLMParamsBase & {
type LLMParamsWithTools<
AI extends LLM,
AdditionalMessageOptions extends object = AI extends LLM<
object,
infer AdditionalMessageOptions
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> = LLMParamsBase<AI, AdditionalMessageOptions, AdditionalChatOptions> & {
tools: BaseToolWithCall[];
};
type LLMParamsWithToolRetriever = LLMParamsBase & {
type LLMParamsWithToolRetriever<
AI extends LLM,
AdditionalMessageOptions extends object = AI extends LLM<
object,
infer AdditionalMessageOptions
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> = LLMParamsBase<AI, AdditionalMessageOptions, AdditionalChatOptions> & {
toolRetriever: ObjectRetriever<BaseToolWithCall>;
};
export type LLMAgentParams = LLMParamsWithTools | LLMParamsWithToolRetriever;
export type LLMAgentParams<
AI extends LLM,
AdditionalMessageOptions extends object = AI extends LLM<
object,
infer AdditionalMessageOptions
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> =
| LLMParamsWithTools<AI, AdditionalMessageOptions, AdditionalChatOptions>
| LLMParamsWithToolRetriever<
AI,
AdditionalMessageOptions,
AdditionalChatOptions
>;
export class LLMAgentWorker extends AgentWorker<LLM> {
taskHandler = AgentRunner.defaultTaskHandler;
}
export class LLMAgent extends AgentRunner<LLM> {
constructor(params: LLMAgentParams) {
constructor(params: LLMAgentParams<LLM>) {
validateAgentParams(params);
const llm = params.llm ?? (Settings.llm ? (Settings.llm as LLM) : null);
if (!llm)
+33 -6
View File
@@ -19,6 +19,7 @@ export type AgentTaskContext<
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> = {
readonly stream: boolean;
readonly toolCallCount: number;
@@ -26,6 +27,7 @@ export type AgentTaskContext<
readonly getTools: (
input: MessageContent,
) => BaseToolWithCall[] | Promise<BaseToolWithCall[]>;
readonly additionalChatOptions: Partial<AdditionalChatOptions>;
shouldContinue: (
taskStep: Readonly<TaskStep<Model, Store, AdditionalMessageOptions>>,
) => boolean;
@@ -45,13 +47,26 @@ export type TaskStep<
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> = {
id: UUID;
context: AgentTaskContext<Model, Store, AdditionalMessageOptions>;
context: AgentTaskContext<
Model,
Store,
AdditionalMessageOptions,
AdditionalChatOptions
>;
// linked list
prevStep: TaskStep<Model, Store, AdditionalMessageOptions> | null;
nextSteps: Set<TaskStep<Model, Store, AdditionalMessageOptions>>;
prevStep: TaskStep<
Model,
Store,
AdditionalMessageOptions,
AdditionalChatOptions
> | null;
nextSteps: Set<
TaskStep<Model, Store, AdditionalMessageOptions, AdditionalChatOptions>
>;
};
export type TaskStepOutput<
@@ -63,8 +78,14 @@ export type TaskStepOutput<
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> = {
taskStep: TaskStep<Model, Store, AdditionalMessageOptions>;
taskStep: TaskStep<
Model,
Store,
AdditionalMessageOptions,
AdditionalChatOptions
>;
// output shows the response to the user
output:
| ChatResponse<AdditionalMessageOptions>
@@ -81,10 +102,16 @@ export type TaskHandler<
>
? AdditionalMessageOptions
: never,
AdditionalChatOptions extends object = object,
> = (
step: TaskStep<Model, Store, AdditionalMessageOptions>,
step: TaskStep<Model, Store, AdditionalMessageOptions, AdditionalChatOptions>,
enqueueOutput: (
taskOutput: TaskStepOutput<Model, Store, AdditionalMessageOptions>,
taskOutput: TaskStepOutput<
Model,
Store,
AdditionalMessageOptions,
AdditionalChatOptions
>,
) => void,
) => Promise<void>;
+4
View File
@@ -16,14 +16,18 @@ export interface BaseChatEngineParams<
export interface StreamingChatEngineParams<
AdditionalMessageOptions extends object = object,
AdditionalChatOptions extends object = object,
> extends BaseChatEngineParams<AdditionalMessageOptions> {
stream: true;
chatOptions?: AdditionalChatOptions;
}
export interface NonStreamingChatEngineParams<
AdditionalMessageOptions extends object = object,
AdditionalChatOptions extends object = object,
> extends BaseChatEngineParams<AdditionalMessageOptions> {
stream?: false;
chatOptions?: AdditionalChatOptions;
}
export abstract class BaseChatEngine {
+3 -1
View File
@@ -65,7 +65,9 @@ export abstract class BaseChatStoreMemory<
super();
}
getAllMessages(): ChatMessage<AdditionalMessageOptions>[] {
getAllMessages():
| ChatMessage<AdditionalMessageOptions>[]
| Promise<ChatMessage<AdditionalMessageOptions>[]> {
return this.chatStore.getMessages(this.chatStoreKey);
}
@@ -33,11 +33,11 @@ export class ChatMemoryBuffer<
}
}
getMessages(
async getMessages(
transientMessages?: ChatMessage<AdditionalMessageOptions>[] | undefined,
initialTokenCount: number = 0,
) {
const messages = this.getAllMessages();
const messages = await this.getAllMessages();
if (initialTokenCount > this.tokenLimit) {
throw new Error("Initial token count exceeds token limit");
@@ -7,7 +7,11 @@ export abstract class BaseChatStore<
key: string,
messages: ChatMessage<AdditionalMessageOptions>[],
): void;
abstract getMessages(key: string): ChatMessage<AdditionalMessageOptions>[];
abstract getMessages(
key: string,
):
| ChatMessage<AdditionalMessageOptions>[]
| Promise<ChatMessage<AdditionalMessageOptions>[]>;
abstract addMessage(
key: string,
message: ChatMessage<AdditionalMessageOptions>,
@@ -19,7 +19,7 @@ describe("ChatMemoryBuffer", () => {
expect(buffer.tokenLimit).toBe(500);
});
test("getMessages returns all messages when under token limit", () => {
test("getMessages returns all messages when under token limit", async () => {
const messages: ChatMessage[] = [
{ role: "user", content: "Hello" },
{ role: "assistant", content: "Hi there!" },
@@ -30,11 +30,11 @@ describe("ChatMemoryBuffer", () => {
chatHistory: messages,
});
const result = buffer.getMessages();
const result = await buffer.getMessages();
expect(result).toEqual(messages);
});
test("getMessages truncates messages when over token limit", () => {
test("getMessages truncates messages when over token limit", async () => {
const messages: ChatMessage[] = [
{ role: "user", content: "This is a long message" },
{ role: "assistant", content: "This is also a long reply" },
@@ -45,11 +45,11 @@ describe("ChatMemoryBuffer", () => {
chatHistory: messages,
});
const result = buffer.getMessages();
const result = await buffer.getMessages();
expect(result).toEqual([{ role: "user", content: "Short" }]);
});
test("getMessages handles input messages", () => {
test("getMessages handles input messages", async () => {
const storedMessages: ChatMessage[] = [
{ role: "user", content: "Hello" },
{ role: "assistant", content: "Hi there!" },
@@ -62,13 +62,13 @@ describe("ChatMemoryBuffer", () => {
const inputMessages: ChatMessage[] = [
{ role: "user", content: "New message" },
];
const result = buffer.getMessages(inputMessages);
const result = await buffer.getMessages(inputMessages);
expect(result).toEqual([...inputMessages, ...storedMessages]);
});
test("getMessages throws error when initial token count exceeds limit", () => {
const buffer = new ChatMemoryBuffer({ tokenLimit: 10 });
expect(() => buffer.getMessages(undefined, 20)).toThrow(
expect(async () => buffer.getMessages(undefined, 20)).rejects.toThrow(
"Initial token count exceeds token limit",
);
});
+12
View File
@@ -1,5 +1,17 @@
# @llamaindex/experimental
## 0.0.124
### Patch Changes
- llamaindex@0.8.12
## 0.0.123
### Patch Changes
- llamaindex@0.8.11
## 0.0.122
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/experimental",
"description": "Experimental package for LlamaIndexTS",
"version": "0.0.122",
"version": "0.0.124",
"type": "module",
"types": "dist/type/index.d.ts",
"main": "dist/cjs/index.js",
+40
View File
@@ -1,5 +1,45 @@
# llamaindex
## 0.8.12
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
- @llamaindex/openai@0.1.34
- @llamaindex/cloud@2.0.9
- @llamaindex/node-parser@0.0.10
- @llamaindex/anthropic@0.0.18
- @llamaindex/clip@0.0.18
- @llamaindex/deepinfra@0.0.18
- @llamaindex/huggingface@0.0.18
- @llamaindex/ollama@0.0.25
- @llamaindex/portkey-ai@0.0.18
- @llamaindex/replicate@0.0.18
- @llamaindex/readers@1.0.10
- @llamaindex/groq@0.0.33
- @llamaindex/vllm@0.0.4
## 0.8.11
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
- @llamaindex/cloud@2.0.8
- @llamaindex/node-parser@0.0.9
- @llamaindex/anthropic@0.0.17
- @llamaindex/clip@0.0.17
- @llamaindex/deepinfra@0.0.17
- @llamaindex/huggingface@0.0.17
- @llamaindex/ollama@0.0.24
- @llamaindex/openai@0.1.33
- @llamaindex/portkey-ai@0.0.17
- @llamaindex/replicate@0.0.17
- @llamaindex/readers@1.0.9
- @llamaindex/groq@0.0.32
- @llamaindex/vllm@0.0.3
## 0.8.10
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "llamaindex",
"version": "0.8.10",
"version": "0.8.12",
"license": "MIT",
"type": "module",
"keywords": [
+14
View File
@@ -1,5 +1,19 @@
# @llamaindex/node-parser
## 0.0.10
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
## 0.0.9
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
## 0.0.8
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@llamaindex/node-parser",
"version": "0.0.8",
"version": "0.0.10",
"description": "Node parser for LlamaIndex",
"type": "module",
"exports": {
+14
View File
@@ -1,5 +1,19 @@
# @llamaindex/anthropic
## 0.0.18
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
## 0.0.17
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
## 0.0.16
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/anthropic",
"description": "Anthropic Adapter for LlamaIndex",
"version": "0.0.16",
"version": "0.0.18",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+1 -1
View File
@@ -11,7 +11,7 @@ import { Settings } from "@llamaindex/core/global";
import type { EngineResponse } from "@llamaindex/core/schema";
import { Anthropic } from "./llm.js";
export type AnthropicAgentParams = LLMAgentParams;
export type AnthropicAgentParams = LLMAgentParams<Anthropic>;
export class AnthropicAgentWorker extends LLMAgentWorker {}
+16
View File
@@ -1,5 +1,21 @@
# @llamaindex/clip
## 0.0.18
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
- @llamaindex/openai@0.1.34
## 0.0.17
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
- @llamaindex/openai@0.1.33
## 0.0.16
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/clip",
"description": "Clip Embedding Adapter for LlamaIndex",
"version": "0.0.16",
"version": "0.0.18",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
+16
View File
@@ -1,5 +1,21 @@
# @llamaindex/deepinfra
## 0.0.18
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
- @llamaindex/openai@0.1.34
## 0.0.17
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
- @llamaindex/openai@0.1.33
## 0.0.16
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/deepinfra",
"description": "Deepinfra Adapter for LlamaIndex",
"version": "0.0.16",
"version": "0.0.18",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+13
View File
@@ -1,5 +1,18 @@
# @llamaindex/groq
## 0.0.33
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/openai@0.1.34
## 0.0.32
### Patch Changes
- @llamaindex/openai@0.1.33
## 0.0.31
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/groq",
"description": "Groq Adapter for LlamaIndex",
"version": "0.0.31",
"version": "0.0.33",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -1,5 +1,21 @@
# @llamaindex/huggingface
## 0.0.18
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
- @llamaindex/openai@0.1.34
## 0.0.17
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
- @llamaindex/openai@0.1.33
## 0.0.16
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/huggingface",
"description": "Huggingface Adapter for LlamaIndex",
"version": "0.0.16",
"version": "0.0.18",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
+14
View File
@@ -1,5 +1,19 @@
# @llamaindex/ollama
## 0.0.25
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
## 0.0.24
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
## 0.0.23
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/ollama",
"description": "Ollama Adapter for LlamaIndex",
"version": "0.0.23",
"version": "0.0.25",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+1 -1
View File
@@ -8,7 +8,7 @@ import { Ollama } from "./llm";
// This is likely not necessary anymore but leaving it here just incase it's in use elsewhere
export type OllamaAgentParams = LLMAgentParams & {
export type OllamaAgentParams = LLMAgentParams<Ollama> & {
model?: string;
};
+15
View File
@@ -1,5 +1,20 @@
# @llamaindex/openai
## 0.1.34
### Patch Changes
- 7ae6eaa: feat: allow pass `additionalChatOptions` to agent
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
## 0.1.33
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
## 0.1.32
### Patch Changes
+2 -3
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/openai",
"description": "OpenAI Adapter for LlamaIndex",
"version": "0.1.32",
"version": "0.1.34",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -35,7 +35,6 @@
"dependencies": {
"@llamaindex/core": "workspace:*",
"@llamaindex/env": "workspace:*",
"openai": "^4.68.1",
"remeda": "^2.12.0"
"openai": "^4.68.1"
}
}
+8 -3
View File
@@ -4,11 +4,16 @@ import {
type LLMAgentParams,
} from "@llamaindex/core/agent";
import { Settings } from "@llamaindex/core/global";
import { OpenAI } from "./llm";
import type { ToolCallLLMMessageOptions } from "@llamaindex/core/llms";
import { OpenAI, type OpenAIAdditionalChatOptions } from "./llm";
// This is likely not necessary anymore but leaving it here just incase it's in use elsewhere
// This is likely not necessary anymore but leaving it here just in case it's in use elsewhere
export type OpenAIAgentParams = LLMAgentParams;
export type OpenAIAgentParams = LLMAgentParams<
OpenAI,
ToolCallLLMMessageOptions,
OpenAIAdditionalChatOptions
>;
export class OpenAIAgentWorker extends LLMAgentWorker {}
@@ -1,5 +1,19 @@
# @llamaindex/portkey-ai
## 0.0.18
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
## 0.0.17
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
## 0.0.16
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/portkey-ai",
"description": "Portkey Adapter for LlamaIndex",
"version": "0.0.16",
"version": "0.0.18",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+14
View File
@@ -1,5 +1,19 @@
# @llamaindex/replicate
## 0.0.18
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
## 0.0.17
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
## 0.0.16
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/replicate",
"description": "Replicate Adapter for LlamaIndex",
"version": "0.0.16",
"version": "0.0.18",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+13
View File
@@ -1,5 +1,18 @@
# @llamaindex/vllm
## 0.0.4
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/openai@0.1.34
## 0.0.3
### Patch Changes
- @llamaindex/openai@0.1.33
## 0.0.2
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/vllm",
"description": "vLLM Adapter for LlamaIndex",
"version": "0.0.2",
"version": "0.0.4",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+14
View File
@@ -1,5 +1,19 @@
# @llamaindex/readers
## 1.0.10
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
## 1.0.9
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
## 1.0.8
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/readers",
"description": "LlamaIndex Readers",
"version": "1.0.8",
"version": "1.0.10",
"type": "module",
"exports": {
"./node/hook": "./node/dist/hook.js",
+8 -4
View File
@@ -397,10 +397,11 @@ export class WorkflowContext<Start = string, Stop = string, Data = unknown>
);
}
const outputs = outputsMap.get(step) ?? [];
const outputEvents = flattenEvents(outputs, [
nextEvent,
]);
if (outputEvents.length !== outputs.length) {
if (
!outputs.some(
(output) => nextEvent.constructor === output,
)
) {
if (this.#strict) {
const error = Error(
`Step ${step.name} returned an unexpected output event ${nextEvent}`,
@@ -452,6 +453,9 @@ export class WorkflowContext<Start = string, Stop = string, Data = unknown>
}),
)
.catch((err) => {
// when the step raise an error, should go back to the previous step
this.#sendEvent(event);
isPendingEvents.add(event);
controller.error(err);
});
}
+1118 -129
View File
File diff suppressed because it is too large Load Diff
+24
View File
@@ -1,5 +1,29 @@
# @llamaindex/unit-test
## 0.0.21
### Patch Changes
- Updated dependencies [7ae6eaa]
- @llamaindex/core@0.4.9
- @llamaindex/openai@0.1.34
- @llamaindex/cloud@2.0.9
- llamaindex@0.8.12
- @llamaindex/node-parser@0.0.10
- @llamaindex/readers@1.0.10
## 0.0.20
### Patch Changes
- Updated dependencies [f865c98]
- @llamaindex/core@0.4.8
- @llamaindex/cloud@2.0.8
- llamaindex@0.8.11
- @llamaindex/node-parser@0.0.9
- @llamaindex/openai@0.1.33
- @llamaindex/readers@1.0.9
## 0.0.19
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/unit-test",
"private": true,
"version": "0.0.19",
"version": "0.0.21",
"type": "module",
"scripts": {
"test": "vitest run"
+95
View File
@@ -794,6 +794,21 @@ describe("workflow event loop", () => {
}
`);
});
test("workflow multiple output", async () => {
const myFlow = new Workflow<unknown, string, string>({ verbose: true });
myFlow.addStep(
{
inputs: [StartEvent<string>],
outputs: [StopEvent<string>, StopEvent<string>],
},
async (_context, ev) => {
return new StopEvent(`Hello ${ev.data}!`);
},
);
const result = await myFlow.run("world").strict();
expect(result.data).toBe("Hello world!");
});
});
describe("snapshot", async () => {
@@ -869,3 +884,83 @@ describe("snapshot", async () => {
expect(fn).toHaveBeenCalledTimes(1);
});
});
describe("error", () => {
test("error in handler", async () => {
const myFlow = new Workflow<boolean, string, string>({ verbose: true });
myFlow.addStep(
{
inputs: [StartEvent<string>],
outputs: [StopEvent<string>],
},
async ({ data }) => {
if (!data) {
throw new Error("Something went wrong");
} else {
return new StopEvent(`Hello ${data}!`);
}
},
);
await expect(myFlow.run("world")).rejects.toThrow("Something went wrong");
{
const context = myFlow.run("world");
try {
for await (const _ of context) {
// do nothing
}
} catch (error) {
expect(error).toBeInstanceOf(Error);
expect((error as Error).message).toBe("Something went wrong");
const snapshot = context.snapshot();
const newContext = myFlow.recover(snapshot).with(true);
expect((await newContext).data).toBe("Hello true!");
}
}
});
test("recover in the middle of workflow", async () => {
const myFlow = new Workflow<string | undefined, string, string>({
verbose: true,
});
class AEvent extends WorkflowEvent<string> {}
myFlow.addStep(
{
inputs: [StartEvent<string>],
outputs: [AEvent],
},
async ({ data }) => {
if (data !== undefined) {
throw new Error("Something went wrong");
}
return new AEvent("world");
},
);
myFlow.addStep(
{
inputs: [AEvent],
outputs: [StopEvent],
},
async ({ data }, ev) => {
if (data === undefined) {
throw new Error("Something went wrong");
}
return new StopEvent(`Hello, ${data}!`);
},
);
// no context, so will throw error
const context = myFlow.run("world");
try {
for await (const _ of context) {
// do nothing
}
} catch (error) {
expect(error).toBeInstanceOf(Error);
expect((error as Error).message).toBe("Something went wrong");
const snapshot = context.snapshot();
const newContext = myFlow.recover(snapshot).with("Recovered Data");
expect((await newContext).data).toBe("Hello, Recovered Data!");
}
});
});