Skip to content

Commit

Permalink
updated examples README.md, CONTRIBUTING.md, and added build:watch sc…
Browse files Browse the repository at this point in the history
…ript
  • Loading branch information
jakedetels committed Feb 12, 2024
1 parent c5e6a6c commit 020d2a4
Show file tree
Hide file tree
Showing 37 changed files with 1,898 additions and 1,874 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Feedback, bug reports and other contributions are welcome.
pnpm build
```

## Watch Mode for Local Development

When running the `pnpm install` command, pnpm will both install all dependencies within the monorepo and symlink dependant workspaces to one another (specifically symlinking the compiled output in each workspace's `dist` folder). Therefore, if you are working on a specific package (e.g., `packages/modelfusion`) and you want your changes to be reflected in the consuming package (e.g., `examples/basic`), you can run `pnpm build:watch` from the monorepo's root directory.

<!-- Links -->

[install-git]: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
Expand Down
36 changes: 19 additions & 17 deletions examples/babyagi-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ TypeScript implementation of the classic [BabyAGI](https://github.com/yoheinakaj

1. Create .env file with the following content:

```
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
```
```sh
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
```

2. Run the following commands:
2. Run the following commands from the root directory of the modelfusion repo:

```sh
pnpm install
pnpm tsx src/BabyAGI.ts --objective "Solve world hunger."
```
```sh
pnpm install
pnpm build
pnpm tsx examples/babyagi-agent/src/BabyAGI.ts --objective "Solve world hunger."
```

## BabyBeeAGI

Expand All @@ -31,14 +32,15 @@ TypeScript implementation of [BabyBeeAGI](https://github.com/yoheinakajima/babya

1. Create .env file with the following content:

```
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
SERPAPI_API_KEY="YOUR_SERPAPI_API_KEY"
```
```sh
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
SERPAPI_API_KEY="YOUR_SERPAPI_API_KEY"
```

2. Run the following commands:
2. Run the following commands from the root directory of the modelfusion repo:

```sh
pnpm install
pnpm tsx src/BabyBeeAGI.ts --objective "Research and write a short text about the BabyAGI project"
```
```sh
pnpm install
pnpm build
pnpm tsx examples/babyagi-agent/src/BabyBeeAGI.ts --objective "Research and write a short text about the BabyAGI project"
```
2 changes: 1 addition & 1 deletion examples/babyagi-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"commander": "10.0.1",
"dotenv": "16.3.1",
"jsdom": "^22.1.0",
"modelfusion": "0.136.0",
"modelfusion": "workspace:*",
"serpapi": "^2.0.0"
},
"devDependencies": {
Expand Down
28 changes: 15 additions & 13 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ Basic examples of how to the the functions in ModelFusion.

1. Create .env file with the following content (and more settings, depending on the providers you want to use):

```
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
COHERE_API_KEY="YOUR_COHERE_API_KEY"
HUGGINGFACE_API_KEY="YOUR_HUGGINGFACE_API_KEY"
...
```
```sh
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
COHERE_API_KEY="YOUR_COHERE_API_KEY"
HUGGINGFACE_API_KEY="YOUR_HUGGINGFACE_API_KEY"
...
```

2. Setup:
2. Run the following commands from the root directory of the modelfusion repo:

```sh
pnpm install
```
```sh
pnpm install
pnpm build
```

3. Run any example:
```sh
pnpm tsx src/path/to/example.ts
```

```sh
pnpm tsx examples/basic/src/path/to/example.ts
```
14 changes: 7 additions & 7 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
"license": "MIT",
"private": true,
"dependencies": {
"@modelfusion/google-custom-search-tool": "0.10.0",
"@modelfusion/mathjs-tool": "0.1.1",
"@modelfusion/pinecone": "0.4.0",
"@modelfusion/serpapi-tool": "0.11.0",
"@modelfusion/sqlite-vss": "0.4.0",
"@modelfusion/google-custom-search-tool": "workspace:*",
"@modelfusion/mathjs-tool": "workspace:*",
"@modelfusion/pinecone": "workspace:*",
"@modelfusion/serpapi-tool": "workspace:*",
"@modelfusion/sqlite-vss": "workspace:*",
"modelfusion": "workspace:*",
"modelfusion-experimental": "workspace:*",
"@pinecone-database/pinecone": "0.1.6",
"dotenv": "16.3.1",
"secure-json-parse": "2.7.0",
"modelfusion": "0.136.0",
"modelfusion-experimental": "0.7.0",
"nanoid": "3.3.6",
"better-sqlite3": "9.0.0",
"sqlite-vss": "0.1.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import dotenv from "dotenv";
import { generateTranscription, openai } from "modelfusion";
import fs from "node:fs";
import path from "node:path";

dotenv.config();

async function main() {
const transcription = await generateTranscription({
model: openai.Transcriber({ model: "whisper-1" }),
mimeType: "audio/mp3",
audioData: await fs.promises.readFile("data/test.mp3"),
audioData: await fs.promises.readFile(
path.join(__dirname, "../../data/test.mp3")
),
});

console.log(transcription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import path from "node:path";
dotenv.config();

async function main() {
const image = fs.readFileSync(path.join("data", "example-image.png"));
const image = fs.readFileSync(
path.join(__dirname, "../../data/example-image.png")
);

const textStream = await streamText({
model: openai.ChatTextGenerator({
Expand Down
6 changes: 5 additions & 1 deletion examples/basic/src/text-chunk/split-text-chunk-example.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import dotenv from "dotenv";
import { splitAtCharacter, splitTextChunk } from "modelfusion";
import fs from "node:fs";
import path from "node:path";

dotenv.config();

async function main() {
const sanFranciscoWikipediaText = JSON.parse(
fs.readFileSync("data/san-francisco-wikipedia.json", "utf8")
fs.readFileSync(
path.join(__dirname, "../../data/san-francisco-wikipedia.json"),
"utf8"
)
).content as string;

const chunks = await splitTextChunk(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { splitAtCharacter } from "modelfusion";
import fs from "node:fs";
import path from "node:path";

async function main() {
const sanFranciscoWikipediaText = JSON.parse(
fs.readFileSync("data/san-francisco-wikipedia.json", "utf8")
fs.readFileSync(
path.join(__dirname, "../../../data/san-francisco-wikipedia.json"),
"utf8"
)
).content as string;

const split = splitAtCharacter({ maxCharactersPerChunk: 1000 });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { openai, splitAtToken } from "modelfusion";
import fs from "node:fs";
import path from "node:path";

async function main() {
const sanFranciscoWikipediaText = JSON.parse(
fs.readFileSync("data/san-francisco-wikipedia.json", "utf8")
fs.readFileSync(
path.join(__dirname, "../../../data/san-francisco-wikipedia.json"),
"utf8"
)
).content as string;

const split = splitAtToken({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { splitOnSeparator } from "modelfusion";
import fs from "node:fs";
import path from "node:path";

async function main() {
const sanFranciscoWikipediaText = JSON.parse(
fs.readFileSync("data/san-francisco-wikipedia.json", "utf8")
fs.readFileSync(
path.join(__dirname, "../../../data/san-francisco-wikipedia.json"),
"utf8"
)
).content as string;

const split = splitOnSeparator({ separator: "\n" });
Expand Down
10 changes: 6 additions & 4 deletions examples/chatbot-next-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ A web chat with an AI assistant.

1. Create `.env.local` file with the following content:

```
```sh
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
```

2. Run the following commands:
2. Run the following commands from the root directory of the modelfusion repo:

```sh
npm install
npm run dev
pnpm install
pnpm build
cd examples/chatbot-next-js
pnpm dev
```

3. Go to http://localhost:3000/ in your browser
4 changes: 2 additions & 2 deletions examples/chatbot-next-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"@emotion/styled": "11.10.8",
"@mui/icons-material": "5.15.5",
"@mui/material": "5.12.2",
"modelfusion": "0.136.0",
"modelfusion-experimental": "0.7.0",
"modelfusion": "workspace:*",
"modelfusion-experimental": "workspace:*",
"next": "13.5.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
10 changes: 9 additions & 1 deletion examples/cloudflare-workers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ Generate text on a Cloudflare Worker using ModelFusion and OpenAI.
- For local environment: Add to `.dev.vars`
- For cloudflare workers: Use `pnpm wrangler secret put OPENAI_API_KEY`

1. Run
2. Run the following commands from the root directory of the modelfusion repo:

```sh
pnpm install
pnpm build
cd examples/cloudflare-workers
```

3. Run
- Local environment: `pnpm dev`
- Cloud (deployment): `pnpm deploy`
2 changes: 1 addition & 1 deletion examples/cloudflare-workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"wrangler": "^3.22.1"
},
"dependencies": {
"modelfusion": "0.136.0"
"modelfusion": "workspace:*"
}
}
10 changes: 3 additions & 7 deletions examples/middle-school-math-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ Note: GPT-4 can solve these problems without a calculator. This example is just
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
```

2. Setup:
2. Run the following commands from the root directory of the modelfusion repo:

```sh
pnpm install
```

3. Run:

```sh
pnpm tsx src/MiddleSchoolMathAgent.ts
pnpm build
pnpm tsx examples/middle-school-math-agent/src/MiddleSchoolMathAgent.ts
```
4 changes: 2 additions & 2 deletions examples/middle-school-math-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"clean": "rimraf build dist .turbo node_modules && pnpm clear"
},
"dependencies": {
"@modelfusion/mathjs-tool": "0.1.1",
"modelfusion": "0.136.0",
"@modelfusion/mathjs-tool": "workspace:*",
"modelfusion": "workspace:*",
"dotenv": "16.3.1",
"zod": "3.22.4"
},
Expand Down
6 changes: 4 additions & 2 deletions examples/nextjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ Examples of using ModelFusion with Next.js 14 (App Router):

1. Create a `.env.local` file with the following content (depending on which demo you want to run)):

```
```sh
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
STABILITY_API_KEY="YOUR_STABILITY_API_KEY"
```

2. Run the following commands:
2. Run the following commands from the root directory of the modelfusion repo:

```sh
pnpm install
pnpm build
cd examples/nextjs
pnpm dev
```

Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"lucide-react": "^0.312.0",
"modelfusion": "0.136.0",
"modelfusion-experimental": "0.7.0",
"modelfusion": "workspace:*",
"modelfusion-experimental": "workspace:*",
"next": "14.1.0",
"react": "^18",
"react-dom": "^18",
Expand Down
7 changes: 4 additions & 3 deletions examples/pdf-chat-terminal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ Ask questions about a PDF document and get answers from the document.

1. Create .env file with the following content:

```
```sh
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
```

2. Run the following commands:
2. Run the following commands from the root directory of the modelfusion repo:

```sh
pnpm install
pnpm tsx src/main.ts -f my.pdf
pnpm build
pnpm tsx examples/pdf-chat-terminal/src/main.ts -f my.pdf
```
2 changes: 1 addition & 1 deletion examples/pdf-chat-terminal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"private": true,
"dependencies": {
"modelfusion": "0.136.0",
"modelfusion": "workspace:*",
"commander": "10.0.1",
"dotenv": "16.3.1",
"pdfjs-dist": "3.6.172"
Expand Down
4 changes: 2 additions & 2 deletions examples/pdf-to-tweet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"private": true,
"dependencies": {
"modelfusion": "0.136.0",
"modelfusion-experimental": "0.7.0",
"modelfusion": "workspace:*",
"modelfusion-experimental": "workspace:*",
"commander": "10.0.1",
"dotenv": "16.3.1",
"pdfjs-dist": "3.6.172",
Expand Down
4 changes: 2 additions & 2 deletions examples/speech-streaming-vite-react-fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"clsx": "^2.0.0",
"dotenv": "16.3.1",
"fastify": "^4.23.2",
"modelfusion": "0.136.0",
"modelfusion-experimental": "0.7.0",
"modelfusion": "workspace:*",
"modelfusion-experimental": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwind-merge": "^1.14.0",
Expand Down
Loading

0 comments on commit 020d2a4

Please sign in to comment.