From 1ea5ef089ce73af587ef108e05cd355eebafe6a0 Mon Sep 17 00:00:00 2001 From: Lars Grammel Date: Tue, 26 Dec 2023 19:00:42 +0100 Subject: [PATCH] v0.105.0 --- CHANGELOG.md | 49 ++++++++++++++++++ examples/babyagi-agent/package.json | 2 +- examples/basic/package.json | 2 +- examples/chatbot-next-js/package.json | 2 +- examples/cloudflare-workers/package.json | 2 +- examples/image-generator-next-js/package.json | 2 +- .../middle-school-math-agent/package.json | 2 +- examples/pdf-chat-terminal/package.json | 2 +- examples/pdf-to-tweet/package.json | 2 +- .../package.json | 2 +- examples/wikipedia-agent/package.json | 2 +- .../package.json | 2 +- packages/@modelfusion-pinecone/package.json | 2 +- .../@modelfusion-serpapi-tools/package.json | 2 +- packages/@modelfusion-sqlite-vss/package.json | 2 +- packages/@modelfusion-vercel-ai/package.json | 2 +- packages/modelfusion/package.json | 2 +- pnpm-lock.yaml | 50 ++++++++++++------- test-environments/commonjs/package.json | 2 +- 19 files changed, 99 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46d31d9b3..6f756b429 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,54 @@ # Changelog +## v0.105.0 - 2023-12-26 + +### Added + +- Tool call support for chat prompts. Assistant messages can contain tool calls, and tool messages can contain tool call results. Tool calls can be used to implement e.g. agents: + + ```ts + const chat: ChatPrompt = { + system: "You are ...", + messages: [ChatMessage.user({ text: instruction })], + }; + + while (true) { + const { text, toolResults } = await useToolsOrGenerateText( + openai + .ChatTextGenerator({ model: "gpt-4-1106-preview" }) + .withChatPrompt(), + tools, // array of tools + chat + ); + + // add the assistant and tool messages to the chat: + chat.messages.push( + ChatMessage.assistant({ text, toolResults }), + ChatMessage.tool({ toolResults }) + ); + + if (toolResults == null) { + return; // no more actions, break loop + } + + // ... (handle tool results) + } + ``` + +- `streamText` returns a `text` promise when invoked with `fullResponse: true`. After the streaming has finished, the promise resolves with the full text. + + ```ts + const { text, textStream } = await streamText( + openai.ChatTextGenerator({ model: "gpt-3.5-turbo" }).withTextPrompt(), + "Write a short story about a robot learning to love:", + { fullResponse: true } + ); + + // ... (handle streaming) + + console.log(await text); // full text + ``` + ## v0.104.0 - 2023-12-24 ### Changed diff --git a/examples/babyagi-agent/package.json b/examples/babyagi-agent/package.json index f6a348645..33074b2d3 100644 --- a/examples/babyagi-agent/package.json +++ b/examples/babyagi-agent/package.json @@ -12,7 +12,7 @@ "commander": "10.0.1", "dotenv": "16.0.3", "jsdom": "^22.1.0", - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "serpapi": "^2.0.0" }, "devDependencies": { diff --git a/examples/basic/package.json b/examples/basic/package.json index 1a72fbc30..950c90b5e 100644 --- a/examples/basic/package.json +++ b/examples/basic/package.json @@ -11,7 +11,7 @@ "@pinecone-database/pinecone": "0.1.6", "dotenv": "16.0.3", "secure-json-parse": "2.7.0", - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "nanoid": "3.3.6", "better-sqlite3": "9.0.0", "sqlite-vss": "0.1.2", diff --git a/examples/chatbot-next-js/package.json b/examples/chatbot-next-js/package.json index eebb39866..366b61d36 100644 --- a/examples/chatbot-next-js/package.json +++ b/examples/chatbot-next-js/package.json @@ -20,7 +20,7 @@ "@emotion/styled": "11.10.8", "@mui/icons-material": "5.11.16", "@mui/material": "5.12.2", - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "next": "13.5.1", "react": "18.2.0", "react-dom": "18.2.0", diff --git a/examples/cloudflare-workers/package.json b/examples/cloudflare-workers/package.json index 00a4a32f9..496d8c46f 100644 --- a/examples/cloudflare-workers/package.json +++ b/examples/cloudflare-workers/package.json @@ -15,6 +15,6 @@ "wrangler": "^3.0.0" }, "dependencies": { - "modelfusion": "0.104.0" + "modelfusion": "0.105.0" } } diff --git a/examples/image-generator-next-js/package.json b/examples/image-generator-next-js/package.json index e42736238..4949f3f49 100644 --- a/examples/image-generator-next-js/package.json +++ b/examples/image-generator-next-js/package.json @@ -20,7 +20,7 @@ "dependencies": { "@emotion/react": "^11.11.0", "@emotion/styled": "^11.11.0", - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "next": "13.5.1", "react": "18.2.0", "react-dom": "18.2.0" diff --git a/examples/middle-school-math-agent/package.json b/examples/middle-school-math-agent/package.json index 3bfcb0c04..0586511c7 100644 --- a/examples/middle-school-math-agent/package.json +++ b/examples/middle-school-math-agent/package.json @@ -8,7 +8,7 @@ "clean": "rimraf build dist .turbo node_modules && pnpm clear" }, "dependencies": { - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "dotenv": "16.0.3", "zod": "3.22.4" }, diff --git a/examples/pdf-chat-terminal/package.json b/examples/pdf-chat-terminal/package.json index 1dcca0cbb..bd806b54c 100644 --- a/examples/pdf-chat-terminal/package.json +++ b/examples/pdf-chat-terminal/package.json @@ -9,7 +9,7 @@ }, "private": true, "dependencies": { - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "commander": "10.0.1", "dotenv": "16.0.3", "pdfjs-dist": "3.6.172" diff --git a/examples/pdf-to-tweet/package.json b/examples/pdf-to-tweet/package.json index 6d4498fba..94613c895 100644 --- a/examples/pdf-to-tweet/package.json +++ b/examples/pdf-to-tweet/package.json @@ -9,7 +9,7 @@ }, "private": true, "dependencies": { - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "commander": "10.0.1", "dotenv": "16.0.3", "pdfjs-dist": "3.6.172", diff --git a/examples/speech-streaming-vite-react-fastify/package.json b/examples/speech-streaming-vite-react-fastify/package.json index 899f7d769..2219cd2b0 100644 --- a/examples/speech-streaming-vite-react-fastify/package.json +++ b/examples/speech-streaming-vite-react-fastify/package.json @@ -19,7 +19,7 @@ "clsx": "^2.0.0", "dotenv": "16.0.3", "fastify": "^4.23.2", - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "react": "^18.2.0", "react-dom": "^18.2.0", "tailwind-merge": "^1.14.0", diff --git a/examples/wikipedia-agent/package.json b/examples/wikipedia-agent/package.json index 67bd676a7..96da6ea0f 100644 --- a/examples/wikipedia-agent/package.json +++ b/examples/wikipedia-agent/package.json @@ -14,7 +14,7 @@ "dotenv": "16.0.3", "html-to-text": "9.0.5", "jsdom": "^22.1.0", - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "zod": "3.22.4" }, "devDependencies": { diff --git a/packages/@modelfusion-google-custom-search-tool/package.json b/packages/@modelfusion-google-custom-search-tool/package.json index 3db91c948..e62225b65 100644 --- a/packages/@modelfusion-google-custom-search-tool/package.json +++ b/packages/@modelfusion-google-custom-search-tool/package.json @@ -55,7 +55,7 @@ "@typescript-eslint/parser": "^6.1.0", "eslint": "^8.45.0", "eslint-config-prettier": "9.1.0", - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "zod": "3.22.4" }, "peerDependencies": { diff --git a/packages/@modelfusion-pinecone/package.json b/packages/@modelfusion-pinecone/package.json index 6ab6d7be8..99ff27b8a 100644 --- a/packages/@modelfusion-pinecone/package.json +++ b/packages/@modelfusion-pinecone/package.json @@ -54,7 +54,7 @@ "@typescript-eslint/parser": "^6.1.0", "eslint": "^8.45.0", "eslint-config-prettier": "9.1.0", - "modelfusion": "0.104.0" + "modelfusion": "0.105.0" }, "peerDependencies": { "modelfusion": ">=0.72.0 <1.0.0-0", diff --git a/packages/@modelfusion-serpapi-tools/package.json b/packages/@modelfusion-serpapi-tools/package.json index c86f8eb52..53fdf01b6 100644 --- a/packages/@modelfusion-serpapi-tools/package.json +++ b/packages/@modelfusion-serpapi-tools/package.json @@ -57,7 +57,7 @@ "@typescript-eslint/parser": "^6.1.0", "eslint": "^8.45.0", "eslint-config-prettier": "9.1.0", - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "zod": "3.22.4" }, "peerDependencies": { diff --git a/packages/@modelfusion-sqlite-vss/package.json b/packages/@modelfusion-sqlite-vss/package.json index 7e738c50b..487bce2e4 100644 --- a/packages/@modelfusion-sqlite-vss/package.json +++ b/packages/@modelfusion-sqlite-vss/package.json @@ -54,7 +54,7 @@ "@typescript-eslint/parser": "^6.1.0", "eslint": "^8.45.0", "eslint-config-prettier": "9.1.0", - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "sqlite-vss": "^0.1.2", "better-sqlite3": "^9.0.0" }, diff --git a/packages/@modelfusion-vercel-ai/package.json b/packages/@modelfusion-vercel-ai/package.json index f8d9f1e82..142ae21e5 100644 --- a/packages/@modelfusion-vercel-ai/package.json +++ b/packages/@modelfusion-vercel-ai/package.json @@ -55,7 +55,7 @@ "ai": ">= 2.2.27", "eslint": "^8.45.0", "eslint-config-prettier": "9.1.0", - "modelfusion": "0.104.0" + "modelfusion": "0.105.0" }, "peerDependencies": { "modelfusion": ">=0.89.0", diff --git a/packages/modelfusion/package.json b/packages/modelfusion/package.json index 1b0ae0168..1b033f093 100644 --- a/packages/modelfusion/package.json +++ b/packages/modelfusion/package.json @@ -1,7 +1,7 @@ { "name": "modelfusion", "description": "The TypeScript library for building multi-modal AI applications.", - "version": "0.104.0", + "version": "0.105.0", "author": "Lars Grammel", "license": "MIT", "keywords": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9f615d6aa..e651bf31b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -103,7 +103,7 @@ importers: specifier: ^22.1.0 version: 22.1.0 modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../../packages/modelfusion/dist serpapi: specifier: ^2.0.0 @@ -140,7 +140,7 @@ importers: specifier: 16.0.3 version: 16.0.3 modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../../packages/modelfusion/dist nanoid: specifier: 3.3.6 @@ -180,7 +180,7 @@ importers: specifier: 5.12.2 version: 5.12.2(@emotion/react@11.10.8)(@emotion/styled@11.10.8)(@types/react@18.2.15)(react-dom@18.2.0)(react@18.2.0) modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../../packages/modelfusion/dist next: specifier: 13.5.1 @@ -220,7 +220,7 @@ importers: examples/cloudflare-workers: dependencies: modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../../packages/modelfusion/dist devDependencies: '@cloudflare/workers-types': @@ -242,7 +242,7 @@ importers: specifier: ^11.11.0 version: 11.11.0(@emotion/react@11.11.1)(@types/react@18.2.15)(react@18.2.0) modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../../packages/modelfusion/dist next: specifier: 13.5.1 @@ -279,7 +279,7 @@ importers: specifier: 16.0.3 version: 16.0.3 modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../../packages/modelfusion/dist zod: specifier: 3.22.4 @@ -298,7 +298,7 @@ importers: specifier: 16.0.3 version: 16.0.3 modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../../packages/modelfusion/dist pdfjs-dist: specifier: 3.6.172 @@ -317,7 +317,7 @@ importers: specifier: 16.0.3 version: 16.0.3 modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../../packages/modelfusion/dist pdfjs-dist: specifier: 3.6.172 @@ -354,7 +354,7 @@ importers: specifier: ^4.23.2 version: 4.25.1 modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../../packages/modelfusion/dist react: specifier: ^18.2.0 @@ -433,7 +433,7 @@ importers: specifier: ^22.1.0 version: 22.1.0 modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../../packages/modelfusion/dist zod: specifier: 3.22.4 @@ -467,7 +467,7 @@ importers: specifier: 9.1.0 version: 9.1.0(eslint@8.56.0) modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../modelfusion/dist zod: specifier: 3.22.4 @@ -495,7 +495,7 @@ importers: specifier: 9.1.0 version: 9.1.0(eslint@8.56.0) modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../modelfusion/dist publishDirectory: dist @@ -521,7 +521,7 @@ importers: specifier: 9.1.0 version: 9.1.0(eslint@8.56.0) modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../modelfusion/dist zod: specifier: 3.22.4 @@ -552,7 +552,7 @@ importers: specifier: 9.1.0 version: 9.1.0(eslint@8.56.0) modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../modelfusion/dist sqlite-vss: specifier: ^0.1.2 @@ -583,7 +583,7 @@ importers: specifier: 9.1.0 version: 9.1.0(eslint@8.56.0) modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../modelfusion/dist publishDirectory: dist @@ -649,7 +649,7 @@ importers: specifier: 16.0.3 version: 16.0.3 modelfusion: - specifier: 0.104.0 + specifier: 0.105.0 version: link:../../packages/modelfusion/dist test-environments/esm: @@ -659,7 +659,7 @@ importers: version: 16.0.3 modelfusion: specifier: 0.104.0 - version: link:../../packages/modelfusion/dist + version: 0.104.0 packages: @@ -10692,6 +10692,22 @@ packages: obliterator: 2.0.4 dev: false + /modelfusion@0.104.0: + resolution: {integrity: sha512-Qs+ZydjhTn9R0yKL/6RrNzD+tqjcB81e8UjAyXtEYPN4sNZAIVfTDzDeQPZzSH9BkBfQfuQmxIqE0v4unMlsYQ==} + engines: {node: '>=18'} + dependencies: + eventsource-parser: 1.1.1 + js-tiktoken: 1.0.7 + nanoid: 3.3.6 + secure-json-parse: 2.7.0 + ws: 8.14.2 + zod: 3.22.4 + zod-to-json-schema: 3.22.3(zod@3.22.4) + transitivePeerDependencies: + - bufferutil + - utf-8-validate + dev: false + /mri@1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} engines: {node: '>=4'} diff --git a/test-environments/commonjs/package.json b/test-environments/commonjs/package.json index 8581edd5d..78e04513e 100644 --- a/test-environments/commonjs/package.json +++ b/test-environments/commonjs/package.json @@ -6,7 +6,7 @@ "start": "node src/index.js" }, "dependencies": { - "modelfusion": "0.104.0", + "modelfusion": "0.105.0", "dotenv": "16.0.3" } }