├── .eslintrc.json ├── .github └── workflows │ ├── ci.yml │ └── publish.yml ├── .gitignore ├── .husky ├── commit-msg └── prepare-commit-msg ├── .koumurc.toml ├── .prettierrc.json ├── README.md ├── docs └── v0.2.3 │ ├── Auth │ ├── login.md │ ├── login │ │ ├── anonymous-not-intended-for-production.md │ │ ├── custom-authentification-system.md │ │ ├── firebase.md │ │ └── login-with-providers.md │ ├── logout.md │ ├── react-stripe-subscriptions.md │ └── user.md │ ├── Client Libraries │ ├── javascript.md │ ├── react-use-polyfact.md │ └── react-use-polyfact │ │ ├── useagent-react-hook-1.md │ │ ├── usechat.md │ │ └── usepolyfire.md │ ├── Data │ ├── dataloaders.md │ ├── embeddings.md │ └── kv-store.md │ ├── Get Started │ ├── basic-usage.md │ ├── developer-console.md │ ├── introduction.md │ ├── models-list.md │ └── new-project-rate-limit.md │ ├── Models │ ├── chatgpt-clone.md │ ├── chats.md │ ├── chats │ │ ├── getmessages.md │ │ ├── new-chat.md │ │ └── sendmessage.md │ ├── generate-image.md │ ├── generate-with-types.md │ ├── generate.md │ ├── generate │ │ ├── generate-1.md │ │ ├── infos.md │ │ ├── stream.md │ │ └── web.md │ ├── other-chat-overvire.md │ ├── text-generation.md │ ├── text-to-speech.md │ └── transcribe.md │ ├── Prompt │ └── system-prompts-alias.md │ └── React Components │ ├── auto-complete-input.md │ ├── auto-complete-textarea.md │ ├── chat.md │ ├── chat │ ├── chat-1.md │ ├── prompt.md │ ├── root.md │ ├── sidebar.md │ ├── test.md │ └── usechatcontext.md │ ├── imagegenerate.md │ ├── loginui.md │ ├── payments.md │ ├── text-generated.md │ ├── text-summarize.md │ └── text-summary.md ├── examples ├── Makefile ├── chatgpt-clone │ ├── .gitignore │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ ├── src │ │ ├── App.css │ │ ├── App.test.tsx │ │ ├── App.tsx │ │ ├── ChatBox.tsx │ │ ├── index.css │ │ ├── index.tsx │ │ ├── logo.svg │ │ ├── react-app-env.d.ts │ │ ├── reportWebVitals.ts │ │ └── setupTests.ts │ ├── tailwind.config.js │ ├── tsconfig.json │ └── yarn.lock ├── hello-world-haiku │ ├── .gitignore │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ ├── src │ │ ├── App.css │ │ ├── App.test.tsx │ │ ├── App.tsx │ │ ├── index.css │ │ ├── index.tsx │ │ ├── logo.svg │ │ ├── react-app-env.d.ts │ │ ├── reportWebVitals.ts │ │ └── setupTests.ts │ ├── tailwind.config.js │ ├── tsconfig.json │ └── yarn.lock ├── polyfire-components │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ ├── src │ │ ├── App.css │ │ ├── App.test.tsx │ │ ├── App.tsx │ │ ├── components │ │ │ ├── CodeDisplay.tsx │ │ │ ├── ImageGeneratedDemo.tsx │ │ │ ├── TextGenerationDemo.tsx │ │ │ ├── TextSummaryDemo.tsx │ │ │ └── TextTranslatedDemo.tsx │ │ ├── index.css │ │ ├── index.tsx │ │ ├── logo.svg │ │ ├── react-app-env.d.ts │ │ ├── reportWebVitals.ts │ │ ├── setupTests.ts │ │ └── utils │ │ │ └── debounce.ts │ ├── tailwind.config.js │ ├── tsconfig.json │ └── yarn.lock └── transcription │ ├── .gitignore │ ├── package.json │ ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt │ ├── src │ ├── App.css │ ├── App.test.tsx │ ├── App.tsx │ ├── index.css │ ├── index.tsx │ ├── logo.svg │ ├── react-app-env.d.ts │ ├── reportWebVitals.ts │ └── setupTests.ts │ ├── tsconfig.json │ └── yarn.lock ├── lib ├── auth.ts ├── chats │ └── index.ts ├── client.ts ├── clientOpts.ts ├── components │ ├── AutoCompleteInput.tsx │ ├── AutoCompleteTextArea.tsx │ ├── ImageGenerated.tsx │ ├── Login.css │ ├── Login.tsx │ ├── Paywall.tsx │ ├── TextGenerated.tsx │ ├── TextSummary.tsx │ ├── TextTranslated.tsx │ ├── index.tsx │ └── utils.tsx ├── dataloader │ └── index.ts ├── embeddings.ts ├── generate.ts ├── helpers │ ├── error.ts │ ├── models.ts │ └── uuid.ts ├── hooks │ ├── index.ts │ ├── useAgent.ts │ ├── useBrowserSpeech.tsx │ ├── useChat.ts │ ├── usePolyfire.tsx │ └── useVoiceToText.ts ├── image.ts ├── index.ts ├── kv.ts ├── probabilistic_helpers │ └── generateWithType.ts ├── split.ts ├── transcribe.ts ├── tts.ts ├── user.ts └── utils.ts ├── package.json ├── target └── vanilla-js.ts ├── tests ├── auth.test.js └── generation.test.js ├── tsconfig.json └── yarn.lock /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "commonjs": false, 4 | "node": true, 5 | "es6": true, 6 | "jest": true 7 | }, 8 | "plugins": ["eslint-plugin-tsdoc"], 9 | "extends": [ 10 | "airbnb-base", 11 | "eslint:recommended", 12 | 13 | "plugin:@typescript-eslint/eslint-recommended", 14 | "plugin:@typescript-eslint/recommended", 15 | 16 | "prettier" 17 | ], 18 | 19 | "ignorePatterns": ["examples/**/*"], 20 | "parser": "@typescript-eslint/parser", 21 | "parserOptions": { 22 | "ecmaVersion": 2020, 23 | "sourceType": "module", 24 | "project": "./tsconfig.json" 25 | }, 26 | "globals": { 27 | "fetch": true 28 | }, 29 | "rules": { 30 | "@typescript-eslint/explicit-module-boundary-types": ["warn"], 31 | "@typescript-eslint/ban-types": ["warn"], 32 | "@typescript-eslint/no-unused-vars": [ 33 | "warn", 34 | { 35 | "varsIgnorePattern": "^_.*", 36 | "argsIgnorePattern": "^_.*" 37 | } 38 | ], 39 | "@typescript-eslint/no-empty-function": ["warn"], 40 | "import/no-extraneous-dependencies": [ 41 | "error", 42 | { "devDependencies": true, "optionalDependencies": true, "peerDependencies": true } 43 | ], 44 | 45 | "import/no-unresolved": "off", 46 | "import/prefer-default-export": "off", 47 | "import/extensions": "off", 48 | "no-else-return": "off", 49 | "lines-around-directive": "off", 50 | 51 | "no-unused-vars": "off", 52 | "no-restricted-imports": [ 53 | "off", 54 | { 55 | "patterns": ["../*", "./*"] 56 | } 57 | ], 58 | "no-case-declarations": "off", 59 | "no-underscore-dangle": ["off"], 60 | "class-methods-use-this": ["off"], 61 | "linebreak-style": ["error", "unix"], 62 | "camelcase": ["error"], 63 | "require-jsdoc": ["off"], 64 | "no-invalid-this": ["off"], 65 | "arrow-body-style": ["off"], 66 | "no-shadow": ["off"], 67 | "no-return-await": ["off"], 68 | "prefer-promise-reject-errors": ["off"], 69 | "no-param-reassign": ["off"], 70 | "no-useless-return": ["off"], 71 | "no-use-before-define": "off", 72 | "@typescript-eslint/no-use-before-define": ["error"], 73 | "no-undef": ["error"], 74 | "no-plusplus": ["off"], 75 | "radix": ["off"], 76 | "eslinttguard-for-in": ["off"], 77 | "no-restricted-syntax": ["off"], 78 | "no-alert": ["off"], 79 | "guard-for-in": ["off"], 80 | "max-classes-per-file": ["off"], 81 | "no-await-in-loop": ["off"], 82 | "no-continue": ["off"], 83 | "no-console": ["off"], 84 | "tsdoc/syntax": "warn", 85 | "@typescript-eslint/no-empty-function": ["off"] 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - master 6 | - main 7 | pull_request: 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | eslint: 14 | name: Lint 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Install modules 19 | run: yarn 20 | - name: Run ESLint 21 | run: yarn lint --max-warnings 0 22 | build-examples: 23 | name: Build examples 24 | runs-on: ubuntu-latest 25 | steps: 26 | - uses: actions/checkout@v2 27 | - name: Build Examples 28 | working-directory: ./examples 29 | run: make examples 30 | test: 31 | name: Run tests 32 | runs-on: ubuntu-latest 33 | steps: 34 | - uses: actions/checkout@v2 35 | - name: Install modules 36 | run: yarn 37 | - name: Build library 38 | run: yarn build 39 | - name: Run tests 40 | run: yarn test 41 | env: 42 | CUSTOM_PROJECT_ID: ${{ secrets.CUSTOM_PROJECT_ID }} 43 | CUSTOM_PROJECT_TOKEN: ${{ secrets.CUSTOM_PROJECT_TOKEN }} 44 | ENDPOINT: ${{ secrets.ENDPOINT }} 45 | ANONYMOUS_PROJECT_ID: ${{ secrets.ANONYMOUS_PROJECT_ID }} 46 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to npm 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | workflow_run: 8 | workflows: [CI] 9 | types: [completed] 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: Check out repository 17 | uses: actions/checkout@v2 18 | 19 | - name: Use Node.js 20 | uses: actions/setup-node@v2 21 | with: 22 | node-version: "19" 23 | registry-url: "https://registry.npmjs.org" 24 | 25 | - name: Install dependencies using Yarn 26 | run: yarn install 27 | 28 | - name: Publish to npm 29 | run: npm run npm-publish 30 | env: 31 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 32 | 33 | - name: Build Vanilla JS 34 | run: npm run build:vanilla-js 35 | 36 | - name: Parse the package.json for the version 37 | run: | 38 | echo 'PACKAGE_JSON<> $GITHUB_ENV 39 | cat ./package.json >> $GITHUB_ENV 40 | echo 'EOF' >> $GITHUB_ENV 41 | 42 | - name: Create Release 43 | id: create_release 44 | uses: actions/create-release@v1 45 | env: 46 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 47 | with: 48 | tag_name: ${{ fromJson(env.PACKAGE_JSON).version }} 49 | release_name: Release ${{ fromJson(env.PACKAGE_JSON).version }} 50 | draft: false 51 | prerelease: false 52 | 53 | - name: Upload Release Asset 54 | id: upload-release-asset 55 | uses: actions/upload-release-asset@v1 56 | env: 57 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 58 | with: 59 | upload_url: ${{ steps.create_release.outputs.upload_url }} 60 | asset_path: ./build/vanilla-js.js 61 | asset_name: 'polyfire-min-${{ fromJson(env.PACKAGE_JSON).version }}.js' 62 | asset_content_type: application/javascript 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | package-lock.json 3 | bun.lockb 4 | yarn-error.log 5 | build/ 6 | dist/ 7 | -------------------------------------------------------------------------------- /.koumurc.toml: -------------------------------------------------------------------------------- 1 | mergeKind = ":twisted_rightwards_arrows:" 2 | 3 | maxCommitLength = 72 4 | 5 | [scopes] 6 | models = "Related to the models (LLMs, ImageGen, TTS, etc...)" 7 | auth = "Related to user authentification" 8 | data = "Related to the data sent to the models (Embeddings, loaders, etc...)" 9 | "react/hooks" = "Related to the react hooks" 10 | "react/components" = "Related to the react components" 11 | examples = "Related to the provided examples" 12 | tests = "Related to the tests" 13 | docs = "Documentation" 14 | meta = "Anything about the project / cross scopes" 15 | 16 | [kinds] 17 | ":sparkles:" = "implement a new feature" 18 | ":zap:" = "update existing feature" 19 | 20 | ":recycle:" = "refactor code" 21 | ":racehorse:" = "improve performance" 22 | ":wastebasket:" = "deprecate code that needs to be cleaned up" 23 | 24 | ":bug:" = "fix a bug" 25 | ":rotating_light:" = "critical hotfix" 26 | ":warning:" = "fix compiler / linter warnings" 27 | 28 | ":books:" = "add or update documentation" 29 | ":bulb:" = "add or update comments in source code" 30 | ":loud_sound:" = "add or update logs" 31 | ":mute:" = "remove logs" 32 | 33 | ":floppy_disk:" = "update ressources" 34 | 35 | ":file_cabinet:" = "perform database related changes" 36 | 37 | ":white_check_mark:" = "add, update, or pass tests" 38 | 39 | ":triangular_flag_on_post:" = "add, update, or remove feature flags" 40 | ":chart_with_upwards_trend:" = "add or update analytics or track code" 41 | 42 | ":speech_balloon:" = "add or update text and literals" 43 | 44 | ":rewind:" = "revert changes" 45 | ":twisted_rightwards_arrows:" = "merge branches" 46 | 47 | ":bookmark:" = "prepare a new release version" 48 | ":package:" = "update dependencies" 49 | ":wrench:" = "update dev workspace" 50 | 51 | ":beers:" = "write code drunkenly" 52 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": false, 3 | "trailingComma": "all", 4 | "semi": true, 5 | "printWidth": 100, 6 | "tabWidth": 4 7 | } 8 | -------------------------------------------------------------------------------- /docs/v0.2.3/Auth/login.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "login" 3 | slug: "login" 4 | excerpt: "Login users with Polyfire Auth" 5 | hidden: false 6 | createdAt: "Wed Sep 27 2023 07:29:51 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:33:49 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | > 📘 Auth is required 10 | > 11 | > All the components and functions in the SDK require you to connect your users to Polyfire Auth. 12 | > 13 | > Because all calls to the Polyfire API use LLMs (and therefore cost money) or access user data, the client needs some kind of secured authentification. 14 | > 15 | > You don't need to authenticate your users entirely through Polyfire (e.g. we can authenticate your Firebase or Supabase user tokens). If you need a custom auth provider integrated, [tell us on Discord](https://discord.polyfire.com). 16 | 17 | Login users client-side to create unique user sessions. 18 | 19 | - Works with providers "Google" and "GitHub" but also "Firebase" (see below). 20 | - Must be called to use _models_ and _data_ modules client-side. 21 | 22 | ```typescript 23 | export declare function login(input: LoginFunctionInput, projectOptions: { 24 | project: string; 25 | endpoint: string; 26 | }): Promise; 27 | ``` 28 | 29 | ## Types 30 | 31 | ```typescript 32 | type SimpleProvider = "github" | "google"; 33 | type LoginWithFirebaseInput = { 34 | token: string; 35 | provider: "firebase"; 36 | }; 37 | type LoginFunctionInput = SimpleProvider | { 38 | provider: SimpleProvider; 39 | } | LoginWithFirebaseInput; 40 | ``` 41 | -------------------------------------------------------------------------------- /docs/v0.2.3/Auth/login/anonymous-not-intended-for-production.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Anonymous (Not intended for Production)" 3 | slug: "anonymous-not-intended-for-production" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Mon Oct 16 2023 12:05:20 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:33:49 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | To simplify your onboarding with polyfire, we added an "anonymous" login method. 10 | 11 | It must first be activated in the dashboard in your project settings. 12 | 13 | **After that, logging in should be automatic.** 14 | 15 | You can also try to call it manually (after a logout for example) with: 16 | 17 | ```js Javascript 18 | login({ provider: "anonymous" }); 19 | ``` 20 | 21 | If you want to simulate multiple users, the login function also provides you with the ability to add an email to differentiate them like this: 22 | 23 | ```js Javascript 24 | login({ provider: "anonymous", email: "user@example.com" }); 25 | ``` 26 | -------------------------------------------------------------------------------- /docs/v0.2.3/Auth/login/custom-authentification-system.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Custom Authentification System" 3 | slug: "custom-authentification-system" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Mon Oct 16 2023 11:41:24 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:33:49 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | If you are already using a custom authentification system and want to link Polyfire to your authentification system, you can use the "custom" provider. 10 | 11 | You will need to sign a Json Web Token using the RSA/RS256 algorithm and input your public key in the PEM format in the dashboard in the "Custom Auth Public Key" field of your project's settings. 12 | 13 | Your JWT must contains these fields: 14 | 15 | - `iss`: Your project alias 16 | - `aud`: must be:`polyfire_custom_auth_api` 17 | - `sub`: The id of the user you want to identify. It can be any string as long as it is unique to the user. 18 | 19 | For example. Assuming the public key is already added in the dashboard "Custom Auth Public Key" field, somewhere in server-side code: 20 | 21 | ```js Javascript 22 | 23 | const token = jwt.sign( 24 | { 25 | iss: projectAlias, 26 | aud: "polyfire_custom_auth_api", // Don't change this string 27 | sub: userID, 28 | }, 29 | privateKey, // Leaking this key would allow to connect as any user. Make sure it's never sent client-side. 30 | { algorithm: "RS256" } 31 | ); 32 | ``` 33 | 34 | The generated token can then be used client-side in the login function like this: 35 | 36 | ```js Javascript 37 | login({ provider: "custom", token: theTokenGeneratedBefore }) 38 | ``` 39 | -------------------------------------------------------------------------------- /docs/v0.2.3/Auth/login/firebase.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Firebase" 3 | slug: "firebase" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Mon Oct 16 2023 11:40:36 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:33:49 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | ## Add your Firebase Project ID to your project 10 | 11 | Before being able to use firebase as a login method you first need to link your Firebase project to your polyfire project. 12 | 13 | You can find your Firebase Project ID in your project settings in the firebase console . Choose your project, click on the gear icon in the top left corner and click on "Project Settings". Your Project ID will be displayed among other infos. 14 | 15 | To link it to your Polyfire project, go on and choose your project. When you are in the project detail page, click on the Edit button and add your Firebase Project ID before saving. 16 | 17 | ## Setup the Firebase login 18 | 19 | If you didn't do it already, follow this tutorial to setup the login with firebase: 20 | 21 | ## Link your Firebase User Session to Polyfire 22 | 23 | You can set the provider to firebase and send a firebase token to the login function parameter. To get a firebase token, you can use the `getIdToken()` method of the firebase user object. 24 | 25 | For example: 26 | 27 | ```js Javascript 28 | const userCredentials = await signInWithEmailAndPassword( 29 | auth, 30 | "john.doe@example.com", 31 | "correct_horse_battery_staple" 32 | ); 33 | 34 | const user = userCredentials.user; 35 | 36 | const firebaseToken = await user.getIdToken(); 37 | 38 | const polyfire = PolyfireClientBuilder({ project: "your_project_alias" }) 39 | await polyfire.auth.login({ provider: "firebase", token: firebaseToken }) 40 | 41 | // You can now use the Polyfire Client: 42 | const helloWorldHaiku = await polyfire.generate("Write me a hello world haiku"); 43 | 44 | console.log(helloWorldHaiku); 45 | ``` 46 | 47 | > 📘 With the usePolyfire React Hook 48 | > 49 | > Using the usePolyfire React Hook it would work the same except that you would be importing the _auth_ module from usePolyfire instead of creating a client object like higher up. 50 | -------------------------------------------------------------------------------- /docs/v0.2.3/Auth/login/login-with-providers.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "OAuth Providers" 3 | slug: "login-with-providers" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Wed Sep 27 2023 07:17:47 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:41:44 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | For Polyfire to work client-side, **you need to setup unique user sessions**. That way, each user of your app will have a custom, rate-limited, API token and can use your app according to the restrictions you give them. 10 | 11 | To do that you can use our login functions, from the _auth_ module. 12 | 13 | ```jsx 14 | import React from 'react'; 15 | import { usePolyfire } from 'polyfire-js/hooks'; 16 | 17 | function App() { 18 | const { auth } = usePolyfire(); 19 | const { login, status } = auth; 20 | 21 | if (status == 'loading') { 22 | return ( 23 |
Loading...
24 | ) 25 | } else if (status == 'authenticated') { 26 | return ( 27 |
We already logged in!
28 | ) 29 | } else if (status == 'unauthenticated') { 30 | return ( 31 | 32 | ) 33 | } else { 34 | return
35 | } 36 | } 37 | 38 | export default App; 39 | ``` 40 | 41 | # Linking pre-existing auth system 42 | 43 | If you have Firebase Auth setup. Pass in your JWT as shown [in that tutorial](doc:signin-firebase). If you want integrations to other auth providers:[message us on our Discord](https://www.polyfire.com/discord). 44 | 45 | You can also connect your own auth system [by doing a custom auth.](doc:custom-authentification-system) 46 | 47 | # Providers Available 48 | 49 | The sign in providers available are GitHub, Google, Microsoft (Azure) and Firebase (passing your Firebase JWT). 50 | 51 | [Reach out on Discord if you want more.](discord.polyfire.com) 52 | -------------------------------------------------------------------------------- /docs/v0.2.3/Auth/logout.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "logout" 3 | slug: "logout" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Wed Sep 27 2023 07:32:37 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:33:48 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | Ends user session and cleans cache. 10 | 11 | - Doesn't return anything. 12 | - Will require user to re-authenticate user to use API modules. (models, data, etc). 13 | 14 | ```typescript 15 | export declare function logout(): Promise; 16 | ``` 17 | -------------------------------------------------------------------------------- /docs/v0.2.3/Auth/user.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "user" 3 | slug: "user" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Wed Sep 27 2023 07:39:48 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:33:49 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | User object with Auth and Token IDs. 10 | 11 | - Give you access to a unique userID 12 | - Useful to mesure rateLimit and user's usage if you want to trigger a paywall / payment flow. 13 | 14 | ```typescript 15 | export type UserClient = { 16 | usage: () => Promise<{ 17 | usage: number; 18 | rateLimit?: number; 19 | }>; 20 | getAuthID: () => Promise; 21 | getToken: () => Promise; 22 | }; 23 | ``` 24 | -------------------------------------------------------------------------------- /docs/v0.2.3/Client Libraries/javascript.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Javascript" 3 | slug: "javascript" 4 | excerpt: "" 5 | hidden: false 6 | metadata: 7 | image: [] 8 | robots: "index" 9 | createdAt: "Tue Sep 12 2023 08:49:03 GMT+0000 (Coordinated Universal Time)" 10 | updatedAt: "Fri Nov 03 2023 01:23:26 GMT+0000 (Coordinated Universal Time)" 11 | --- 12 | > **_NOTE:_** 13 | > 14 | > _If you're using React, we recommend to use the [usePolyfire hook](doc:usepolyfire)_ 15 | 16 | ## With NPM 17 | 18 | First install the Polyfire SDK: 19 | 20 | ```Text Bash 21 | npm install polyfire-js 22 | ``` 23 | 24 | Import the `PolyfireClientBuilder` object 25 | 26 | ```javascript 27 | import PolyfireClientBuilder from "polyfire-js"; 28 | ``` 29 | 30 | ## Without NPM 31 | 32 | You can initialize Polyfire by importing the browser minified script: 33 | 34 | ```html 35 | 36 | ``` 37 | 38 | The `PolyfireClientBuilder` object is added as a global variable in the window object 39 | 40 | ## Using the _polyfire_ Object 41 | 42 | You can check if the user is already connected by using the `polyfire.auth.init()` function 43 | 44 | If they aren't we'll have to use the `polyfire.auth.login(provider: string)` method to connect them first 45 | 46 | ```js Javascript 47 | const polyfire = PolyfireClientBuilder({ project: "your_project_alias" }) 48 | 49 | const isAuthenticated = await polyfire.auth.init(); 50 | if (!isAuthenticated) { 51 | await polyfire.auth.login("github") 52 | } 53 | 54 | const helloWorld = await polyfire.models.generate("Write me a hello world haiku"); 55 | console.log(helloWorld); 56 | ``` 57 | -------------------------------------------------------------------------------- /docs/v0.2.3/Client Libraries/react-use-polyfact.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "React" 3 | slug: "react-use-polyfact" 4 | excerpt: "" 5 | hidden: false 6 | metadata: 7 | image: [] 8 | robots: "index" 9 | createdAt: "Mon Sep 11 2023 09:04:43 GMT+0000 (Coordinated Universal Time)" 10 | updatedAt: "Wed Oct 18 2023 20:57:45 GMT+0000 (Coordinated Universal Time)" 11 | --- 12 | -------------------------------------------------------------------------------- /docs/v0.2.3/Client Libraries/react-use-polyfact/usechat.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "useChat" 3 | slug: "usechat" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Tue Sep 12 2023 08:28:54 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Dec 29 2023 15:03:38 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | ## Importing the Hook 10 | 11 | ```js Javascript 12 | import { useChat } from "polyfire-js/hooks"; 13 | ``` 14 | 15 | ## Using the useChat hook 16 | 17 | ```ts Typescript 18 | function useChat(): ChatInstance 19 | ``` 20 | 21 | `useChat` doesn't take any parameter returns a `ChatInstance` object containing all the necessary informations and functions to interact with the chat as defined below: 22 | 23 | ```ts Typescript 24 | type Message = { 25 | id: string | null; // The current question/answer will be null. An id will be set to it at the end of the generation 26 | chat_id: string; 27 | is_user_message: boolean; 28 | content: string; 29 | created_at: string | null; // The current question/answer will be null. The date will be set at the end of the generation 30 | } 31 | 32 | type ChatInfos = { 33 | created_at: string; 34 | id: string; 35 | latest_message_content: string; 36 | latest_message_created_at: string; 37 | name: string | null; 38 | system_prompt: string | null; 39 | system_prompt_id: string | null; 40 | user_id: string; 41 | } 42 | 43 | type ChatBase = { 44 | data: T | undefined; 45 | error: string | undefined; 46 | loading: boolean; 47 | } 48 | 49 | type Chats = ChatBase 50 | type ChatHistory = ChatBase 51 | type ChatAnswer = ChatBase 52 | 53 | type ChatUtils = { 54 | deleteChat: (chatId: string) => Promise; 55 | renameChat: (chatId: string, name: string) => Promise; 56 | resetChat: () => void; 57 | selectChat: (chatId: string) => Promise; 58 | sendMessage: (message: string) => Promise; 59 | }; 60 | 61 | type ChatInstance = { 62 | answer: ChatAnswer; 63 | chat: ChatInfos | undefined; 64 | chats: Chats; 65 | history: ChatHistory; 66 | utils: ChatUtils; 67 | } 68 | ``` 69 | 70 | To send a new message, use the `sendMessage` function. 71 | 72 | ```ts Typescript 73 | function sendMessage(message: string): void; 74 | ``` 75 | 76 | The message will be added to messages and the answer from the LLM will be updated token by token until the answer have been fully generated. 77 | 78 | During the generation, loading will be set to `true`, allowing you to disable the send button. 79 | 80 | `answer.loading` is also set to true during the usePolyfire initialization. 81 | 82 | > :warning: **Using sendMessage when answer.loading is true will throw an error** 83 | 84 | ## Example Usage 85 | 86 | The [How to make a clone of ChatGPT](doc:chatgpt-clone) app could be simplified with this hook: 87 | 88 | ```js Javascript 89 | function App() { 90 | const { 91 | auth: { login, status }, 92 | } = usePolyfire(); 93 | const { 94 | history: { data: messages }, 95 | utils: { onSendMessage: sendMessage }, 96 | answer: { loading }, 97 | } = useChat(); 98 | 99 | return ( 100 | <> 101 | {status === "unauthenticated" ? ( 102 |
103 |

104 | Don't forget to change the project slug in src/index.tsx 105 |

106 |

107 | After that you will be able to{" "} 108 | 114 |

115 |
116 | ) : status === "authenticated" ? ( 117 | 122 | ) : ( 123 | "Loading..." 124 | )} 125 | 126 | ); 127 | } 128 | ``` 129 | -------------------------------------------------------------------------------- /docs/v0.2.3/Client Libraries/react-use-polyfact/usepolyfire.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "usePolyfire" 3 | slug: "usepolyfire" 4 | excerpt: "Polyfire provides a hook to simplify the login process of your users in React." 5 | hidden: false 6 | createdAt: "Tue Sep 12 2023 08:46:37 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Mon Nov 27 2023 06:34:25 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | > **_NOTE:_** 10 | > 11 | > _The usePolyfire hook is a React Hook_ 12 | > 13 | > _If you're not using React, please follow this page instead: [Importing polyfire](doc:javascript)_ 14 | 15 | ## Importing Polyfire 16 | 17 | First install the Polyfire SDK: 18 | 19 | ```bash Bash 20 | npm install polyfire-js 21 | ``` 22 | 23 | ## Usage 24 | 25 | ### PolyfireProvider 26 | 27 | You will need to wrap your app in the Polyfire Provider to be able to use the usePolyfire hook. Pass your project id to the PolyfireProvider 28 | 29 | ```jsx Javascript 30 | root.render( 31 | 32 | 33 | 34 | ); 35 | ``` 36 | 37 | ### Hook: usePolyfire 38 | 39 | The usePolyfire hook exports a client with all the Polyfire functions, to use most of them you will first need to login. The authentification functions are exported like this: 40 | 41 | ```js Javascript 42 | const { auth: { login, logout, status }, models: { generate } } = usePolyfire(); 43 | ``` 44 | 45 | All of the functions except the login function requires the user to be authenticated before calling them. You can check whether you're authenticated with `status`. `status` can be `authenticated`, `unauthenticated` and `loading`. 46 | 47 | ```js Javascript 48 | if (status === "authenticated") { 49 | const haiku = await generate("Generate a hello world haiku"); 50 | console.log(haiku); 51 | } 52 | ``` 53 | 54 | The login function takes the login provider as a parameter. 55 | 56 | ```jsx Javascript 57 | 58 | ``` 59 | 60 | **WARNING: For now, the only login provider available are GitHub, Google [and Firebase](doc:signin-firebase), we will add more in the future** 61 | 62 | To logout, use the logout function 63 | 64 | ```jsx Javascript 65 | 66 | ``` 67 | -------------------------------------------------------------------------------- /docs/v0.2.3/Data/dataloaders.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "DataLoaders" 3 | slug: "dataloaders" 4 | excerpt: "" 5 | hidden: false 6 | metadata: 7 | image: [] 8 | robots: "index" 9 | createdAt: "Tue Sep 12 2023 08:33:18 GMT+0000 (Coordinated Universal Time)" 10 | updatedAt: "Mon Nov 06 2023 10:35:43 GMT+0000 (Coordinated Universal Time)" 11 | --- 12 | Data Loaders are designed to make it easy to send context to a LLM. 13 | 14 | The Data Loaders are built on top of memories, this means the Key Points of the [Embeddings](ref:embeddings) feature also applies to it. _TLDR; it's not made for summarizing documents, it's best use is for search._ 15 | 16 | ## Using dataloaders 17 | 18 | You can send your dataloaders in the `data` field of the generationOption. 19 | 20 | For example, here's how you would use the `AudioLoader` dataloader: 21 | 22 | ```js Javascript 23 | import { AudioLoader } from "polyfire-js"; 24 | 25 | // In React: 26 | const { models: { generate } } = usePolyfire(); 27 | // In other environments: 28 | const { models: { generate } } = polyfire; 29 | 30 | const audioStream = await fetch("https://storage.googleapis.com/polyfact-docs-storage/secret.mp3"); 31 | 32 | if (audioStream?.body) { 33 | const answer = await generate("What is the secret ?", { 34 | data: AudioLoader(audioStream.body), 35 | }); 36 | 37 | console.log(answer); // It should give you something like "The secret is banana42" 38 | } 39 | ``` 40 | 41 | We already expose 3 simple dataloaders `AudioLoader`, `TextFileLoader` and `StringLoader`: 42 | 43 | ```ts Typescript 44 | // TextFileLoader is used to load content from a raw text file (Buffer or Stream) 45 | function TextFileLoader(file: FileInput, maxTokenPerChunk = 100): Loader; 46 | 47 | // AudioLoader is used to load content from an audio file (Buffer or Stream, the formats are the ones supported by transcribe) 48 | function AudioLoader(file: FileInput, maxTokenPerChunk = 100): Loader; 49 | 50 | // StringLoader is used to load content directly from a string 51 | function StringLoader(str: string, maxTokenPerChunk = 100): Loader; 52 | ``` 53 | 54 | ## Implementing a new dataloader 55 | 56 | Under the hood, a dataloader is a function that takes a embedding collection and loads some data to it. 57 | 58 | The dataloader must be of the type LoaderFunction. 59 | 60 | ```ts Typescript 61 | type LoaderFunction = (embeddings: Embeddings, clientOptions: InputClientOptions) => Promise; 62 | ``` 63 | 64 | But we in most cases we can use the StringLoader to implement your own dataLoader without having to manage the Embeddings and chunking of the data ourselves. 65 | 66 | For example, let's imagine we want to implement a dataloader that just takes an URL and load the raw html content of the page to the context: 67 | 68 | ```js Typescript 69 | function URLLoader(url: string, maxTokenPerChunk = 100): LoaderFunction { 70 | return async function loadURLContentIntoMemory(...args) { 71 | const response = await fetch(url); 72 | const content = await response.text(); 73 | 74 | await StringLoader(content, maxTokenPerChunk)(...args); 75 | }; 76 | } 77 | ``` 78 | 79 | We can now use our URLLoader by sending it to the generate function: 80 | 81 | ```js Javascript 82 | const answer = await generate("your_question", { 83 | data: URLLoader("your_url_with_infos_about_your_subject") 84 | }); 85 | ``` 86 | 87 | > **NOTE:** 88 | > 89 | > This naive implementation of URLLoader might not be optimal, especially on modern websites since it takes the raw html, there's a lot of noise. A better implementation would use . 90 | > 91 | > Note that we already have a special option to allow to search the web for more context. See [Web](ref:web) 92 | -------------------------------------------------------------------------------- /docs/v0.2.3/Data/embeddings.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Embeddings" 3 | slug: "embeddings" 4 | excerpt: "The embeddings are a simple way to create a long term memory and simplify the use of extracted information." 5 | hidden: false 6 | createdAt: "Mon Sep 11 2023 08:57:33 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Mon Mar 04 2024 07:11:34 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | # Overview 10 | 11 | 1. Embeddings are a **data format using vectors** to store information in a way that can be **searched based on its semantic meaning** 12 | 2. Calling the `Embeddings()` class creates a **vector index** you can add data to 13 | 3. Large inputs are **automatically split up** in chunks of about 512 tokens and added to the index 14 | 4. When **calling a LLM** with the embeddings index ID, **Polyfire automatically queries the most similar data** in your index and inject it in the LLM call as context 15 | 16 | # Simple example 17 | 18 | ```javascript 19 | // In React 20 | const { data: { Embeddings } } = usePolyfire(); 21 | // In other environments: 22 | const { data: { Embeddings } } = polyfire; 23 | 24 | const index = Embeddings(); 25 | indexId = index.getId() 26 | embeddings.add("The secret word is: banana42"); 27 | const secret = await polyfire.generate("What's the secret?", { embeddingsId: indexId }); 28 | console.log(secret); // Outputs: The secret word is "banana42". 29 | ``` 30 | 31 | # Embeddings() class 32 | 33 | ## Class prototype 34 | 35 | ```typescript 36 | type EmbeddingsOptions = { 37 | id?: string, // This cannot be set at the same time as public since it gets an existing embedding index instead of creating a new one. 38 | public?: boolean, // Whether the content of your new embedding index should be accessible accross your project or restricted to a single user. Default is false. 39 | } | string; 40 | 41 | function Embeddings(options?: EmbeddingsOptions): embeddings; 42 | async function embeddings.getId(): Promise; 43 | async function embeddings.add(input: string): Promise; 44 | async function embeddings.search(input: string): Promise<{ content: string, similarity: number }[]> 45 | ``` 46 | 47 | ## New index 48 | 49 | To create a new index, import the `Embedding` class from the `data` Polyfire module and instantiate it 50 | 51 | ```typescript 52 | import { data } = polyfireClient; 53 | const { Embeddings } = data; 54 | 55 | const index = Embeddings() 56 | ``` 57 | 58 | ## Index ID 59 | 60 | To get the ID of an embeddings index, call the `getId()` function 61 | 62 | ```javascript 63 | const id = await index.getId(); 64 | console.log(id); // Outputs the ID of the embedding index 65 | ``` 66 | 67 | ## Retrieve an index 68 | 69 | Pass an embeddings ID in options to retrieve previously created indexes 70 | 71 | ```javascript 72 | const existingIndex = Embeddings("yourEmbeddingsIndexId"); 73 | // or 74 | const existingIndex = Embeddings({ id: "yourEmbeddingsIndexId" }); 75 | ``` 76 | 77 | ## Add data 78 | 79 | You can add new data to your embeddings using the `add` method 80 | 81 | ```javascript 82 | index.add("My house is yellow"); 83 | ``` 84 | 85 | ## Search index 86 | 87 | The `search()` function looks for semantically similar data in an embeddings index 88 | 89 | ```javascript 90 | const [{ content }] = await index.search("My house is pink"); 91 | 92 | console.log(content); // My house is yellow 93 | ``` 94 | 95 | # getAllEmbeddings() 96 | 97 | This function returns all the embedding indexes that have been created. 98 | -------------------------------------------------------------------------------- /docs/v0.2.3/Data/kv-store.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "KV Store" 3 | slug: "kv-store" 4 | excerpt: "" 5 | hidden: false 6 | metadata: 7 | image: [] 8 | robots: "index" 9 | createdAt: "Tue Sep 12 2023 08:31:14 GMT+0000 (Coordinated Universal Time)" 10 | updatedAt: "Wed Oct 18 2023 20:57:45 GMT+0000 (Coordinated Universal Time)" 11 | --- 12 | Polyfire exposes a simple persistent key value store for each user of each project. 13 | 14 | _NOTE: The kv store only stores string. If you want to store something more complex, you can use JSON.stringify_ 15 | 16 | ## 💡 Example 17 | 18 | To set a value: 19 | 20 | ```js Javascript 21 | // In React: 22 | const { data: { kv } } = usePolyfire(); 23 | // In other environments: 24 | const { data: { kv } } = polyfire; 25 | 26 | await kv.set("my_key", "my_value"); 27 | ``` 28 | 29 | The value can later be retieved with kv.get: 30 | 31 | ```js Javascript 32 | console.log(await kv.get("my_key")); // Should print "my_value" 33 | ``` 34 | -------------------------------------------------------------------------------- /docs/v0.2.3/Get Started/developer-console.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Developer Console" 3 | slug: "developer-console" 4 | excerpt: "The Developer Console is a key element of the Polyfire Backend API. It where you can see visually all the elements of your managed backend, including the various model usages, projects, billing, data and all the other metrics and variables you use through the API." 5 | hidden: false 6 | metadata: 7 | image: [] 8 | robots: "index" 9 | createdAt: "Tue Sep 26 2023 01:46:41 GMT+0000 (Coordinated Universal Time)" 10 | updatedAt: "Fri Nov 03 2023 02:27:45 GMT+0000 (Coordinated Universal Time)" 11 | --- 12 | # Overview of the Developer Console 13 | 14 | The Polyfire Developer Console is at [beta.polyfire.com](https://beta.polyfire.com.) Most of the things you can do from the Console can also be done using the API, but the visual interface is much more enjoyable to keep track of you project, users, data and other API metrics. 15 | 16 | The Dev Console is broken down in a few sections: 17 | 18 | 1. **Home**: where you can init your project and access your configuration variables. 19 | 2. **Auth**: where you can see the list of your users and define parameters like rate limits or payments. 20 | 3. **Models**: where you can consult the list of models we support and see logs of their usage. 21 | 4. **Data**: where you can see the embeddings you have created and stored, your key-value database and the variation data integrations of your app. 22 | 5. **Prompts**: where you can see the various prompts you have saved and are using in your app. 23 | 24 | # Create an account 25 | 26 | To create a Developer Account, simply go to the [Developer Console](https://beta.polyfire.com) and Sign Up With Github. 27 | -------------------------------------------------------------------------------- /docs/v0.2.3/Get Started/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introduction" 3 | slug: "introduction" 4 | excerpt: "⚡ A managed backend for AI apps. Call AI models from the frontend 🪶" 5 | hidden: false 6 | metadata: 7 | image: [] 8 | robots: "index" 9 | createdAt: "Mon Sep 11 2023 08:37:03 GMT+0000 (Coordinated Universal Time)" 10 | updatedAt: "Fri Nov 03 2023 02:26:18 GMT+0000 (Coordinated Universal Time)" 11 | --- 12 | Polyfire's goal is to make it possible to code every AI tool/Chatbot you could want in only a couple of lines of code in the frontend without the need for complex abstractions and having to deploy anything. 13 | 14 | [block:image] 15 | { 16 | "images": [ 17 | { 18 | "image": [ 19 | "https://files.readme.io/7442014-demo.gif", 20 | "", 21 | "" 22 | ], 23 | "align": "center" 24 | } 25 | ] 26 | } 27 | [/block] 28 | 29 | 30 | ## :new: Getting Started 31 | 32 | To get an overview of Polyfire follow this **[Basic Usage](doc:basic-usage)** tutorial. 33 | 34 | ## ✨ Starter Guides 35 | 36 | We also made a couple of tutorials you can use to get started with Polyfire: 37 | 38 | - **[How to make a clone of ChatGPT](doc:chatgpt-clone)** 39 | - **[New Project](doc:new-project-rate-limit)** 40 | - **[Adding stripe subscriptions](doc:react-stripe-subscriptions)** 41 | - **[Call Polyfire from React](doc:usepolyfire)**: The usePolyfire hooks lets you use Polyfire and handle authentification without having to deploy any backend 42 | - **[Call Polyfire from other browser environments](doc:javascript)**: The Polyfire Client Object allows you to use Polyfire and handle authentification without having to deploy any backend in any environment 43 | 44 | ## 📚 Useful References 45 | 46 | - **[Generate Simple Text](ref:generate)**: Answer to simple requests as text 47 | - **[Create Chatbots](ref:chats)**: Easily create chatbots 48 | - **[Transcribe](ref:transcribe)**: Transcribe audio files to text 49 | - **[Memory](ref:embeddings)**: Easily create a long-term memory and simplify the use of large amounts of information 50 | - **[GenerateImage](ref:generate-image)**: Generate images with Dall-E 51 | 52 | ## 📫 Contact us 53 | 54 | We strive for feedback and want to understand everyone's needs, and you can hang out with us on [Discord](https://www.polyfire.com/discord)! 55 | 56 | ## 🧑‍💻 Contributing 57 | 58 | Polyfire is open-source! You can contribute to the [Javascript SDK](https://github.com/polyfire-ai/polyfire-js) or the [API](https://github.com/polyfire-ai/polyfact-api-go) by opening an issue or a PR! 59 | -------------------------------------------------------------------------------- /docs/v0.2.3/Get Started/models-list.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Models List" 3 | slug: "models-list" 4 | excerpt: "List of the models available and their respective costs." 5 | hidden: false 6 | metadata: 7 | image: [] 8 | robots: "index" 9 | createdAt: "Tue Sep 26 2023 01:24:16 GMT+0000 (Coordinated Universal Time)" 10 | updatedAt: "Fri Nov 10 2023 10:06:56 GMT+0000 (Coordinated Universal Time)" 11 | --- 12 | | Model Name | Type | Input | Output | 13 | | :--------------------------------- | :------------------------- | :------------------ | :------------------ | 14 | | `gpt-3.5-turbo` | Text Generation | $0.0015 / 1K tokens | $0.002 / 1K tokens | 15 | | `gpt-3.5-turbo-16k` | Text Generation | $0.0030 / 1K tokens | $0.004 / 1K tokens | 16 | | `gpt-4` | Text Generation | $0.03 / 1K tokens | $0.06 / 1K tokens | 17 | | `gpt-4-32k` | Text Generation | $0.06 / 1K tokens | $0.12 / 1K tokens | 18 | | `cohere` | Text Generation | $0.015 / 1K tokens | $0.015 / 1K tokens | 19 | | `llama-2-70b-chat`[Replicate] | Text Generation | N/A | $0.0014 / second | 20 | | `wizard-mega-13b-awq`[Replicate] | Uncensored Text Generation | N/A | $0.000725 / second | 21 | | `airoboros-llama-2-70b`[Replicate] | Uncensored Text Generation | N/A | $0.0014 / second | 22 | | `replit-code-v1-3b`[Replicate] | Code Generation | N/A | $0.00115 / second | 23 | | `dalle-2` | Image Generation | N/A | $0.02 / image | 24 | | `text-embedding-ada-002` | Embeddings | $0.0001 / 1K tokens | N/A | 25 | | `elevenlabs` | Text-To-Speech | $0.3 / 1K chars | N/A | 26 | | `whisper` | Speech-To-Text | $0.0001 / second | N/A | 27 | 28 | - You can put your own OpenAI and Replicate keys in the [dashboard settings](https://beta.polyfire.com/settings). 29 | - `text-embedding-ada-002` is used when creating a Memory/Embeddings or when using a DataLoader. 30 | - Some features (Web, Memory, Embeddings, DataLoaders, etc...) will increase the number of input tokens. [the infos method](ref:infos) lets you monitor closely the LLMs token usage. 31 | - Your total usage costs appears on [your dashboard](https://beta.polyfire.com) 32 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/chats.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Chat" 3 | slug: "chats" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Mon Sep 11 2023 08:54:18 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:44:07 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/chats/getmessages.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "getMessages" 3 | slug: "getmessages" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Wed Sep 27 2023 06:31:52 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:44:07 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | Get the history of the previous chat messages. 10 | 11 | - Returns an array of Messages sorted from the most recent ones to the oldest. 12 | 13 | ```js javascript 14 | const history = await chat.getMessages(); 15 | 16 | const lastAnswer = history[0]; 17 | 18 | console.log(lastAnswer.content); // Neil, Buzz and Richard. 19 | ``` 20 | 21 | ```ts typescript 22 | type Message = { 23 | id: string; // A unique id for the message 24 | chat_id: string; // A unique id for the chat 25 | is_user_message: boolean; // Whether the message was sent by the user or the chatbot. 26 | content: string; // The content of the message 27 | created_at: string; // An ISO date for the time when the message was sent 28 | } 29 | ``` 30 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/chats/new-chat.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "new Chat()" 3 | slug: "new-chat" 4 | excerpt: "This feature allows you to create a chatbot with the minimal amount of code" 5 | hidden: false 6 | createdAt: "Fri Nov 03 2023 02:48:16 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:43:07 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | ## Create a simple chatbot 10 | 11 | To initialize a new chat: 12 | 13 | ```js javascript 14 | // In React 15 | const { utils: { Chat } } = usePolyfire(); 16 | // In other environments 17 | const { utils: { Chat } } = polyfire; 18 | 19 | const chat = new Chat(); 20 | ``` 21 | 22 | ## Chat context 23 | 24 | You can add context to your chatbot by the `systemPrompt` parameter. Pass a string containing your context when initiating the chat object. 25 | 26 | ```js javascript 27 | const systemPrompt = `Ask a random physics question. If the Human answers correctly, ask another question...`; 28 | const chat = new Chat({ systemPrompt }); 29 | ``` 30 | 31 | ## Chat options 32 | 33 | ```ts typescript 34 | type ChatOptions = { 35 | provider?: "openai" | "cohere" | "llama"; // The default value is "openai" 36 | systemPrompt?: string; // The system prompt as seen above 37 | systemPromptId?: string // The Id of a custom prompt 38 | autoMemory?: boolean; 39 | }; 40 | ``` 41 | 42 | ### Provider 43 | 44 | You can change the model provider using the provider option. 45 | 46 | For example, to create a chatbot using cohere: 47 | 48 | ```js javascript 49 | const chat = new Chat({ provider: "cohere" }); 50 | ``` 51 | 52 | ### AutoMemory 53 | 54 | The autoMemory option allows to send every message of the chat to a new memory and use it in every message. 55 | 56 | This adds a long-term memory to the chatbot. 57 | 58 | ```js javascript 59 | const chat = new Chat(); 60 | 61 | await chat.sendMessage("The secret word is banana42"); 62 | 63 | ... Send a lot of messages here 64 | 65 | await chat.sendMessage("What is the secret word?"); // The chatbot should still answer with banana42 66 | ``` 67 | 68 | ### systemPromptId 69 | 70 | The systemPromptId option allows you to add the ID of a custom prompt that you've created using the[ prompt features](ref:prompt-store) or by directly using a prompt shared by another developer. 71 | 72 | ### systemPromptId 73 | 74 | The `systemPromptId` option in the `ChatOptions` type allows you to specify a custom prompt that you've created for your app. This can be either the ID of the prompt or its alias. When using the Polyfire dashboard, the alias of the prompt is typically provided, which you can directly use here. 75 | 76 | #### Usage Example 77 | 78 | ```typescript 79 | import { Chat, usePolyfire } from 'polyfire-js'; 80 | import { ChatOptions } from "polyfire-js/generate"; 81 | 82 | 83 | // Example: Initializing a Chat with a custom system prompt ID (or alias) 84 | const App = () => { 85 | // In React 86 | const { utils: { Chat } } = usePolyfire(); 87 | // In other environments 88 | // const { utils: { Chat } } = polyfire; 89 | 90 | // Assuming 'physics-quiz-alias' is the alias of the custom prompt that you have created. 91 | const customSystemPromptId = 'physics-quiz-alias'; 92 | 93 | const chatOptions: ChatOptions = { 94 | systemPromptId: customSystemPromptId 95 | }; 96 | 97 | const chat = new Chat(chatOptions); 98 | 99 | // Further chat implementation... 100 | }; 101 | 102 | export default App; 103 | ``` 104 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/chats/sendmessage.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "sendMessage" 3 | slug: "sendmessage" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Wed Sep 27 2023 06:08:16 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:43:07 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | The `sendMessage` method in the `Chat` class is used to send a message to a chat conversation. This method automatically adapts to provide either a stream of responses or a single, complete response based on how it is called. 10 | 11 | ### Key Features 12 | 13 | #### Context-Aware 14 | 15 | - **Conversational Memory**: Every message sent and the corresponding response from the language model are stored, ensuring a continuous and coherent conversation flow by keeping track of all previous exchanges. 16 | 17 | #### Flexible Response Handling 18 | 19 | - **Streaming Mode**: Direct calls to `sendMessage` return a stream for real-time, incremental responses. Useful for lengthy or real-time interactions. Requires event listeners like `on('data', callback)`. 20 | - **Complete Mode**: Using `sendMessage` with `async/await` or `.then` returns a promise for a single, full response, suitable for standard request-response scenarios. 21 | 22 | ### Usage Examples 23 | 24 | #### Non-Streaming Response 25 | 26 | To receive a complete response after the message processing is finished, use `sendMessage` with `async/await` or `.then`. This will return a promise that resolves to a string containing the full response. 27 | 28 | ```ts 29 | const chat = new Chat(); 30 | 31 | // Example using async/await 32 | async function getCompleteResponse() { 33 | const answerString = await chat.sendMessage("Who was the first man to walk on the moon?"); 34 | console.log("Non-Streaming Response:", answerString); 35 | } 36 | 37 | // Example using .then 38 | chat.sendMessage("Who was the first man to walk on the moon?") 39 | .then(answerString => { 40 | console.log("Non-Streaming Response:", answerString); 41 | }); 42 | ``` 43 | 44 | #### Streaming Response 45 | 46 | For a real-time, incremental response, simply call `sendMessage` without `async/await` or `.then`. This will return a stream of responses as they become available. 47 | 48 | ```ts 49 | const chat = new Chat(); 50 | 51 | // Sending a message for streaming response 52 | const responseStream = chat.sendMessage("Who was the first man to walk on the moon?"); 53 | 54 | responseStream.on('data', (data) => { 55 | console.log("Streaming Part of Response:", data); 56 | }); 57 | ``` 58 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/generate-image.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "generateImage" 3 | slug: "generate-image" 4 | excerpt: "This features allows you to generate images easily from a prompt using dall-e" 5 | hidden: false 6 | createdAt: "Mon Sep 11 2023 09:01:05 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:44:07 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | ## Function: generateImage 10 | 11 | **Prototype:** 12 | 13 | ```ts typescript 14 | async function generateImage(prompt: string, options: GenerationOptions = {}): Promise<{ url: string }> 15 | ``` 16 | 17 | ### 💡 Examples 18 | 19 | The simplest way to use it: 20 | 21 | ```js javascript 22 | // In React: 23 | const { models: { generateImage } } = usePolyfire(); 24 | // In other environments: 25 | const { models: { generateImage } } = polyfire; 26 | 27 | const { url } = await generateImage("Pikachu"); // By default generateImage uses Dall-E to generate its images 28 | 29 | console.log(url); 30 | ``` 31 | 32 | [block:image] 33 | { 34 | "images": [ 35 | { 36 | "image": [ 37 | "https://hqyxaayiizqwlknddokk.supabase.co/storage/v1/object/public/generated_images/d70de08e-636e-4c78-b72e-a924b9d61464.png", 38 | null, 39 | "Cursed pikachu" 40 | ], 41 | "align": "center", 42 | "caption": "A cursed Pikachu" 43 | } 44 | ] 45 | } 46 | [/block] 47 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/generate-with-types.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "generateWithType" 3 | slug: "generate-with-types" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Mon Sep 11 2023 14:58:13 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:43:06 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | > **WARNING:** Probabilistic functions 10 | > Theses functions cannot be guaranteed to work every time. Complex inputs can sometimes confuse the LLMs and lead them to throw an Error. 11 | 12 | To define the schema we expose a modified version of `io-ts` that adds a way to describe your types. 13 | 14 | For the example here, we want to describe a function given in input and extract its name, the name of its arguments and its return type. 15 | 16 | ```js javascript 17 | import { t } from "polyfire"; 18 | 19 | // In React: const { models: { generateWithType } } = usePolyfire(); 20 | // In other environments: const { models: { generateWithType } } = polyfire; 21 | 22 | const functionDescriptionType = t.type({ 23 | functionName: t.string, 24 | description: t.string.description("A 50 word description of what the function does"), 25 | args: t.array(t.string).description("The name of the arguments"), 26 | returnType: t.string 27 | }); 28 | 29 | const { functionName, description, args, returnType } = await generateWithType( 30 | "function add(a, b, c) { return a + b + c }", 31 | functionDescriptionType, 32 | ); 33 | 34 | console.log(functionName) // add 35 | console.log(description) // Adds three numbers together. 36 | console.log(args) // ["a", "b", "c"] 37 | console.log(returnType) // number 38 | ``` 39 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/generate.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "generate" 3 | slug: "generate" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Mon Sep 11 2023 14:48:07 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:44:07 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/generate/generate-1.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "generate()" 3 | slug: "generate-1" 4 | excerpt: "This function is the simplest way to use LLM Text Generation." 5 | hidden: false 6 | createdAt: "Fri Nov 03 2023 02:45:48 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:43:07 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | **Prototype:** 10 | 11 | ```ts typescript 12 | // In React: const { models: { generate } } = usePolyfire(); 13 | // In other environments: const { models: { generate } } = polyfire; 14 | 15 | async function generate(task: string, options?: GenerationOptions): Generation // Generation implements Promise 16 | ``` 17 | 18 | ## 💡 Examples 19 | 20 | The simplest way to use it: 21 | 22 | ```js javascript 23 | const answer = await polyfire.generate("Who was the first man to walk on the moon?"); 24 | ``` 25 | 26 | You can also send some options as a second argument to the generate function. 27 | 28 | ```ts typescript 29 | type GenerationOptions = { 30 | model?: "gpt-3.5-turbo" | "gpt-3.5-turbo-16k" | "gpt-4" | "gpt-4-32k" | "cohere" | "llama-2-70b-chat" | "replit-code-v1-3b" | "wizard-mega-13b-awq"; // The default value is gpt-3.5-turbo 31 | stop?: string[]; // A list of word where the generation should stop 32 | temperature?: number; // The text generation temperature (setting this to 0.0 will make the generation deterministic) 33 | memoryId?: string; // The id of a memory to improve the context given to the LLM see the memory section of the wiki to learn more. 34 | chatId?: string; // The id of a existing chat. It is not recommended to use this directly,prefer to use the chat feature, see the chat section to learn more. 35 | language?: string; // The language the result should be written in 36 | } 37 | ``` 38 | 39 | For example, to generate with cohere: 40 | 41 | ```javascript 42 | const answer = await polyfire.generate("What color is the sky?", { model: "gpt-4" }); 43 | ``` 44 | 45 | ## Generate Chains 46 | 47 | You can easily construct chains of generates by call the generate method of the Generation result class 48 | 49 | ```javascript 50 | const answer = await generate("Who was Neil Armstrong ?") 51 | .generate("Who was the US president at the time ?") 52 | .generate("Who was his wife ?"); 53 | 54 | console.log(answer); 55 | // Answer: The wife of Richard Nixon, the President of the United States at the time of Neil Armstrong's moonwalk, was Pat Nixon. 56 | ``` 57 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/generate/infos.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "infos" 3 | slug: "infos" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Tue Sep 12 2023 09:00:17 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:44:07 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | The `infos`method, when used with Polyfire`generate` function, lets you see more details about how the text is created. 10 | 11 | ### Infos Option 12 | 13 | Use the `infos` method to get a report showing token use (what goes in and comes out) and the resources the model uses when creating text with the `web`, `memory` or `data` options. This is helpful for seeing how the model works, its costs, and figuring out where the created content comes from. 14 | 15 | To use the `infos` feature, call the `infos` method of the result of the `generate` function: 16 | 17 | ```typescript 18 | generate("your_task_here").infos(); 19 | ``` 20 | 21 | When turned on, the `generate` function gives back a `GenerationResult` that includes: 22 | 23 | ``` 24 | type GenerationResult = { 25 | result: string; // The generated content 26 | tokenUsage: { // Token usage for input and output 27 | input: number; 28 | output: number; 29 | }; 30 | ressources?: Ressource[]; // Resources or embeddings used during generation 31 | }; 32 | 33 | ``` 34 | 35 | ### TokenUsage 36 | 37 | A part of `GenerationResult`, `TokenUsage` shows clearly the tokens used in a specific text creation task: 38 | 39 | ```typescript 40 | type TokenUsage = { 41 | input: number; // Tokens consumed for the input task. 42 | output: number; // Tokens generated as output. 43 | }; 44 | ``` 45 | 46 | This feature is especially valuable for understanding model computation costs and ensuring you're not overshooting token limitations. 47 | 48 | ### Ressource 49 | 50 | `Ressource` arrays encapsulate and present the various resources from `web`, `memory` or `data` that the model relied upon during generation: 51 | 52 | ```typescript 53 | type Ressource = { 54 | similarity: number; // Similarity score between resource and generated content. 55 | id: string; // Unique identifier of the resource. 56 | content: string; // Actual content of the resource. 57 | }; 58 | ``` 59 | 60 | This data can be leveraged to trace back the origins of generated content. 61 | 62 | 💡 **Example** 63 | 64 | ```typescript 65 | // In React: 66 | const { models: { generate } } = usePolyfire(); 67 | // In other environments: 68 | const { models: { generate } } = polyfire; 69 | 70 | // Define task, options, and client configurations 71 | const task = "Explain the concept of quantum entanglement."; 72 | 73 | const generationOptions: GenerationWithInfosOptions = { 74 | provider: "openai", 75 | model: "gpt-3.5-turbo", 76 | memoryId: "your_memory_id", 77 | }; 78 | 79 | try { 80 | const result = await generate(task, generationOptions).infos(); 81 | console.log("Generated Output:", result.result); 82 | console.log("Token Usage:", result.tokenUsage); 83 | console.log("Resources Used:", result.ressources); 84 | 85 | } catch (error) { 86 | console.error("Generation faced an inconsistency:", error); 87 | } 88 | 89 | ``` 90 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/generate/stream.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "stream" 3 | slug: "stream" 4 | excerpt: "" 5 | hidden: false 6 | createdAt: "Mon Sep 11 2023 14:53:10 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:44:07 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | The result of a generation can also be used as a stream 10 | 11 | **Prototype:** 12 | 13 | ```ts typescript 14 | function generate( 15 | task: string, 16 | options: GenerationOption, 17 | ): Generation; // Generation implements the Readable interface from https://www.npmjs.com/package/readable-stream 18 | ``` 19 | 20 | The stream should send the result token by token instead of waiting for the whole answer. 21 | 22 | _NOTE: Cohere doesn't support streams yet and will return the entire answer in one chunk_ 23 | 24 | ### 💡 Example 25 | 26 | The result can be piped to a writable stream with the `pipe` method or individuals chunks can be retrieved using the `.on` method as seen in the [stream api](https://nodejs.org/api/stream.html#readable-streams) 27 | 28 | ```js javascript 29 | const resultStream = polyfire.generate("Who was the first man to walk on the moon?", { stream: true }); 30 | 31 | resultStream.on("data", console.log); // In this should start printing the result word by word 32 | ``` 33 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/text-generation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Text Generation" 3 | slug: "text-generation" 4 | excerpt: "Examples of text generation functions." 5 | hidden: false 6 | metadata: 7 | image: [] 8 | robots: "index" 9 | createdAt: "Fri Nov 03 2023 01:00:22 GMT+0000 (Coordinated Universal Time)" 10 | updatedAt: "Fri Nov 03 2023 02:14:19 GMT+0000 (Coordinated Universal Time)" 11 | --- 12 | # Generate Text 13 | 14 | The basic LLM function is called `generate()`. It is imported from the _models_ Polyfire module. By default `generate()` calls the OpenAI gpt-3.5-turbo endpoint, which is the model running ChatGPT. 15 | 16 | An example of a simple AI-generated greeting in a React app: 17 | 18 | ```jsx 19 | function GreetingBox({ userName }) { 20 | const [greeting, setGreeting] = useState(); 21 | const { models } = usePolyfire(); 22 | 23 | useEffect(() => { 24 | models 25 | .generate(`Write a fun and simple greeting for ${userName}`) 26 | .then(setGreeting); 27 | }, []); 28 | 29 | return
{greeting}
; 30 | } 31 | ``` 32 | 33 | # Customizing the Model 34 | 35 | You can change the the model the `generate()` function calls by including the options object. The complete list of available models and their names can be found [here](doc:models-list) or on the Dashboard. 36 | 37 | The same example but using GPT-4: 38 | 39 | ```jsx JSX 40 | function GreetingBox({ userName }) { 41 | const [greeting, setGreeting] = useState(); 42 | const { models } = usePolyfire(); 43 | 44 | useEffect(() => { 45 | models 46 | .generate(`Write a fun and simple greeting for ${userName}`, { model: "gpt-4" }) 47 | .then(setGreeting); 48 | }, []); 49 | 50 | return
{greeting}
; 51 | } 52 | ``` 53 | 54 | # Uncensored Generation 55 | 56 | To generate uncensored text, call the model `wizard-mega-13b-awq`. It can be very handy if you are trying to build, let's say, an AI girlfriend. 57 | 58 | ```jsx 59 | function DirtyAnswer({ userMessage, girlfriendPrompt }) { 60 | const [dirtyTalk, setDirtyTalk] = useState(); 61 | const { models } = usePolyfire(); 62 | 63 | useEffect(() => { 64 | const prompt = `${girlfriendPrompt}. Write a dirty answer to this message: ${userMessage}.` 65 | 66 | models 67 | .generate(prompt, { model: "wizard-mega-13b-awq" }) 68 | .then(setDirtyTalk); 69 | }, []); 70 | 71 | return
{dirtyTalk}
; 72 | } 73 | ``` 74 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/text-to-speech.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Text to speech" 3 | slug: "text-to-speech" 4 | excerpt: "Generate realistic audio files from written text" 5 | hidden: false 6 | createdAt: "Thu Oct 26 2023 13:08:03 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Thu Oct 26 2023 13:35:00 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | ## Function: tts 10 | 11 | **Prototype:** 12 | 13 | ```ts typescript 14 | async function tts(text: string, options?: TTSOptions): Promise 15 | 16 | type TTSOptions = { voice?: string }; // See below the list of all possible voices 17 | 18 | function AudioTTS.getMp3Buffer(): Buffer // Get the speech as an Mp3 file buffer 19 | async function AudioTTS.getAudioBuffer(): Promise // Get the speech as a standard [AudioBuffer](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer) 20 | async function AudioTTS.play(): Promise // Play the speech audio 21 | ``` 22 | 23 | ### 💡 Example 24 | 25 | ```js javascript 26 | // In React: 27 | const { models: { tts } } = usePolyfire(); 28 | // In other environments: 29 | const { models: { tts } } = polyfire; 30 | 31 | const audio = await tts("According to all known laws of aviations, there is no way that a bee should be able to fly."); 32 | 33 | await audio.play(); 34 | ``` 35 | 36 | *** 37 | 38 | ## Available voices list: 39 | 40 | | name | gender | description | provider | 41 | | :-------- | :----- | :------------- | :--------- | 42 | | rachel | female | calm | elevenlabs | 43 | | clyde | male | war veteran | elevenlabs | 44 | | domi | female | strong | elevenlabs | 45 | | dave | male | conversational | elevenlabs | 46 | | fin | male | sailor | elevenlabs | 47 | | bella | female | soft | elevenlabs | 48 | | antoni | male | well-rounded | elevenlabs | 49 | | thomas | male | calm | elevenlabs | 50 | | charlie | male | casual | elevenlabs | 51 | | emily | female | calm | elevenlabs | 52 | | elli | female | emotional | elevenlabs | 53 | | callum | male | hoarse | elevenlabs | 54 | | patrick | male | shouty | elevenlabs | 55 | | harry | male | anxious | elevenlabs | 56 | | liam | male | | elevenlabs | 57 | | dorothy | female | pleasant | elevenlabs | 58 | | josh | male | deep | elevenlabs | 59 | | arnold | male | crisp | elevenlabs | 60 | | charlotte | female | seductive | elevenlabs | 61 | | matilda | female | warm | elevenlabs | 62 | | matthew | male | | elevenlabs | 63 | | james | male | calm | elevenlabs | 64 | | joseph | male | | elevenlabs | 65 | | jeremy | male | excited | elevenlabs | 66 | | michael | male | | elevenlabs | 67 | | ethan | male | | elevenlabs | 68 | | gigi | female | childlish | elevenlabs | 69 | | freya | female | | elevenlabs | 70 | | grace | female | | elevenlabs | 71 | | daniel | male | deep | elevenlabs | 72 | | serena | female | pleasant | elevenlabs | 73 | | adam | male | deep | elevenlabs | 74 | | nicole | female | whisper | elevenlabs | 75 | | jessie | male | raspy | elevenlabs | 76 | | ryan | male | soldier | elevenlabs | 77 | | sam | male | raspy | elevenlabs | 78 | | glinda | female | witch | elevenlabs | 79 | | giovanni | male | foreigner | elevenlabs | 80 | | mimi | female | childish | elevenlabs | 81 | -------------------------------------------------------------------------------- /docs/v0.2.3/Models/transcribe.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Speech to text" 3 | slug: "transcribe" 4 | excerpt: "Transcribe audio files to texts easily using the transcribe function" 5 | hidden: false 6 | createdAt: "Mon Sep 11 2023 08:56:11 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:44:07 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | ## Function: transcribe 10 | 11 | **Prototype:** 12 | 13 | ```ts typescript 14 | async function transcribe(file: Uint8Array | Buffer | Readable): Promise 15 | ``` 16 | 17 | ### 💡 Example 18 | 19 | ```js javascript 20 | // Get your file from an upload/fetch. 21 | 22 | // In React: 23 | const { models: { transcribe } } = usePolyfire(); 24 | // In other environments: 25 | const { models: { transcribe } } = polyfire; 26 | 27 | const transcription = await transcribe(file); 28 | 29 | console.log(transcription); 30 | ``` 31 | 32 | Should return (only if you have send the audio version on the bee-movie of course) 33 | 34 | ``` 35 | According to all known laws of aviation, there is no way that a bee should be able to fly. Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway because bees don't care about what humans think is impossible. 36 | ``` 37 | 38 | The supported file formats are `mp3`, `mp4`, `mpeg`, `mpga`, `m4a`, `wav` and `webm` 39 | 40 | The maximum file size is 25MB 41 | -------------------------------------------------------------------------------- /docs/v0.2.3/Prompt/system-prompts-alias.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "System Prompts" 3 | slug: "system-prompts-alias" 4 | excerpt: "" 5 | hidden: false 6 | metadata: 7 | title: "System Prompts Alias" 8 | description: "In this guide, we'll help you use aliases for system prompts to simplify your code" 9 | image: [] 10 | robots: "index" 11 | createdAt: "Thu Nov 02 2023 10:39:07 GMT+0000 (Coordinated Universal Time)" 12 | updatedAt: "Fri Nov 03 2023 16:12:07 GMT+0000 (Coordinated Universal Time)" 13 | --- 14 | In the Polyfire-JS SDK, the `generate` function or `Chat` class allows the use of the `systemPrompt` option where your prompts are typically hardcoded. An alternative is the `systemPromptId` option which utilizes a UUID. However, remembering and managing these UUIDs can be a hassle.So you can use an alias generated from your prompt name. They provide a recognizable and easy-to-use name for your system prompts, tidying up your code and enhancing clarity. 15 | 16 | ## Setting Up Prompts 17 | 18 | 1. **Access System Prompts**: Enter your dashboard, choose your project, and navigate to the system prompts management area. 19 | 20 | 2. **Create a New Prompt**: 21 | - Select `Prompts > Saved`. 22 | - Press the `New` button. 23 | - Input the name and prompt content, then save your new prompt. 24 | - If a prompt already exists, locate it in `Prompts > Saved`. 25 | 26 | 3. **Select a Prompt**: Identify the prompt you wish to use and copy its alias for use in your code. 27 | 28 | _Note_: Your prompt's name should be distinctive as it forms the basis of the alias and should be easy to remember. 29 | 30 | ## Use Alias in Your Code 31 | 32 | After setting up your custom prompt, you can use the alias with the `systemPromptId` in your code when engaging with polyfire-js SDK. Here's how: 33 | 34 | ```javascript 35 | generate("Write a hello world haiku", {systemPromptId: "my_prompt_alias"}) 36 | .then(response => { 37 | console.log(response); 38 | }) 39 | .catch(error => { 40 | console.error(error); 41 | }); 42 | ``` 43 | 44 | In the snippet above, "my_prompt_alias" stands in for the system prompt's alias. The Polyfire API will use this alias to identify and execute the appropriate system prompt. 45 | -------------------------------------------------------------------------------- /docs/v0.2.3/React Components/auto-complete-input.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "AutoCompleteInput" 3 | slug: "auto-complete-input" 4 | excerpt: "Input component with auto-complete suggestions" 5 | hidden: false 6 | createdAt: "Mon Jan 08 2024 15:18:11 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:42:00 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | # Description 10 | 11 | A regular input component with an auto-complete placeholder. When a user types some text, the component waits for a 1 second break, and then sends a query to GPT-3.5 to suggest the next couple of words. The users can accept the suggestion with the Tab key. 12 | 13 | # Props 14 | 15 | - `completionColor`: Specifies the color of the auto-complete text. 16 | - `containerStyle`: Defines the styling for the component's container. 17 | - `containerClassName`: CSS class name for the component's container 18 | - Extends all the props of a classic `` component 19 | 20 | # Example 21 | 22 | ```typescript 23 | 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/v0.2.3/React Components/auto-complete-textarea.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "AutoCompleteTextArea" 3 | slug: "auto-complete-textarea" 4 | excerpt: "Textarea component with auto-complete suggestions" 5 | hidden: false 6 | createdAt: "Mon Jan 08 2024 15:17:59 GMT+0000 (Coordinated Universal Time)" 7 | updatedAt: "Fri Mar 01 2024 06:42:00 GMT+0000 (Coordinated Universal Time)" 8 | --- 9 | # Description 10 | 11 | This component is a regular Textarea component. But after the user has stopped typing for 1 second, it calls GTP-3.5 to ask for a suggestion on the next couple of words. The user can accept the suggestion with the Tab key. 12 | 13 | It's like [AutoCompleteInput](ref:auto-complete-input) but for a Textarea. 14 | 15 | # Props 16 | 17 | - Extends all the props of a standard `