mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-11 00:04:07 -04:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6dde924d0a |
@@ -1,21 +1,5 @@
|
||||
# @llamaindex/doc
|
||||
|
||||
## 0.1.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [aea550a]
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/openai@0.1.60
|
||||
- llamaindex@0.9.10
|
||||
- @llamaindex/workflow@0.0.16
|
||||
- @llamaindex/core@0.5.8
|
||||
- @llamaindex/cloud@3.0.9
|
||||
- @llamaindex/node-parser@1.0.8
|
||||
- @llamaindex/readers@2.0.8
|
||||
|
||||
## 0.1.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/doc",
|
||||
"version": "0.1.10",
|
||||
"version": "0.1.9",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"postinstall": "fumadocs-mdx",
|
||||
|
||||
@@ -4,8 +4,4 @@ import { updateLlamaCloud } from "./update-llamacloud.mjs";
|
||||
|
||||
env.loadEnvConfig(process.cwd());
|
||||
|
||||
if (process.env.VERCEL_ENV === "production") {
|
||||
updateLlamaCloud().catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
await updateLlamaCloud();
|
||||
|
||||
@@ -125,20 +125,19 @@ const response = await agent.chat({
|
||||
description="Truly powerful retrieval-augmented generation applications use agentic techniques, and LlamaIndex.TS makes it easy to build them."
|
||||
>
|
||||
<CodeBlock
|
||||
code={`import { agent } from "llamaindex";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
code={`import { FunctionTool } from "llamaindex";
|
||||
import { OpenAIAgent } from "@llamaindex/openai";
|
||||
|
||||
// using a previously created LlamaIndex index to query information from
|
||||
const queryTool = index.queryTool();
|
||||
const interpreterTool = FunctionTool.from(...);
|
||||
const systemPrompt = \`...\`;
|
||||
|
||||
const agent = agent({
|
||||
llm: new OpenAI({
|
||||
model: "gpt-4o",
|
||||
}),
|
||||
tools: [queryTool],
|
||||
const agent = new OpenAIAgent({
|
||||
llm,
|
||||
tools: [interpreterTool],
|
||||
systemPrompt,
|
||||
});
|
||||
|
||||
await agent.run('...');`}
|
||||
await agent.chat('...');`}
|
||||
lang="ts"
|
||||
/>
|
||||
</Feature>
|
||||
|
||||
@@ -3,10 +3,28 @@ title: Agent Workflow
|
||||
---
|
||||
|
||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
||||
import CodeSource from "!raw-loader!../../../../../../../examples/agentworkflow/blog-writer.ts";
|
||||
import CodeSource from "!raw-loader!../../../../../../../examples/agentworkflow/blog_writer.ts";
|
||||
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
||||
|
||||
Agent Workflows are a powerful system that enables you to create and orchestrate one or multiple agents with tools to perform specific tasks. It's built on top of the base `Workflow` system and provides a streamlined interface for agent interactions.
|
||||
`AgentWorkflow` is a powerful system that enables you to create and orchestrate one or multiple agents with tools to perform specific tasks. It's built on top of the base `Workflow` system and provides a streamlined interface for agent interactions.
|
||||
|
||||
## Installation
|
||||
|
||||
You'll need to install the `@llamaindex/workflow` package:
|
||||
|
||||
<Tabs groupId="install" items={["npm", "yarn", "pnpm"]} persist>
|
||||
```shell tab="npm"
|
||||
npm install @llamaindex/workflow
|
||||
```
|
||||
|
||||
```shell tab="yarn"
|
||||
yarn add @llamaindex/workflow
|
||||
```
|
||||
|
||||
```shell tab="pnpm"
|
||||
pnpm add @llamaindex/workflow
|
||||
```
|
||||
</Tabs>
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -15,7 +33,7 @@ Agent Workflows are a powerful system that enables you to create and orchestrate
|
||||
The simplest use case is creating a single agent with specific tools. Here's an example of creating an assistant that tells jokes:
|
||||
|
||||
```typescript
|
||||
import { agent, FunctionTool } from "llamaindex";
|
||||
import { AgentWorkflow, FunctionTool } from "llamaindex";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
|
||||
// Define a joke-telling tool
|
||||
@@ -27,8 +45,8 @@ const jokeTool = FunctionTool.from(
|
||||
}
|
||||
);
|
||||
|
||||
// Create an single agent workflow with the tool
|
||||
const workflow = agent({
|
||||
// Create an agent workflow with the tool
|
||||
const workflow = AgentWorkflow.fromTools({
|
||||
tools: [jokeTool],
|
||||
llm: new OpenAI({
|
||||
model: "gpt-4o-mini",
|
||||
@@ -42,7 +60,7 @@ console.log(result); // Baby Llama is called cria
|
||||
|
||||
### Event Streaming
|
||||
|
||||
Agent Workflows provide a unified interface for event streaming, making it easy to track and respond to different events during execution:
|
||||
`AgentWorkflow` provides a unified interface for event streaming, making it easy to track and respond to different events during execution:
|
||||
|
||||
```typescript
|
||||
import { AgentToolCall, AgentStream } from "llamaindex";
|
||||
@@ -63,7 +81,7 @@ for await (const event of context) {
|
||||
|
||||
### Multi-Agent Workflow
|
||||
|
||||
An Agent Workflow can orchestrate multiple agents, enabling complex interactions and task handoffs. Each agent in a multi-agent workflow requires:
|
||||
`AgentWorkflow` can orchestrate multiple agents, enabling complex interactions and task handoffs. Each agent in a multi-agent workflow requires:
|
||||
|
||||
- `name`: Unique identifier for the agent
|
||||
- `description`: Purpose description used for task routing
|
||||
@@ -73,12 +91,12 @@ An Agent Workflow can orchestrate multiple agents, enabling complex interactions
|
||||
Here's an example of a multi-agent system that combines joke-telling and weather information:
|
||||
|
||||
```typescript
|
||||
import { multiAgent, agent, FunctionTool } from "llamaindex";
|
||||
import { AgentWorkflow, FunctionAgent, FunctionTool } from "llamaindex";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { z } from "zod";
|
||||
|
||||
// Create a weather agent
|
||||
const weatherAgent = agent({
|
||||
const weatherAgent = new FunctionAgent({
|
||||
name: "WeatherAgent",
|
||||
description: "Provides weather information for any city",
|
||||
tools: [
|
||||
@@ -97,7 +115,7 @@ const weatherAgent = agent({
|
||||
});
|
||||
|
||||
// Create a joke-telling agent
|
||||
const jokeAgent = agent({
|
||||
const jokeAgent = new FunctionAgent({
|
||||
name: "JokeAgent",
|
||||
description: "Tells jokes and funny stories",
|
||||
tools: [jokeTool], // Using the joke tool defined earlier
|
||||
@@ -106,7 +124,7 @@ const jokeAgent = agent({
|
||||
});
|
||||
|
||||
// Create the multi-agent workflow
|
||||
const workflow = multiAgent({
|
||||
const workflow = new AgentWorkflow({
|
||||
agents: [jokeAgent, weatherAgent],
|
||||
rootAgent: jokeAgent, // Start with the joke agent
|
||||
});
|
||||
|
||||
@@ -119,7 +119,7 @@ Lastly, we run the workflow. The `.run()` method is async, so we use await here
|
||||
Optionally, you can choose to use a shared context between steps by specifying a context type when creating the workflow. Here's an example where multiple steps access a shared state:
|
||||
|
||||
```typescript
|
||||
import { HandlerContext } from "llamaindex";
|
||||
import { HandlerContext } from "@llamaindex/workflow";
|
||||
|
||||
type MyContextData = {
|
||||
query: string;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
{
|
||||
"$schema": "https://turbo.build/schema.json",
|
||||
"extends": ["//"],
|
||||
"tasks": {
|
||||
"build": {
|
||||
@@ -9,11 +8,6 @@
|
||||
"next-env.d.ts",
|
||||
"src/content/docs/cloud/api/**",
|
||||
"src/content/docs/api/**"
|
||||
],
|
||||
"env": [
|
||||
"LLAMA_CLOUD_API_KEY",
|
||||
"LLAMA_CLOUD_PIPELINE_ID",
|
||||
"OPENAI_API_KEY"
|
||||
]
|
||||
},
|
||||
"dev": {
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
# @llamaindex/cloudflare-worker-agent-test
|
||||
|
||||
## 0.0.144
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- Updated dependencies [40ee761]
|
||||
- llamaindex@0.9.10
|
||||
|
||||
## 0.0.143
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/cloudflare-worker-agent-test",
|
||||
"version": "0.0.144",
|
||||
"version": "0.0.143",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
# @llamaindex/llama-parse-browser-test
|
||||
|
||||
## 0.0.54
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @llamaindex/cloud@3.0.9
|
||||
|
||||
## 0.0.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/llama-parse-browser-test",
|
||||
"private": true,
|
||||
"version": "0.0.54",
|
||||
"version": "0.0.53",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
# @llamaindex/next-agent-test
|
||||
|
||||
## 0.1.144
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- Updated dependencies [40ee761]
|
||||
- llamaindex@0.9.10
|
||||
|
||||
## 0.1.143
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/next-agent-test",
|
||||
"version": "0.1.144",
|
||||
"version": "0.1.143",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
# test-edge-runtime
|
||||
|
||||
## 0.1.143
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- Updated dependencies [40ee761]
|
||||
- llamaindex@0.9.10
|
||||
|
||||
## 0.1.142
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/nextjs-edge-runtime-test",
|
||||
"version": "0.1.143",
|
||||
"version": "0.1.142",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
# @llamaindex/next-node-runtime
|
||||
|
||||
## 0.1.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [aea550a]
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/huggingface@0.0.44
|
||||
- llamaindex@0.9.10
|
||||
- @llamaindex/readers@2.0.8
|
||||
|
||||
## 0.1.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/next-node-runtime-test",
|
||||
"version": "0.1.10",
|
||||
"version": "0.1.9",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
"use server";
|
||||
import { HuggingFaceEmbedding } from "@llamaindex/huggingface";
|
||||
import { SimpleDirectoryReader } from "@llamaindex/readers/directory";
|
||||
import { OpenAI, OpenAIAgent, Settings, VectorStoreIndex } from "llamaindex";
|
||||
import {
|
||||
OpenAI,
|
||||
OpenAIAgent,
|
||||
QueryEngineTool,
|
||||
Settings,
|
||||
VectorStoreIndex,
|
||||
} from "llamaindex";
|
||||
|
||||
Settings.llm = new OpenAI({
|
||||
apiKey: process.env.NEXT_PUBLIC_OPENAI_KEY ?? "FAKE_KEY_TO_PASS_TESTS",
|
||||
@@ -25,20 +31,23 @@ export async function getOpenAIModelRequest(query: string) {
|
||||
const reader = new SimpleDirectoryReader();
|
||||
const documents = await reader.loadData(currentDir);
|
||||
const index = await VectorStoreIndex.fromDocuments(documents);
|
||||
const retriever = index.asRetriever({
|
||||
similarityTopK: 10,
|
||||
});
|
||||
const queryEngine = index.asQueryEngine({
|
||||
retriever,
|
||||
});
|
||||
|
||||
// define the query engine as a tool
|
||||
const tools = [
|
||||
index.queryTool({
|
||||
options: {
|
||||
similarityTopK: 10,
|
||||
},
|
||||
new QueryEngineTool({
|
||||
queryEngine: queryEngine,
|
||||
metadata: {
|
||||
name: "deployment_details_per_env",
|
||||
description: `This tool can answer detailed questions about deployments happened in various environments.`,
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
// create the agent
|
||||
const agent = new OpenAIAgent({ tools });
|
||||
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
# vite-import-llamaindex
|
||||
|
||||
## 0.0.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- Updated dependencies [40ee761]
|
||||
- llamaindex@0.9.10
|
||||
|
||||
## 0.0.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "vite-import-llamaindex",
|
||||
"private": true,
|
||||
"version": "0.0.10",
|
||||
"version": "0.0.9",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
# @llamaindex/waku-query-engine-test
|
||||
|
||||
## 0.0.144
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- Updated dependencies [40ee761]
|
||||
- llamaindex@0.9.10
|
||||
|
||||
## 0.0.143
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/waku-query-engine-test",
|
||||
"version": "0.0.144",
|
||||
"version": "0.0.143",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,54 +1,5 @@
|
||||
# examples
|
||||
|
||||
## 0.2.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- aea550a: Add factory convenience factory for each LLM provider, e.g. you can use openai instead of 'new OpenAI'
|
||||
- Updated dependencies [c14a21b]
|
||||
- Updated dependencies [33f9856]
|
||||
- Updated dependencies [aea550a]
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/azure@0.1.8
|
||||
- @llamaindex/google@0.1.1
|
||||
- @llamaindex/huggingface@0.0.44
|
||||
- @llamaindex/portkey-ai@0.0.41
|
||||
- @llamaindex/anthropic@0.2.6
|
||||
- @llamaindex/deepinfra@0.0.44
|
||||
- @llamaindex/fireworks@0.0.4
|
||||
- @llamaindex/replicate@0.0.41
|
||||
- @llamaindex/deepseek@0.0.4
|
||||
- @llamaindex/together@0.0.4
|
||||
- @llamaindex/mistral@0.0.13
|
||||
- @llamaindex/ollama@0.0.48
|
||||
- @llamaindex/openai@0.1.60
|
||||
- @llamaindex/vercel@0.0.19
|
||||
- @llamaindex/groq@0.0.59
|
||||
- @llamaindex/vllm@0.0.30
|
||||
- llamaindex@0.9.10
|
||||
- @llamaindex/workflow@0.0.16
|
||||
- @llamaindex/core@0.5.8
|
||||
- @llamaindex/clip@0.0.44
|
||||
- @llamaindex/jinaai@0.0.4
|
||||
- @llamaindex/milvus@0.1.8
|
||||
- @llamaindex/qdrant@0.1.8
|
||||
- @llamaindex/cloud@3.0.9
|
||||
- @llamaindex/node-parser@1.0.8
|
||||
- @llamaindex/cohere@0.0.13
|
||||
- @llamaindex/mixedbread@0.0.13
|
||||
- @llamaindex/astra@0.0.13
|
||||
- @llamaindex/chroma@0.0.13
|
||||
- @llamaindex/firestore@1.0.6
|
||||
- @llamaindex/mongodb@0.0.13
|
||||
- @llamaindex/pinecone@0.0.13
|
||||
- @llamaindex/postgres@0.0.41
|
||||
- @llamaindex/upstash@0.0.13
|
||||
- @llamaindex/weaviate@0.0.13
|
||||
- @llamaindex/voyage-ai@1.0.5
|
||||
- @llamaindex/readers@2.0.8
|
||||
|
||||
## 0.2.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { FunctionTool, agent } from "llamaindex";
|
||||
import { AgentWorkflow, FunctionTool } from "llamaindex";
|
||||
import { z } from "zod";
|
||||
|
||||
const csvData =
|
||||
@@ -33,7 +33,7 @@ const userQuestion = "which are the best comedies after 2010?";
|
||||
const systemPrompt =
|
||||
"You are a Python interpreter.\n - You are given tasks to complete and you run python code to solve them.\n - The python code runs in a Jupyter notebook. Every time you call $(interpreter) tool, the python code is executed in a separate cell. It's okay to make multiple calls to $(interpreter).\n - Display visualizations using matplotlib or any other visualization library directly in the notebook. Shouldn't save the visualizations to a file, just return the base64 encoded data.\n - You can install any pip package (if it exists) if you need to but the usual packages for data analysis are already preinstalled.\n - You can run any python code you want in a secure environment.";
|
||||
|
||||
const workflow = agent({
|
||||
const workflow = AgentWorkflow.fromTools({
|
||||
tools: [interpreterTool],
|
||||
llm,
|
||||
verbose: false,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { FunctionTool, agent } from "llamaindex";
|
||||
import { AgentWorkflow, FunctionTool } from "llamaindex";
|
||||
import { z } from "zod";
|
||||
|
||||
const sumNumbers = FunctionTool.from(
|
||||
@@ -27,7 +27,7 @@ const divideNumbers = FunctionTool.from(
|
||||
);
|
||||
|
||||
async function main() {
|
||||
const workflow = agent({
|
||||
const workflow = AgentWorkflow.fromTools({
|
||||
tools: [sumNumbers, divideNumbers],
|
||||
llm: new OpenAI({ model: "gpt-4o-mini" }),
|
||||
verbose: false,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { AgentStream, agent } from "llamaindex";
|
||||
import { AgentStream, AgentWorkflow } from "llamaindex";
|
||||
import { WikipediaTool } from "../wiki";
|
||||
|
||||
async function main() {
|
||||
const llm = new OpenAI({ model: "gpt-4-turbo" });
|
||||
const wikiTool = new WikipediaTool();
|
||||
|
||||
const workflow = agent({
|
||||
const workflow = AgentWorkflow.fromTools({
|
||||
tools: [wikiTool],
|
||||
llm,
|
||||
verbose: false,
|
||||
|
||||
@@ -1,38 +1,40 @@
|
||||
import { openai } from "@llamaindex/openai";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import fs from "fs";
|
||||
import {
|
||||
agent,
|
||||
AgentToolCall,
|
||||
AgentToolCallResult,
|
||||
multiAgent,
|
||||
tool,
|
||||
AgentWorkflow,
|
||||
FunctionAgent,
|
||||
FunctionTool,
|
||||
} from "llamaindex";
|
||||
import os from "os";
|
||||
import { z } from "zod";
|
||||
|
||||
import { WikipediaTool } from "../wiki";
|
||||
const llm = openai({
|
||||
const llm = new OpenAI({
|
||||
model: "gpt-4o-mini",
|
||||
});
|
||||
|
||||
const saveFileTool = tool({
|
||||
name: "saveFile",
|
||||
description:
|
||||
"Save the written content into a file that can be downloaded by the user",
|
||||
parameters: z.object({
|
||||
content: z.string({
|
||||
description: "The content to save into a file",
|
||||
}),
|
||||
}),
|
||||
execute: ({ content }: { content: string }) => {
|
||||
const saveFileTool = FunctionTool.from(
|
||||
({ content }: { content: string }) => {
|
||||
const filePath = os.tmpdir() + "/report.md";
|
||||
fs.writeFileSync(filePath, content);
|
||||
return `File saved successfully at ${filePath}`;
|
||||
},
|
||||
});
|
||||
{
|
||||
name: "saveFile",
|
||||
description:
|
||||
"Save the written content into a file that can be downloaded by the user",
|
||||
parameters: z.object({
|
||||
content: z.string({
|
||||
description: "The content to save into a file",
|
||||
}),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
async function main() {
|
||||
const reportAgent = agent({
|
||||
const reportAgent = new FunctionAgent({
|
||||
name: "ReportAgent",
|
||||
description:
|
||||
"Responsible for crafting well-written blog posts based on research findings",
|
||||
@@ -41,7 +43,7 @@ async function main() {
|
||||
llm,
|
||||
});
|
||||
|
||||
const researchAgent = agent({
|
||||
const researchAgent = new FunctionAgent({
|
||||
name: "ResearchAgent",
|
||||
description:
|
||||
"Responsible for gathering relevant information from the internet",
|
||||
@@ -51,7 +53,7 @@ async function main() {
|
||||
llm,
|
||||
});
|
||||
|
||||
const workflow = multiAgent({
|
||||
const workflow = new AgentWorkflow({
|
||||
agents: [researchAgent, reportAgent],
|
||||
rootAgent: researchAgent,
|
||||
});
|
||||
+33
-29
@@ -3,55 +3,59 @@
|
||||
* 1. FetchWeatherAgent - Fetches the weather in a city
|
||||
* 2. TemperatureConverterAgent - Converts the temperature from Fahrenheit to Celsius
|
||||
*/
|
||||
import { openai } from "@llamaindex/openai";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { StopEvent } from "@llamaindex/workflow";
|
||||
import {
|
||||
agent,
|
||||
AgentInput,
|
||||
AgentOutput,
|
||||
AgentStream,
|
||||
AgentToolCall,
|
||||
AgentToolCallResult,
|
||||
multiAgent,
|
||||
StopEvent,
|
||||
tool,
|
||||
AgentWorkflow,
|
||||
FunctionAgent,
|
||||
FunctionTool,
|
||||
} from "llamaindex";
|
||||
import { z } from "zod";
|
||||
|
||||
const llm = openai({
|
||||
const llm = new OpenAI({
|
||||
model: "gpt-4o-mini",
|
||||
});
|
||||
|
||||
// Define tools for the agents
|
||||
const temperatureConverterTool = tool({
|
||||
description: "Convert a temperature from Fahrenheit to Celsius",
|
||||
name: "fahrenheitToCelsius",
|
||||
parameters: z.object({
|
||||
temperature: z.number({
|
||||
description: "The temperature in Fahrenheit",
|
||||
}),
|
||||
}),
|
||||
execute: ({ temperature }) => {
|
||||
const temperatureConverterTool = FunctionTool.from(
|
||||
({ temperature }: { temperature: number }) => {
|
||||
return ((temperature - 32) * 5) / 9;
|
||||
},
|
||||
});
|
||||
|
||||
const temperatureFetcherTool = tool({
|
||||
description: "Fetch the temperature (in Fahrenheit) for a city",
|
||||
name: "fetchTemperature",
|
||||
parameters: z.object({
|
||||
city: z.string({
|
||||
description: "The city to fetch the temperature for",
|
||||
{
|
||||
description: "Convert a temperature from Fahrenheit to Celsius",
|
||||
name: "fahrenheitToCelsius",
|
||||
parameters: z.object({
|
||||
temperature: z.number({
|
||||
description: "The temperature in Fahrenheit",
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
execute: ({ city }) => {
|
||||
},
|
||||
);
|
||||
|
||||
const temperatureFetcherTool = FunctionTool.from(
|
||||
({ city }: { city: string }) => {
|
||||
const temperature = Math.floor(Math.random() * 58) + 32;
|
||||
return `The current temperature in ${city} is ${temperature}°F`;
|
||||
},
|
||||
});
|
||||
{
|
||||
description: "Fetch the temperature (in Fahrenheit) for a city",
|
||||
name: "fetchTemperature",
|
||||
parameters: z.object({
|
||||
city: z.string({
|
||||
description: "The city to fetch the temperature for",
|
||||
}),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
// Create agents
|
||||
async function multiWeatherAgent() {
|
||||
const converterAgent = agent({
|
||||
const converterAgent = new FunctionAgent({
|
||||
name: "TemperatureConverterAgent",
|
||||
description:
|
||||
"An agent that can convert temperatures from Fahrenheit to Celsius.",
|
||||
@@ -59,7 +63,7 @@ async function multiWeatherAgent() {
|
||||
llm,
|
||||
});
|
||||
|
||||
const weatherAgent = agent({
|
||||
const weatherAgent = new FunctionAgent({
|
||||
name: "FetchWeatherAgent",
|
||||
description: "An agent that can get the weather in a city. ",
|
||||
systemPrompt:
|
||||
@@ -72,7 +76,7 @@ async function multiWeatherAgent() {
|
||||
});
|
||||
|
||||
// Create agent workflow with the agents
|
||||
const workflow = multiAgent({
|
||||
const workflow = new AgentWorkflow({
|
||||
agents: [weatherAgent, converterAgent],
|
||||
rootAgent: weatherAgent,
|
||||
verbose: false,
|
||||
@@ -1,17 +1,18 @@
|
||||
/**
|
||||
* This example shows how to use AgentWorkflow as a single agent with tools
|
||||
*/
|
||||
import { openai } from "@llamaindex/openai";
|
||||
import { Settings, agent } from "llamaindex";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { AgentWorkflow } from "llamaindex";
|
||||
import { getWeatherTool } from "../agent/utils/tools";
|
||||
|
||||
Settings.llm = openai({
|
||||
const llm = new OpenAI({
|
||||
model: "gpt-4o",
|
||||
});
|
||||
|
||||
async function singleWeatherAgent() {
|
||||
const workflow = agent({
|
||||
const workflow = AgentWorkflow.fromTools({
|
||||
tools: [getWeatherTool],
|
||||
llm,
|
||||
verbose: false,
|
||||
});
|
||||
|
||||
@@ -1,63 +1,69 @@
|
||||
import fs from "fs";
|
||||
import {
|
||||
agent,
|
||||
AgentToolCall,
|
||||
AgentToolCallResult,
|
||||
multiAgent,
|
||||
tool,
|
||||
AgentWorkflow,
|
||||
FunctionAgent,
|
||||
FunctionTool,
|
||||
} from "llamaindex";
|
||||
import { z } from "zod";
|
||||
|
||||
import { anthropic } from "@llamaindex/anthropic";
|
||||
import { Anthropic } from "@llamaindex/anthropic";
|
||||
|
||||
const weatherTool = tool({
|
||||
name: "weather",
|
||||
description: "Get the weather",
|
||||
parameters: z.object({
|
||||
location: z.string({
|
||||
description: "The location to get the weather for",
|
||||
}),
|
||||
}),
|
||||
execute: ({ location }) => {
|
||||
return `The weather in ${location} is sunny`;
|
||||
},
|
||||
const llm = new Anthropic({
|
||||
model: "claude-3-5-sonnet",
|
||||
});
|
||||
|
||||
const inflationTool = tool({
|
||||
name: "inflation",
|
||||
description: "Get the inflation",
|
||||
parameters: z.object({
|
||||
location: z.string({
|
||||
description: "The location to get the inflation for",
|
||||
}),
|
||||
}),
|
||||
execute: ({ location }) => {
|
||||
return `The inflation in ${location} is 2%`;
|
||||
const weatherTool = FunctionTool.from(
|
||||
(query: { location: string }) => {
|
||||
return `The weather in ${query.location} is sunny`;
|
||||
},
|
||||
});
|
||||
|
||||
const saveFileTool = tool({
|
||||
name: "saveFile",
|
||||
description:
|
||||
"Save the written content into a file that can be downloaded by the user",
|
||||
parameters: z.object({
|
||||
content: z.string({
|
||||
description: "The content to save into a file",
|
||||
{
|
||||
name: "weather",
|
||||
description: "Get the weather",
|
||||
parameters: z.object({
|
||||
location: z.string({
|
||||
description: "The location to get the weather for",
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
execute: ({ content }) => {
|
||||
},
|
||||
);
|
||||
|
||||
const inflationTool = FunctionTool.from(
|
||||
(query: { location: string }) => {
|
||||
return `The inflation in ${query.location} is 2%`;
|
||||
},
|
||||
{
|
||||
name: "inflation",
|
||||
description: "Get the inflation",
|
||||
parameters: z.object({
|
||||
location: z.string({
|
||||
description: "The location to get the inflation for",
|
||||
}),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const saveFileTool = FunctionTool.from(
|
||||
({ content }: { content: string }) => {
|
||||
const filePath = "./report.md";
|
||||
fs.writeFileSync(filePath, content);
|
||||
return `File saved successfully at ${filePath}`;
|
||||
},
|
||||
});
|
||||
{
|
||||
name: "saveFile",
|
||||
description:
|
||||
"Save the written content into a file that can be downloaded by the user",
|
||||
parameters: z.object({
|
||||
content: z.string({
|
||||
description: "The content to save into a file",
|
||||
}),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
async function main() {
|
||||
const llm = anthropic({
|
||||
model: "claude-3-5-sonnet",
|
||||
});
|
||||
|
||||
const reportAgent = agent({
|
||||
const reportAgent = new FunctionAgent({
|
||||
name: "ReportAgent",
|
||||
description:
|
||||
"Responsible for creating concise reports about weather and inflation data",
|
||||
@@ -66,7 +72,7 @@ async function main() {
|
||||
llm,
|
||||
});
|
||||
|
||||
const researchAgent = agent({
|
||||
const researchAgent = new FunctionAgent({
|
||||
name: "ResearchAgent",
|
||||
description:
|
||||
"Responsible for gathering relevant information from the internet",
|
||||
@@ -76,7 +82,7 @@ async function main() {
|
||||
llm,
|
||||
});
|
||||
|
||||
const workflow = multiAgent({
|
||||
const workflow = new AgentWorkflow({
|
||||
agents: [researchAgent, reportAgent],
|
||||
rootAgent: researchAgent,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { StartEvent, StopEvent, Workflow } from "llamaindex";
|
||||
import { StartEvent, StopEvent, Workflow } from "@llamaindex/workflow";
|
||||
|
||||
type ContextData = {
|
||||
counter: number;
|
||||
|
||||
+38
-38
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/examples",
|
||||
"version": "0.2.9",
|
||||
"version": "0.2.8",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
@@ -11,43 +11,43 @@
|
||||
"@azure/cosmos": "^4.1.1",
|
||||
"@azure/identity": "^4.4.1",
|
||||
"@azure/search-documents": "^12.1.0",
|
||||
"@llamaindex/anthropic": "^0.2.6",
|
||||
"@llamaindex/astra": "^0.0.13",
|
||||
"@llamaindex/azure": "^0.1.8",
|
||||
"@llamaindex/chroma": "^0.0.13",
|
||||
"@llamaindex/clip": "^0.0.44",
|
||||
"@llamaindex/cloud": "^3.0.9",
|
||||
"@llamaindex/cohere": "^0.0.13",
|
||||
"@llamaindex/core": "^0.5.8",
|
||||
"@llamaindex/deepinfra": "^0.0.44",
|
||||
"@llamaindex/anthropic": "^0.2.5",
|
||||
"@llamaindex/astra": "^0.0.12",
|
||||
"@llamaindex/azure": "^0.1.7",
|
||||
"@llamaindex/chroma": "^0.0.12",
|
||||
"@llamaindex/clip": "^0.0.43",
|
||||
"@llamaindex/cloud": "^3.0.8",
|
||||
"@llamaindex/cohere": "^0.0.12",
|
||||
"@llamaindex/core": "^0.5.7",
|
||||
"@llamaindex/deepinfra": "^0.0.43",
|
||||
"@llamaindex/env": "^0.1.29",
|
||||
"@llamaindex/firestore": "^1.0.6",
|
||||
"@llamaindex/google": "^0.1.1",
|
||||
"@llamaindex/groq": "^0.0.59",
|
||||
"@llamaindex/huggingface": "^0.0.44",
|
||||
"@llamaindex/milvus": "^0.1.8",
|
||||
"@llamaindex/mistral": "^0.0.13",
|
||||
"@llamaindex/mixedbread": "^0.0.13",
|
||||
"@llamaindex/mongodb": "^0.0.13",
|
||||
"@llamaindex/node-parser": "^1.0.8",
|
||||
"@llamaindex/ollama": "^0.0.48",
|
||||
"@llamaindex/openai": "^0.1.60",
|
||||
"@llamaindex/pinecone": "^0.0.13",
|
||||
"@llamaindex/portkey-ai": "^0.0.41",
|
||||
"@llamaindex/postgres": "^0.0.41",
|
||||
"@llamaindex/qdrant": "^0.1.8",
|
||||
"@llamaindex/readers": "^2.0.8",
|
||||
"@llamaindex/replicate": "^0.0.41",
|
||||
"@llamaindex/upstash": "^0.0.13",
|
||||
"@llamaindex/vercel": "^0.0.19",
|
||||
"@llamaindex/vllm": "^0.0.30",
|
||||
"@llamaindex/voyage-ai": "^1.0.5",
|
||||
"@llamaindex/weaviate": "^0.0.13",
|
||||
"@llamaindex/workflow": "^0.0.16",
|
||||
"@llamaindex/deepseek": "^0.0.4",
|
||||
"@llamaindex/fireworks": "^0.0.4",
|
||||
"@llamaindex/together": "^0.0.4",
|
||||
"@llamaindex/jinaai": "^0.0.4",
|
||||
"@llamaindex/firestore": "^1.0.5",
|
||||
"@llamaindex/google": "^0.1.0",
|
||||
"@llamaindex/groq": "^0.0.58",
|
||||
"@llamaindex/huggingface": "^0.0.43",
|
||||
"@llamaindex/milvus": "^0.1.7",
|
||||
"@llamaindex/mistral": "^0.0.12",
|
||||
"@llamaindex/mixedbread": "^0.0.12",
|
||||
"@llamaindex/mongodb": "^0.0.12",
|
||||
"@llamaindex/node-parser": "^1.0.7",
|
||||
"@llamaindex/ollama": "^0.0.47",
|
||||
"@llamaindex/openai": "^0.1.59",
|
||||
"@llamaindex/pinecone": "^0.0.12",
|
||||
"@llamaindex/portkey-ai": "^0.0.40",
|
||||
"@llamaindex/postgres": "^0.0.40",
|
||||
"@llamaindex/qdrant": "^0.1.7",
|
||||
"@llamaindex/readers": "^2.0.7",
|
||||
"@llamaindex/replicate": "^0.0.40",
|
||||
"@llamaindex/upstash": "^0.0.12",
|
||||
"@llamaindex/vercel": "^0.0.18",
|
||||
"@llamaindex/vllm": "^0.0.29",
|
||||
"@llamaindex/voyage-ai": "^1.0.4",
|
||||
"@llamaindex/weaviate": "^0.0.12",
|
||||
"@llamaindex/workflow": "^0.0.15",
|
||||
"@llamaindex/deepseek": "^0.0.3",
|
||||
"@llamaindex/fireworks": "^0.0.3",
|
||||
"@llamaindex/together": "^0.0.3",
|
||||
"@llamaindex/jinaai": "^0.0.3",
|
||||
"@notionhq/client": "^2.2.15",
|
||||
"@pinecone-database/pinecone": "^4.0.0",
|
||||
"@vercel/postgres": "^0.10.0",
|
||||
@@ -56,7 +56,7 @@
|
||||
"commander": "^12.1.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"js-tiktoken": "^1.0.14",
|
||||
"llamaindex": "^0.9.10",
|
||||
"llamaindex": "^0.9.9",
|
||||
"mongodb": "6.7.0",
|
||||
"postgres": "^3.4.4",
|
||||
"wikipedia": "^2.1.2",
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
StopEvent,
|
||||
Workflow,
|
||||
WorkflowEvent,
|
||||
} from "llamaindex";
|
||||
} from "@llamaindex/workflow";
|
||||
|
||||
const MAX_REVIEWS = 3;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
StopEvent,
|
||||
Workflow,
|
||||
WorkflowEvent,
|
||||
} from "llamaindex";
|
||||
} from "@llamaindex/workflow";
|
||||
|
||||
// Create LLM instance
|
||||
const llm = new OpenAI();
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { StartEvent, StopEvent, Workflow, WorkflowEvent } from "llamaindex";
|
||||
import {
|
||||
StartEvent,
|
||||
StopEvent,
|
||||
Workflow,
|
||||
WorkflowEvent,
|
||||
} from "@llamaindex/workflow";
|
||||
|
||||
// Create LLM instance
|
||||
const llm = new OpenAI();
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
StopEvent,
|
||||
Workflow,
|
||||
WorkflowEvent,
|
||||
} from "llamaindex";
|
||||
} from "@llamaindex/workflow";
|
||||
|
||||
// Create LLM instance
|
||||
const llm = new OpenAI();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { StartEvent, StopEvent, Workflow } from "llamaindex";
|
||||
import { StartEvent, StopEvent, Workflow } from "@llamaindex/workflow";
|
||||
|
||||
const longRunning = async (_: unknown, ev: StartEvent<string>) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000)); // Wait for 2 seconds
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { StartEvent, StopEvent, Workflow, WorkflowEvent } from "llamaindex";
|
||||
import {
|
||||
StartEvent,
|
||||
StopEvent,
|
||||
Workflow,
|
||||
WorkflowEvent,
|
||||
} from "@llamaindex/workflow";
|
||||
|
||||
// Create LLM instance
|
||||
const llm = new OpenAI();
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
# @llamaindex/autotool
|
||||
|
||||
## 6.0.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- Updated dependencies [40ee761]
|
||||
- llamaindex@0.9.10
|
||||
|
||||
## 6.0.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
# @llamaindex/autotool-01-node-example
|
||||
|
||||
## 0.0.91
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- Updated dependencies [40ee761]
|
||||
- llamaindex@0.9.10
|
||||
- @llamaindex/autotool@6.0.10
|
||||
|
||||
## 0.0.90
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -13,5 +13,5 @@
|
||||
"scripts": {
|
||||
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
|
||||
},
|
||||
"version": "0.0.91"
|
||||
"version": "0.0.90"
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
|
||||
"directory": "packages/autotool"
|
||||
},
|
||||
"version": "6.0.10",
|
||||
"version": "6.0.9",
|
||||
"description": "auto transpile your JS function to LLM Agent compatible",
|
||||
"files": [
|
||||
"dist",
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
# @llamaindex/cloud
|
||||
|
||||
## 3.0.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 3.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/cloud",
|
||||
"version": "3.0.9",
|
||||
"version": "3.0.8",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
{
|
||||
"$schema": "https://turbo.build/schema.json",
|
||||
"extends": ["//"],
|
||||
"tasks": {
|
||||
"build": {
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
# @llamaindex/community
|
||||
|
||||
## 0.0.90
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 0.0.89
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/community",
|
||||
"description": "Community package for LlamaIndexTS",
|
||||
"version": "0.0.90",
|
||||
"version": "0.0.89",
|
||||
"type": "module",
|
||||
"types": "dist/type/index.d.ts",
|
||||
"main": "dist/cjs/index.js",
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
# @llamaindex/core
|
||||
|
||||
## 0.5.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 40ee761: Add factory methods tool, agent and multiAgent to simplify agent usage
|
||||
|
||||
## 0.5.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/core",
|
||||
"type": "module",
|
||||
"version": "0.5.8",
|
||||
"version": "0.5.7",
|
||||
"description": "LlamaIndex Core Module",
|
||||
"exports": {
|
||||
"./agent": {
|
||||
|
||||
@@ -64,52 +64,12 @@ export class FunctionTool<
|
||||
parameters: R;
|
||||
},
|
||||
): FunctionTool<T, JSONValue, AdditionalToolArgument>;
|
||||
static from<
|
||||
R extends z.ZodType,
|
||||
AdditionalToolArgument extends object = object,
|
||||
>(
|
||||
config: Omit<ToolMetadata, "parameters"> & {
|
||||
parameters: R;
|
||||
execute: (
|
||||
input: z.infer<R>,
|
||||
additionalArg?: AdditionalToolArgument,
|
||||
) => JSONValue | Promise<JSONValue>;
|
||||
},
|
||||
): FunctionTool<
|
||||
z.infer<R>,
|
||||
JSONValue | Promise<JSONValue>,
|
||||
AdditionalToolArgument
|
||||
>;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
static from(fnOrConfig: any, schema?: any): any {
|
||||
// Handle the case where an object with execute function is passed
|
||||
if (
|
||||
typeof schema === "undefined" &&
|
||||
typeof fnOrConfig === "object" &&
|
||||
fnOrConfig.execute
|
||||
) {
|
||||
const { execute, parameters, ...restConfig } = fnOrConfig;
|
||||
|
||||
if (parameters instanceof z.ZodSchema) {
|
||||
const jsonSchema = zodToJsonSchema(parameters);
|
||||
return new FunctionTool(
|
||||
execute,
|
||||
{
|
||||
...restConfig,
|
||||
parameters: jsonSchema,
|
||||
},
|
||||
parameters,
|
||||
);
|
||||
}
|
||||
|
||||
return new FunctionTool(execute, fnOrConfig);
|
||||
}
|
||||
|
||||
// Handle the original cases
|
||||
if (schema && schema.parameters instanceof z.ZodSchema) {
|
||||
static from(fn: any, schema: any): any {
|
||||
if (schema.parameters instanceof z.ZodSchema) {
|
||||
const jsonSchema = zodToJsonSchema(schema.parameters);
|
||||
return new FunctionTool(
|
||||
fnOrConfig,
|
||||
fn,
|
||||
{
|
||||
...schema,
|
||||
parameters: jsonSchema,
|
||||
@@ -117,7 +77,7 @@ export class FunctionTool<
|
||||
schema.parameters,
|
||||
);
|
||||
}
|
||||
return new FunctionTool(fnOrConfig, schema);
|
||||
return new FunctionTool(fn, schema);
|
||||
}
|
||||
|
||||
get metadata(): BaseTool<T>["metadata"] {
|
||||
@@ -162,8 +122,3 @@ export class FunctionTool<
|
||||
return this.#fn.call(null, input, this.#additionalArg);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A simpler alias for creating a FunctionTool.
|
||||
*/
|
||||
export const tool = FunctionTool.from;
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "./function-tool";
|
||||
export { FunctionTool } from "./function-tool";
|
||||
|
||||
@@ -80,9 +80,8 @@ export {
|
||||
extractText,
|
||||
imageToDataUrl,
|
||||
messagesToHistory,
|
||||
MockLLM,
|
||||
toToolDescriptions,
|
||||
} from "./llms";
|
||||
|
||||
export { MockLLM } from "./mock";
|
||||
|
||||
export { objectEntries } from "./object-entries";
|
||||
|
||||
@@ -2,6 +2,15 @@ import { fs } from "@llamaindex/env";
|
||||
import { filetypemime } from "magic-bytes.js";
|
||||
import type {
|
||||
ChatMessage,
|
||||
ChatResponse,
|
||||
ChatResponseChunk,
|
||||
CompletionResponse,
|
||||
LLM,
|
||||
LLMChatParamsNonStreaming,
|
||||
LLMChatParamsStreaming,
|
||||
LLMCompletionParamsNonStreaming,
|
||||
LLMCompletionParamsStreaming,
|
||||
LLMMetadata,
|
||||
MessageContent,
|
||||
MessageContentDetail,
|
||||
MessageContentTextDetail,
|
||||
@@ -143,3 +152,82 @@ export async function imageToDataUrl(
|
||||
}
|
||||
return await blobToDataUrl(input);
|
||||
}
|
||||
|
||||
export class MockLLM implements LLM {
|
||||
metadata: LLMMetadata;
|
||||
options: {
|
||||
timeBetweenToken: number;
|
||||
responseMessage: string;
|
||||
};
|
||||
|
||||
constructor(options?: {
|
||||
timeBetweenToken?: number;
|
||||
responseMessage?: string;
|
||||
metadata?: LLMMetadata;
|
||||
}) {
|
||||
this.options = {
|
||||
timeBetweenToken: options?.timeBetweenToken ?? 20,
|
||||
responseMessage: options?.responseMessage ?? "This is a mock response",
|
||||
};
|
||||
this.metadata = options?.metadata ?? {
|
||||
model: "MockLLM",
|
||||
temperature: 0.5,
|
||||
topP: 0.5,
|
||||
contextWindow: 1024,
|
||||
tokenizer: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
chat(
|
||||
params: LLMChatParamsStreaming<object, object>,
|
||||
): Promise<AsyncIterable<ChatResponseChunk>>;
|
||||
chat(
|
||||
params: LLMChatParamsNonStreaming<object, object>,
|
||||
): Promise<ChatResponse<object>>;
|
||||
async chat(
|
||||
params:
|
||||
| LLMChatParamsStreaming<object, object>
|
||||
| LLMChatParamsNonStreaming<object, object>,
|
||||
): Promise<AsyncIterable<ChatResponseChunk> | ChatResponse<object>> {
|
||||
const responseMessage = this.options.responseMessage;
|
||||
const timeBetweenToken = this.options.timeBetweenToken;
|
||||
|
||||
if (params.stream) {
|
||||
return (async function* () {
|
||||
for (const char of responseMessage) {
|
||||
yield { delta: char, raw: {} };
|
||||
await new Promise((resolve) => setTimeout(resolve, timeBetweenToken));
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
return {
|
||||
message: { content: responseMessage, role: "assistant" },
|
||||
raw: {},
|
||||
};
|
||||
}
|
||||
|
||||
async complete(
|
||||
params: LLMCompletionParamsStreaming,
|
||||
): Promise<AsyncIterable<CompletionResponse>>;
|
||||
async complete(
|
||||
params: LLMCompletionParamsNonStreaming,
|
||||
): Promise<CompletionResponse>;
|
||||
async complete(
|
||||
params: LLMCompletionParamsStreaming | LLMCompletionParamsNonStreaming,
|
||||
): Promise<AsyncIterable<CompletionResponse> | CompletionResponse> {
|
||||
const responseMessage = this.options.responseMessage;
|
||||
const timeBetweenToken = this.options.timeBetweenToken;
|
||||
|
||||
if (params.stream) {
|
||||
return (async function* () {
|
||||
for (const char of responseMessage) {
|
||||
yield { delta: char, text: char, raw: {} };
|
||||
await new Promise((resolve) => setTimeout(resolve, timeBetweenToken));
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
return { text: responseMessage, raw: {} };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
// TODO: move to a test package
|
||||
import { ToolCallLLM } from "../llms/base";
|
||||
import type {
|
||||
ChatResponse,
|
||||
ChatResponseChunk,
|
||||
CompletionResponse,
|
||||
LLMChatParamsNonStreaming,
|
||||
LLMChatParamsStreaming,
|
||||
LLMCompletionParamsNonStreaming,
|
||||
LLMCompletionParamsStreaming,
|
||||
LLMMetadata,
|
||||
} from "../llms/type";
|
||||
|
||||
export class MockLLM extends ToolCallLLM {
|
||||
metadata: LLMMetadata;
|
||||
options: {
|
||||
timeBetweenToken: number;
|
||||
responseMessage: string;
|
||||
};
|
||||
supportToolCall: boolean = false;
|
||||
|
||||
constructor(options?: {
|
||||
timeBetweenToken?: number;
|
||||
responseMessage?: string;
|
||||
metadata?: LLMMetadata;
|
||||
}) {
|
||||
super();
|
||||
this.options = {
|
||||
timeBetweenToken: options?.timeBetweenToken ?? 20,
|
||||
responseMessage: options?.responseMessage ?? "This is a mock response",
|
||||
};
|
||||
this.metadata = options?.metadata ?? {
|
||||
model: "MockLLM",
|
||||
temperature: 0.5,
|
||||
topP: 0.5,
|
||||
contextWindow: 1024,
|
||||
tokenizer: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
chat(
|
||||
params: LLMChatParamsStreaming<object, object>,
|
||||
): Promise<AsyncIterable<ChatResponseChunk>>;
|
||||
chat(
|
||||
params: LLMChatParamsNonStreaming<object, object>,
|
||||
): Promise<ChatResponse<object>>;
|
||||
async chat(
|
||||
params:
|
||||
| LLMChatParamsStreaming<object, object>
|
||||
| LLMChatParamsNonStreaming<object, object>,
|
||||
): Promise<AsyncIterable<ChatResponseChunk> | ChatResponse<object>> {
|
||||
const responseMessage = this.options.responseMessage;
|
||||
const timeBetweenToken = this.options.timeBetweenToken;
|
||||
|
||||
if (params.stream) {
|
||||
return (async function* () {
|
||||
for (const char of responseMessage) {
|
||||
yield { delta: char, raw: {} };
|
||||
await new Promise((resolve) => setTimeout(resolve, timeBetweenToken));
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
return {
|
||||
message: { content: responseMessage, role: "assistant" },
|
||||
raw: {},
|
||||
};
|
||||
}
|
||||
|
||||
async complete(
|
||||
params: LLMCompletionParamsStreaming,
|
||||
): Promise<AsyncIterable<CompletionResponse>>;
|
||||
async complete(
|
||||
params: LLMCompletionParamsNonStreaming,
|
||||
): Promise<CompletionResponse>;
|
||||
async complete(
|
||||
params: LLMCompletionParamsStreaming | LLMCompletionParamsNonStreaming,
|
||||
): Promise<AsyncIterable<CompletionResponse> | CompletionResponse> {
|
||||
const responseMessage = this.options.responseMessage;
|
||||
const timeBetweenToken = this.options.timeBetweenToken;
|
||||
|
||||
if (params.stream) {
|
||||
return (async function* () {
|
||||
for (const char of responseMessage) {
|
||||
yield { delta: char, text: char, raw: {} };
|
||||
await new Promise((resolve) => setTimeout(resolve, timeBetweenToken));
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
return { text: responseMessage, raw: {} };
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FunctionTool, tool } from "@llamaindex/core/tools";
|
||||
import { FunctionTool } from "@llamaindex/core/tools";
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -27,41 +27,6 @@ describe("FunctionTool", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("create with execute attribute", async () => {
|
||||
// Mock function to be passed as execute attribute
|
||||
const mockExecute = vi.fn().mockImplementation(({ content }) => {
|
||||
return `File saved with content: ${content}`;
|
||||
});
|
||||
|
||||
const config = {
|
||||
name: "saveFile",
|
||||
description: "Save the content into a file",
|
||||
parameters: z.object({
|
||||
content: z.string({
|
||||
description: "The content to save into a file",
|
||||
}),
|
||||
}),
|
||||
execute: mockExecute,
|
||||
};
|
||||
|
||||
// Create tool using an execute attribute
|
||||
const saveTool = FunctionTool.from(config);
|
||||
|
||||
// Call the tool and verify
|
||||
const result = await saveTool.call({ content: "test content" });
|
||||
expect(mockExecute).toHaveBeenCalledOnce();
|
||||
expect(mockExecute).toHaveBeenCalledWith(
|
||||
{ content: "test content" },
|
||||
undefined,
|
||||
);
|
||||
expect(result).toBe("File saved with content: test content");
|
||||
|
||||
// Test tool alias
|
||||
const saveTool2 = tool(config);
|
||||
const result2 = await saveTool2.call({ content: "test content" });
|
||||
expect(result2).toBe("File saved with content: test content");
|
||||
});
|
||||
|
||||
test("bind additional argument", () => {
|
||||
type AdditionalHelloArgument = {
|
||||
question?: string;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
{
|
||||
"$schema": "https://turbo.build/schema.json",
|
||||
"extends": ["//"],
|
||||
"tasks": {
|
||||
"build": {
|
||||
|
||||
Vendored
-1
@@ -1,5 +1,4 @@
|
||||
{
|
||||
"$schema": "https://turbo.build/schema.json",
|
||||
"extends": ["//"],
|
||||
"tasks": {
|
||||
"build": {
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
# @llamaindex/experimental
|
||||
|
||||
## 0.0.160
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- Updated dependencies [40ee761]
|
||||
- llamaindex@0.9.10
|
||||
|
||||
## 0.0.159
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/experimental",
|
||||
"description": "Experimental package for LlamaIndexTS",
|
||||
"version": "0.0.160",
|
||||
"version": "0.0.159",
|
||||
"type": "module",
|
||||
"types": "dist/type/index.d.ts",
|
||||
"main": "dist/cjs/index.js",
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
# llamaindex
|
||||
|
||||
## 0.9.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- c1b5be5: feat: make AgentWorkflow llm param optional
|
||||
- 40ee761: Add factory methods tool, agent and multiAgent to simplify agent usage
|
||||
- 40ee761: feat: add asQueryTool to index
|
||||
- Updated dependencies [aea550a]
|
||||
- Updated dependencies [c1b5be5]
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/openai@0.1.60
|
||||
- @llamaindex/workflow@0.0.16
|
||||
- @llamaindex/core@0.5.8
|
||||
- @llamaindex/cloud@3.0.9
|
||||
- @llamaindex/node-parser@1.0.8
|
||||
|
||||
## 0.9.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "llamaindex",
|
||||
"version": "0.9.10",
|
||||
"version": "0.9.9",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
|
||||
@@ -67,7 +67,6 @@ export * from "@llamaindex/core/storage/index-store";
|
||||
export * from "@llamaindex/core/storage/kv-store";
|
||||
export * from "@llamaindex/core/utils";
|
||||
export * from "@llamaindex/openai";
|
||||
export * from "@llamaindex/workflow";
|
||||
export * from "@llamaindex/workflow/agent";
|
||||
export * from "./agent/index.js";
|
||||
export * from "./cloud/index.js";
|
||||
|
||||
@@ -2,21 +2,15 @@ import type {
|
||||
BaseChatEngine,
|
||||
ContextChatEngineOptions,
|
||||
} from "@llamaindex/core/chat-engine";
|
||||
import type { ToolMetadata } from "@llamaindex/core/llms";
|
||||
import type { BaseQueryEngine } from "@llamaindex/core/query-engine";
|
||||
import type { BaseSynthesizer } from "@llamaindex/core/response-synthesizers";
|
||||
import type { BaseRetriever } from "@llamaindex/core/retriever";
|
||||
import type { BaseNode, Document } from "@llamaindex/core/schema";
|
||||
import type { BaseDocumentStore } from "@llamaindex/core/storage/doc-store";
|
||||
import type { BaseIndexStore } from "@llamaindex/core/storage/index-store";
|
||||
import type { JSONSchemaType } from "ajv";
|
||||
import { runTransformations } from "../ingestion/IngestionPipeline.js";
|
||||
import { Settings } from "../Settings.js";
|
||||
import type { StorageContext } from "../storage/StorageContext.js";
|
||||
import {
|
||||
type QueryEngineParam,
|
||||
QueryEngineTool,
|
||||
} from "../tools/QueryEngineTool.js";
|
||||
|
||||
export interface BaseIndexInit<T> {
|
||||
storageContext: StorageContext;
|
||||
@@ -25,24 +19,6 @@ export interface BaseIndexInit<T> {
|
||||
indexStruct: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Common parameter type for queryTool and asQueryTool
|
||||
*/
|
||||
export type QueryToolParams = (
|
||||
| {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
options: any;
|
||||
retriever?: never;
|
||||
}
|
||||
| {
|
||||
options?: never;
|
||||
retriever?: BaseRetriever;
|
||||
}
|
||||
) & {
|
||||
responseSynthesizer?: BaseSynthesizer;
|
||||
metadata?: ToolMetadata<JSONSchemaType<QueryEngineParam>> | undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Indexes are the data structure that we store our nodes and embeddings in so
|
||||
* they can be retrieved for our queries.
|
||||
@@ -85,22 +61,6 @@ export abstract class BaseIndex<T> {
|
||||
options?: Omit<ContextChatEngineOptions, "retriever">,
|
||||
): BaseChatEngine;
|
||||
|
||||
/**
|
||||
* Returns a query tool by calling asQueryEngine.
|
||||
* Either options or retriever can be passed, but not both.
|
||||
* If options are provided, they are passed to generate a retriever.
|
||||
*/
|
||||
asQueryTool(params: QueryToolParams): QueryEngineTool {
|
||||
if (params.options) {
|
||||
params.retriever = this.asRetriever(params.options);
|
||||
}
|
||||
|
||||
return new QueryEngineTool({
|
||||
queryEngine: this.asQueryEngine(params),
|
||||
metadata: params?.metadata,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a document into the index.
|
||||
* @param document
|
||||
@@ -116,33 +76,4 @@ export abstract class BaseIndex<T> {
|
||||
refDocId: string,
|
||||
deleteFromDocStore?: boolean,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* Alias for asRetriever
|
||||
* @param options
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
retriever(options?: any): BaseRetriever {
|
||||
return this.asRetriever(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for asQueryEngine
|
||||
* @param options you can supply your own custom Retriever and ResponseSynthesizer
|
||||
*/
|
||||
queryEngine(options?: {
|
||||
retriever?: BaseRetriever;
|
||||
responseSynthesizer?: BaseSynthesizer;
|
||||
}): BaseQueryEngine {
|
||||
return this.asQueryEngine(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for asQueryTool
|
||||
* Either options or retriever can be passed, but not both.
|
||||
* If options are provided, they are passed to generate a retriever.
|
||||
*/
|
||||
queryTool(params: QueryToolParams): QueryEngineTool {
|
||||
return this.asQueryTool(params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ const DEFAULT_PARAMETERS: JSONSchemaType<QueryEngineParam> = {
|
||||
|
||||
export type QueryEngineToolParams = {
|
||||
queryEngine: BaseQueryEngine;
|
||||
metadata?: ToolMetadata<JSONSchemaType<QueryEngineParam>> | undefined;
|
||||
metadata: ToolMetadata<JSONSchemaType<QueryEngineParam>>;
|
||||
};
|
||||
|
||||
export type QueryEngineParam = {
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
# @llamaindex/node-parser
|
||||
|
||||
## 1.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 1.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/node-parser",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.7",
|
||||
"description": "Node parser for LlamaIndex",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
{
|
||||
"$schema": "https://turbo.build/schema.json",
|
||||
"extends": ["//"],
|
||||
"tasks": {
|
||||
"build": {
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
# @llamaindex/anthropic
|
||||
|
||||
## 0.2.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- aea550a: Add factory convenience factory for each LLM provider, e.g. you can use openai instead of 'new OpenAI'
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 0.2.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/anthropic",
|
||||
"description": "Anthropic Adapter for LlamaIndex",
|
||||
"version": "0.2.6",
|
||||
"version": "0.2.5",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,2 +1,14 @@
|
||||
export * from "./agent";
|
||||
export * from "./llm";
|
||||
export {
|
||||
AnthropicAgent,
|
||||
AnthropicAgentWorker,
|
||||
type AnthropicAgentParams,
|
||||
} from "./agent";
|
||||
export {
|
||||
ALL_AVAILABLE_ANTHROPIC_LEGACY_MODELS,
|
||||
ALL_AVAILABLE_ANTHROPIC_MODELS,
|
||||
ALL_AVAILABLE_V3_5_MODELS,
|
||||
ALL_AVAILABLE_V3_MODELS,
|
||||
Anthropic,
|
||||
AnthropicSession,
|
||||
type AnthropicAdditionalChatOptions,
|
||||
} from "./llm";
|
||||
|
||||
@@ -60,7 +60,7 @@ const defaultAnthropicSession: {
|
||||
* @param options
|
||||
* @returns
|
||||
*/
|
||||
function getAnthropicSession(options: ClientOptions = {}) {
|
||||
export function getAnthropicSession(options: ClientOptions = {}) {
|
||||
let session = defaultAnthropicSession.find((session) => {
|
||||
return isDeepEqual(session.options, options);
|
||||
})?.session;
|
||||
@@ -586,11 +586,3 @@ export class Anthropic extends ToolCallLLM<
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to create a new Anthropic instance.
|
||||
* @param init - Optional initialization parameters for the Anthropic instance.
|
||||
* @returns A new Anthropic instance.
|
||||
*/
|
||||
export const anthropic = (init?: ConstructorParameters<typeof Anthropic>[0]) =>
|
||||
new Anthropic(init);
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
# @llamaindex/clip
|
||||
|
||||
## 0.0.44
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [aea550a]
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/openai@0.1.60
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 0.0.43
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/clip",
|
||||
"description": "Clip Embedding Adapter for LlamaIndex",
|
||||
"version": "0.0.44",
|
||||
"version": "0.0.43",
|
||||
"type": "module",
|
||||
"types": "dist/index.d.ts",
|
||||
"main": "dist/index.cjs",
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
# @llamaindex/cohere
|
||||
|
||||
## 0.0.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 0.0.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/cohere",
|
||||
"description": "Cohere Adapter for LlamaIndex",
|
||||
"version": "0.0.13",
|
||||
"version": "0.0.12",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
# @llamaindex/deepinfra
|
||||
|
||||
## 0.0.44
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- aea550a: Add factory convenience factory for each LLM provider, e.g. you can use openai instead of 'new OpenAI'
|
||||
- Updated dependencies [aea550a]
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/openai@0.1.60
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 0.0.43
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/deepinfra",
|
||||
"description": "Deepinfra Adapter for LlamaIndex",
|
||||
"version": "0.0.44",
|
||||
"version": "0.0.43",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -3,4 +3,4 @@ export {
|
||||
type DeepInfraEmbeddingResponse,
|
||||
type InferenceStatus,
|
||||
} from "./embedding";
|
||||
export * from "./llm";
|
||||
export { DeepInfra } from "./llm";
|
||||
|
||||
@@ -31,11 +31,3 @@ export class DeepInfra extends OpenAI {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to create a new DeepInfra instance.
|
||||
* @param init - Optional initialization parameters for the DeepInfra instance.
|
||||
* @returns A new DeepInfra instance.
|
||||
*/
|
||||
export const deepinfra = (init?: ConstructorParameters<typeof DeepInfra>[0]) =>
|
||||
new DeepInfra(init);
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
# @llamaindex/deepseek
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- aea550a: Add factory convenience factory for each LLM provider, e.g. you can use openai instead of 'new OpenAI'
|
||||
- Updated dependencies [aea550a]
|
||||
- @llamaindex/openai@0.1.60
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/deepseek",
|
||||
"description": "DeepSeek Adapter for LlamaIndex",
|
||||
"version": "0.0.4",
|
||||
"version": "0.0.3",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -35,11 +35,3 @@ export class DeepSeekLLM extends OpenAI {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to create a new DeepSeekLLM instance.
|
||||
* @param init - Optional initialization parameters for the DeepSeekLLM instance.
|
||||
* @returns A new DeepSeekLLM instance.
|
||||
*/
|
||||
export const deepseek = (init?: ConstructorParameters<typeof DeepSeekLLM>[0]) =>
|
||||
new DeepSeekLLM(init);
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
# @llamaindex/fireworks
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- aea550a: Add factory convenience factory for each LLM provider, e.g. you can use openai instead of 'new OpenAI'
|
||||
- Updated dependencies [aea550a]
|
||||
- @llamaindex/openai@0.1.60
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/fireworks",
|
||||
"description": "Fireworks Adapter for LlamaIndex",
|
||||
"version": "0.0.4",
|
||||
"version": "0.0.3",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -26,12 +26,3 @@ export class FireworksLLM extends OpenAI {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to create a new FireworksLLM instance.
|
||||
* @param init - Optional initialization parameters for the FireworksLLM instance.
|
||||
* @returns A new FireworksLLM instance.
|
||||
*/
|
||||
export const fireworks = (
|
||||
init?: ConstructorParameters<typeof FireworksLLM>[0],
|
||||
) => new FireworksLLM(init);
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
# @llamaindex/google
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 33f9856: Fix google start chat tools parameter
|
||||
- aea550a: Add factory convenience factory for each LLM provider, e.g. you can use openai instead of 'new OpenAI'
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/google",
|
||||
"description": "Google Adapter for LlamaIndex",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -231,37 +231,29 @@ export class Gemini extends ToolCallLLM<GeminiAdditionalChatOptions> {
|
||||
};
|
||||
}
|
||||
|
||||
private createStartChatParams(
|
||||
params: GeminiChatParamsNonStreaming | GeminiChatParamsStreaming,
|
||||
) {
|
||||
const context = getChatContext(params);
|
||||
const common = {
|
||||
history: context.history,
|
||||
safetySettings: DEFAULT_SAFETY_SETTINGS,
|
||||
};
|
||||
|
||||
return params.tools?.length
|
||||
? {
|
||||
...common,
|
||||
// only if non-empty tools list
|
||||
tools: [
|
||||
{
|
||||
functionDeclarations: params.tools.map(
|
||||
mapBaseToolToGeminiFunctionDeclaration,
|
||||
),
|
||||
},
|
||||
],
|
||||
safetySettings: DEFAULT_SAFETY_SETTINGS,
|
||||
}
|
||||
: common;
|
||||
}
|
||||
|
||||
protected async nonStreamChat(
|
||||
params: GeminiChatParamsNonStreaming,
|
||||
): Promise<GeminiChatNonStreamResponse> {
|
||||
const context = getChatContext(params);
|
||||
const client = this.session.getGenerativeModel(this.metadata);
|
||||
const chat = client.startChat(this.createStartChatParams(params));
|
||||
const chat = client.startChat(
|
||||
params.tools
|
||||
? {
|
||||
history: context.history,
|
||||
tools: [
|
||||
{
|
||||
functionDeclarations: params.tools.map(
|
||||
mapBaseToolToGeminiFunctionDeclaration,
|
||||
),
|
||||
},
|
||||
],
|
||||
safetySettings: DEFAULT_SAFETY_SETTINGS,
|
||||
}
|
||||
: {
|
||||
history: context.history,
|
||||
safetySettings: DEFAULT_SAFETY_SETTINGS,
|
||||
},
|
||||
);
|
||||
const { response } = await chat.sendMessage(context.message);
|
||||
const topCandidate = response.candidates![0]!;
|
||||
|
||||
@@ -287,7 +279,26 @@ export class Gemini extends ToolCallLLM<GeminiAdditionalChatOptions> {
|
||||
): GeminiChatStreamResponse {
|
||||
const context = getChatContext(params);
|
||||
const client = this.session.getGenerativeModel(this.metadata);
|
||||
const chat = client.startChat(this.createStartChatParams(params));
|
||||
const tools = params.tools?.length
|
||||
? [
|
||||
{
|
||||
functionDeclarations: params.tools.map(
|
||||
mapBaseToolToGeminiFunctionDeclaration,
|
||||
),
|
||||
},
|
||||
]
|
||||
: [];
|
||||
const startChatParams = params.tools
|
||||
? {
|
||||
history: context.history,
|
||||
tools,
|
||||
safetySettings: DEFAULT_SAFETY_SETTINGS,
|
||||
}
|
||||
: {
|
||||
history: context.history,
|
||||
safetySettings: DEFAULT_SAFETY_SETTINGS,
|
||||
};
|
||||
const chat = client.startChat(startChatParams);
|
||||
const result = await chat.sendMessageStream(context.message);
|
||||
yield* this.session.getChatStream(result);
|
||||
}
|
||||
@@ -336,11 +347,3 @@ export class Gemini extends ToolCallLLM<GeminiAdditionalChatOptions> {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to create a new Gemini instance.
|
||||
* @param init - Optional initialization parameters for the Gemini instance.
|
||||
* @returns A new Gemini instance.
|
||||
*/
|
||||
export const gemini = (init?: ConstructorParameters<typeof Gemini>[0]) =>
|
||||
new Gemini(init);
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
# @llamaindex/groq
|
||||
|
||||
## 0.0.59
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- aea550a: Add factory convenience factory for each LLM provider, e.g. you can use openai instead of 'new OpenAI'
|
||||
- Updated dependencies [aea550a]
|
||||
- @llamaindex/openai@0.1.60
|
||||
|
||||
## 0.0.58
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/groq",
|
||||
"description": "Groq Adapter for LlamaIndex",
|
||||
"version": "0.0.59",
|
||||
"version": "0.0.58",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "./llm";
|
||||
export { Groq } from "./llm";
|
||||
|
||||
@@ -29,11 +29,3 @@ export class Groq extends OpenAI {
|
||||
}) as never;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to create a new Groq instance.
|
||||
* @param init - Optional initialization parameters for the Groq instance.
|
||||
* @returns A new Groq instance.
|
||||
*/
|
||||
export const groq = (init?: ConstructorParameters<typeof Groq>[0]) =>
|
||||
new Groq(init);
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
# @llamaindex/huggingface
|
||||
|
||||
## 0.0.44
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- aea550a: Add factory convenience factory for each LLM provider, e.g. you can use openai instead of 'new OpenAI'
|
||||
- Updated dependencies [aea550a]
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/openai@0.1.60
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 0.0.43
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/huggingface",
|
||||
"description": "Huggingface Adapter for LlamaIndex",
|
||||
"version": "0.0.44",
|
||||
"version": "0.0.43",
|
||||
"type": "module",
|
||||
"types": "dist/index.d.ts",
|
||||
"main": "dist/index.cjs",
|
||||
|
||||
@@ -2,7 +2,7 @@ export {
|
||||
HuggingFaceEmbedding,
|
||||
type HuggingFaceEmbeddingParams,
|
||||
} from "./embedding";
|
||||
export * from "./llm";
|
||||
export { HuggingFaceLLM, type HFLLMConfig } from "./llm";
|
||||
export {
|
||||
HuggingFaceEmbeddingModelType,
|
||||
HuggingFaceInferenceAPI,
|
||||
|
||||
@@ -146,12 +146,3 @@ export class HuggingFaceLLM extends BaseLLM {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to create a new HuggingFaceLLM instance.
|
||||
* @param init - Optional initialization parameters for the HuggingFaceLLM instance.
|
||||
* @returns A new HuggingFaceLLM instance.
|
||||
*/
|
||||
export const huggingface = (
|
||||
init?: ConstructorParameters<typeof HuggingFaceLLM>[0],
|
||||
) => new HuggingFaceLLM(init);
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
# @llamaindex/jinaai
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [aea550a]
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/openai@0.1.60
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/jinaai",
|
||||
"description": "JinaAI Adapter for LlamaIndex",
|
||||
"version": "0.0.4",
|
||||
"version": "0.0.3",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
# @llamaindex/mistral
|
||||
|
||||
## 0.0.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- aea550a: Add factory convenience factory for each LLM provider, e.g. you can use openai instead of 'new OpenAI'
|
||||
- Updated dependencies [40ee761]
|
||||
- @llamaindex/core@0.5.8
|
||||
|
||||
## 0.0.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/mistral",
|
||||
"description": "Mistral Adapter for LlamaIndex",
|
||||
"version": "0.0.13",
|
||||
"version": "0.0.12",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user