From 33312e0fd9732d434ce31bd6e6177cf353e91c2b Mon Sep 17 00:00:00 2001 From: Lennard Schwarz Date: Mon, 30 Oct 2023 14:52:43 +0100 Subject: [PATCH 1/8] Add my middleware thing --- README.md | 201 +---------------------------------------- middleware.ts | 27 ++++++ pages/api/auth/auth.ts | 7 ++ 3 files changed, 39 insertions(+), 196 deletions(-) create mode 100644 middleware.ts create mode 100644 pages/api/auth/auth.ts diff --git a/README.md b/README.md index 454723498..9da0990e9 100644 --- a/README.md +++ b/README.md @@ -1,201 +1,10 @@ # `BIG-AGI` 🤖💬 -Welcome to `big-AGI` 👋 your personal AGI application -powered by OpenAI GPT-4 and beyond. Designed for smart humans and super-heroes, -this responsive web app comes with Personas, Drawing, Code Execution, PDF imports, Voice support, -data Rendering, AGI functions, chats and much more. Comes with plenty of `#big-AGI-energy` 🚀 +Fork with basic auth added. -[![Official Website](https://img.shields.io/badge/BIG--AGI.com-%23096bde?style=for-the-badge&logo=vercel&label=demo)](https://big-agi.com) +Add the following environment variables -Or fork & run on Vercel +BASIC_AUTH_USERNAME=test +BASIC_AUTH_PASSWORD=test -[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fenricoros%2Fbig-agi&env=OPENAI_API_KEY,OPENAI_API_HOST&envDescription=OpenAI%20KEY%20for%20your%20deployment.%20Set%20HOST%20only%20if%20non-default.) - -## ✨ Key Features 👊 - -![Ask away, paste a ton, copy the gems](docs/pixels/big-AGI-compo1.png) - -- **AI Personas** -- **Polished UI**: installable web app, mobile-friendly, token counters, etc. -- **Fast UX**: Microphone, Camera OCR, Drag files, Voice Synthesis -- **Models**: [OpenAI](https://platform.openai.com/overview), [Anthropic](https://www.anthropic.com/product), [Azure](https://oai.azure.com/), [OpenRouter](https://openrouter.ai/), [Local models](https://github.com/oobabooga/text-generation-webui), and more -- **Private**: use your own API keys and self-host if you like -- **Advanced**: PDF import & Summarization, code execution -- **Integrations**: ElevenLabs, Helicone, Paste.gg, Prodia and more - -## 💖 Support - -[//]: # ([![Official Discord](https://img.shields.io/discord/1098796266906980422?label=discord&logo=discord&logoColor=%23fff&style=for-the-badge)](https://discord.gg/MkH4qj2Jp9)) -[![Official Discord](https://discordapp.com/api/guilds/1098796266906980422/widget.png?style=banner2)](https://discord.gg/MkH4qj2Jp9) - -* Enjoy the hosted open-source app on [big-AGI.com](https://big-agi.com) -* [Chat with us](https://discord.gg/MkH4qj2Jp9) -* Deploy your [fork](https://github.com/enricoros/big-agi/fork) for your friends and family -* send PRs! ... - 🎭[Editing Personas](https://github.com/enricoros/big-agi/issues/35), - 🧩[Reasoning Systems](https://github.com/enricoros/big-agi/issues/36), - 🌐[Community Templates](https://github.com/enricoros/big-agi/issues/35), - and [your big-IDEAs](https://github.com/enricoros/big-agi/issues/new?labels=RFC&body=Describe+the+idea) - -
- -## 🧠 Latest Drops - -#### Next - -- **Cloudflare API Gateway** support -- **Helicone for Anthropic** support -- **Text Tools** - incl. highlight differences - -#### 1.4.0: Sept/Oct: scale OUT - -- **Expanded Model Support**: Azure and [OpenRouter](https://openrouter.ai/docs#models) models, including gpt-4-32k -- **Share and clone** conversations with public links -- Removed the 20 chats hard limit ([Ashesh3](https://github.com/enricoros/big-agi/pull/158)) -- Latex Rendering -- Augmented Chat modes (Labs) - -#### July/Aug: More Better Faster - -- **Camera OCR** - real-world AI - take a picture of a text, and chat with it -- **Anthropic models** support, e.g. Claude -- **Backup/Restore** - save chats, and restore them later -- **[Local model support with Oobabooga server](docs/config-local-oobabooga)** - run your own LLMs! -- **Flatten conversations** - conversations summarizer with 4 modes -- **Fork conversations** - create a new chat, to experiment with different endings -- New commands: /s to add a System message, and /a for an Assistant message -- New Chat modes: Write-only - just appends the message, without assistant response -- Fix STOP generation - in sync with the Vercel team to fix a long-standing NextJS issue -- Fixes on the HTML block - particularly useful to see error pages - -#### June: scale UP - -- **[New OpenAI Models](https://openai.com/blog/function-calling-and-other-api-updates) support** - 0613 models, including 16k and 32k -- **Cleaner UI** - with rationalized Settings, Modals, and Configurators -- **Dynamic Models Configurator** - easy connection with different model vendors -- **Multiple Model Vendors Support** framework to support many LLM vendors -- **Per-model Options** (temperature, tokens, etc.) for fine-tuning AI behavior to your needs -- Support for GPT-4-32k -- Improved Dialogs and Messages -- Much Enhanced DX: TRPC integration, modularization, pluggable UI, etc - -#### April / May: more #big-agi-energy - -- **[Google Search](docs/pixels/feature_react_google.png)** active in ReAct - add your keys to Settings > Google - Search -- **[Reason+Act](docs/pixels/feature_react_turn_on.png)** preview feature - activate with 2-taps on the 'Chat' button -- **[Image Generation](docs/pixels/feature_imagine_command.png)** using Prodia (BYO Keys) - /imagine - or menu option -- **[Voice Synthesis](docs/pixels/feature_voice_1.png)** 📣 with ElevenLabs, including selection of custom voices -- **[Precise Token Counter](docs/pixels/feature_token_counter.png)** 📈 extra-useful to pack the context window -- **[Install Mobile APP](docs/pixels/feature_pwa.png)** 📲 looks like native (@harlanlewis) -- **[UI language](docs/pixels/feature_language.png)** with auto-detect, and future app language! (@tbodyston) -- **PDF Summarization** 🧩🤯 - ask questions to a PDF! (@fredliubojin) -- **Code Execution: [Codepen](https://codepen.io/)/[Replit](https://replit.com/)** 💻 (@harlanlewis) -- **[SVG Drawing](docs/pixels/feature_svg_drawing.png)** - draw with AI 🎨 -- Chats: multiple chats, AI titles, Import/Export, Selection mode -- Rendering: Markdown, SVG, improved Code blocks -- Integrations: OpenAI organization ID -- [Cloudflare deployment instructions](docs/deploy-cloudflare.md), - [awesome-agi](https://github.com/enricoros/awesome-agi) -- [Typing Avatars](docs/pixels/gif_typing_040123.gif) ⌨️ - - -#### March: first release - -- **[AI Personas](docs/pixels/feature_purpose_two.png)** - including Code, Science, Corporate, and Chat 🎭 -- **Privacy**: user-owned API keys 🔑 and localStorage 🛡️ -- **Context** - Attach or [Drag & Drop files](docs/pixels/feature_drop_target.png) to add them to the prompt 📁 -- **Syntax highlighting** - for multiple languages 🌈 -- **Code Execution: Sandpack** - - [now on branch]((https://github.com/enricoros/big-agi/commit/f678a0d463d5e9cf0733f577e11bd612b7902d89)) `variant-code-execution` -- Chat with GPT-4 and 3.5 Turbo 🧠💨 -- Real-time streaming of AI responses ⚡ -- **Voice Input** 🎙️ - works great on Chrome / Windows -- Integration: **[Paste.gg](docs/pixels/feature_paste_gg.png)** integration for chat sharing 📥 -- Integration: **[Helicone](https://www.helicone.ai/)** integration for API observability 📊 -- 🌙 Dark model - Wide mode ⛶ - -
- -## Why this? 💡 - -Because the official Chat ___lacks important features___, is ___more limited than the api___, at times -___slow or unavailable___, and you cannot deploy it yourself, remix it, add features, or share it with -your friends. -Our users report that ___big-AGI is faster___, ___more reliable___, and ___features rich___ -with features that matter to them. - -![Much features, so fun](docs/pixels/big-AGI-compo2b.png) - -## Develop 🧩 - -![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=&logo=typescript&logoColor=white) -![React](https://img.shields.io/badge/React-61DAFB?style=&logo=react&logoColor=black) -![Next.js](https://img.shields.io/badge/Next.js-000000?style=&logo=vercel&logoColor=white) - -Clone this repo, install the dependencies, and run the development server: - -```bash -git clone https://github.com/enricoros/big-agi.git -cd big-agi -npm install -npm run dev -``` - -Now the app should be running on `http://localhost:3000` - -### Integrations: - -* [ElevenLabs](https://elevenlabs.io/) Voice Synthesis (bring your own voice too) - Settings > Text To Speech -* [Helicone](https://www.helicone.ai/) LLM Observability Platform - Models > OpenAI > Advanced > API Host: 'oai.hconeai.com' -* [Paste.gg](https://paste.gg/) Paste Sharing - Chat Menu > Share via paste.gg -* [Prodia](https://prodia.com/) Image Generation - Settings > Image Generation > Api Key & Model - -## Deploy with Docker 🐳 - -For more detailed information on deploying with Docker, please refer to the [docker deployment documentation](docs/deploy-docker.md). - -### 🔧 Locally built image - -> Firstly, write all your API keys and env vars to an `.env` file, and make sure the env file is using *both build and run*. -> See [docs/environment-variables.md](docs/environment-variables.md) for a list of all environment variables. - -```bash - -```bash -docker build -t big-agi . -docker run --detach 'big-agi' -``` - -### Pre-built image - -> Warning: the UI will still be asking for keys, as the image was built without the API keys - -```bash -docker-compose up -``` - -## Deploy with Cloudflare Pages ☁️ - -Please refer to the [Cloudflare deployment documentation](docs/deploy-cloudflare.md). - -## Deploy with Vercel 🚀 - -Create your GitHub fork, create a Vercel project over that fork, and deploy it. Or press the button below for convenience. - -[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fenricoros%2Fbig-agi&env=OPENAI_API_KEY,OPENAI_API_HOST&envDescription=OpenAI%20KEY%20for%20your%20deployment.%20Set%20HOST%20only%20if%20non-default.) - - - -
- -This project is licensed under the MIT License. - -[![GitHub stars](https://img.shields.io/github/stars/enricoros/big-agi)](https://github.com/enricoros/big-agi/stargazers) -[![GitHub forks](https://img.shields.io/github/forks/enricoros/big-agi)](https://github.com/enricoros/big-agi/network) -[![GitHub pull requests](https://img.shields.io/github/issues-pr/enricoros/big-agi)](https://github.com/enricoros/big-agi/pulls) -[![License](https://img.shields.io/github/license/enricoros/big-agi)](https://github.com/enricoros/big-agi/LICENSE) - -[//]: # ([![GitHub issues](https://img.shields.io/github/issues/enricoros/big-agi)](https://github.com/enricoros/big-agi/issues)) - -Made with 💙 +Update the middleware.ts to use the basic auth middleware on all routes in src/pages diff --git a/middleware.ts b/middleware.ts new file mode 100644 index 000000000..06c054a8c --- /dev/null +++ b/middleware.ts @@ -0,0 +1,27 @@ +import { NextRequest, NextResponse } from 'next/server' + +export const config = { + matcher: ['/', '/index', '/labs', '/launch', '/news', '/personas' ], +} + +export function middleware(req: NextRequest) { + const basicAuth = req.headers.get('authorization') + const url = req.nextUrl + + const envUsername = process.env.BASIC_AUTH_USERNAME + const envPassword = process.env.BASIC_AUTH_PASSWORD + + if (basicAuth) { + const authValue = basicAuth.split(' ')[1] + const [user, pwd] = atob(authValue).split(':') + + if (user === envUsername && pwd === envPassword) { + return NextResponse.next() + } + } + + // If the user is not authenticated, redirect to the auth page + url.pathname = '/api/auth/auth' + + return NextResponse.rewrite(url) +} \ No newline at end of file diff --git a/pages/api/auth/auth.ts b/pages/api/auth/auth.ts new file mode 100644 index 000000000..bedb39641 --- /dev/null +++ b/pages/api/auth/auth.ts @@ -0,0 +1,7 @@ +import type { NextApiRequest, NextApiResponse } from 'next' + +export default function handler(_: NextApiRequest, res: NextApiResponse) { + res.setHeader('WWW-authenticate', 'Basic realm="Secure Area"') + res.statusCode = 401 + res.end(`Auth Required.`) +} \ No newline at end of file From c240f6bd5bb474dc88340eab4671447fa9e8bdb5 Mon Sep 17 00:00:00 2001 From: Lennard Schwarz Date: Mon, 30 Oct 2023 14:55:53 +0100 Subject: [PATCH 2/8] Add deploy button --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 9da0990e9..68e4f5941 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,13 @@ Fork with basic auth added. +## Basic Auth Add the following environment variables BASIC_AUTH_USERNAME=test BASIC_AUTH_PASSWORD=test Update the middleware.ts to use the basic auth middleware on all routes in src/pages + +# Deploy +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fenricoros%2Fbig-agi&env=OPENAI_API_KEY,OPENAI_API_HOST&envDescription=OpenAI%20KEY%20for%20your%20deployment.%20Set%20HOST%20only%20if%20non-default.) \ No newline at end of file From e79b429c5e58bc21c0c6fe3016e22f5175043917 Mon Sep 17 00:00:00 2001 From: Lennard Schwarz Date: Mon, 30 Oct 2023 14:57:45 +0100 Subject: [PATCH 3/8] Update Readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 68e4f5941..9193896d3 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ Fork with basic auth added. ## Basic Auth Add the following environment variables -BASIC_AUTH_USERNAME=test -BASIC_AUTH_PASSWORD=test +BASIC_AUTH_USERNAME= +BASIC_AUTH_PASSWORD= Update the middleware.ts to use the basic auth middleware on all routes in src/pages From 89f3e6f95549cb5eaa01996c1cacca189d95f4bf Mon Sep 17 00:00:00 2001 From: Lennard Schwarz Date: Mon, 30 Oct 2023 14:57:51 +0100 Subject: [PATCH 4/8] Update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9193896d3..260e06358 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Fork with basic auth added. Add the following environment variables BASIC_AUTH_USERNAME= + BASIC_AUTH_PASSWORD= Update the middleware.ts to use the basic auth middleware on all routes in src/pages From 1efcadbf46597eb65ef31aa101fc623532faa0fa Mon Sep 17 00:00:00 2001 From: Lennard Schwarz Date: Fri, 1 Dec 2023 18:29:06 +0100 Subject: [PATCH 5/8] Update readme --- README.md | 184 +++++++++++++++++++----------------------------------- 1 file changed, 63 insertions(+), 121 deletions(-) diff --git a/README.md b/README.md index 4b4584943..a7c4988c9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# `BIG-AGI` 🤖💬 +# `Lenns BIG-AGI` # Changes to this fork Fork with basic auth added. @@ -12,30 +12,67 @@ BASIC_AUTH_PASSWORD= Update the middleware.ts to use the basic auth middleware on all routes in src/pages -# Description +# BIG-AGI 🧠✨ -Welcome to `big-AGI` 👋 your personal AGI application -powered by OpenAI GPT-4 and beyond. Designed for smart humans and super-heroes, -this responsive web app comes with Personas, Drawing, Code Execution, PDF imports, Voice support, -data Rendering, AGI functions, chats and much more. Comes with plenty of `#big-AGI-energy` 🚀 +Welcome to big-AGI 👋, the GPT application for Pro users that combines utility, +simplicity, and speed. Powered by the latest models from 7 vendors, including +open-source, `big-AGI` offers best-in-class Voice and Chat with AI Personas, +visualizations, coding, drawing, calling, and quite more -- all in a polished UX. -[![Official Website](https://img.shields.io/badge/BIG--AGI.com-%23096bde?style=for-the-badge&logo=vercel&label=demo)](https://big-agi.com) +Pros use big-AGI. 🚀 Developers love big-AGI. 🤖 + +[![Official Website](https://img.shields.io/badge/BIG--AGI.com-%23096bde?style=for-the-badge&logo=vercel&label=launch)](https://big-agi.com) Or fork & run on Vercel [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fenricoros%2Fbig-agi&env=OPENAI_API_KEY,OPENAI_API_HOST&envDescription=OpenAI%20KEY%20for%20your%20deployment.%20Set%20HOST%20only%20if%20non-default.) +## 👉 [roadmap](https://github.com/users/enricoros/projects/4/views/2) + +big-AGI is an open book; our **[public roadmap](https://github.com/users/enricoros/projects/4/views/2)** +shows the current developments and future ideas. + +- Got a suggestion? [_Add your roadmap ideas_](https://github.com/enricoros/big-agi/issues/new?&template=roadmap-request.md) +- Want to contribute? [_Pick up a task!_](https://github.com/users/enricoros/projects/4/views/4) - _easy_ to _pro_ + +### What's New in 1.6.0 - Nov 28, 2023 🌟 + +- **Web Browsing**: Download web pages within chats - [browsing guide](https://github.com/enricoros/big-agi/blob/main/docs/config-browse.md) +- **Branching Discussions**: Create new conversations from any message +- **Keyboard Navigation**: Swift chat navigation with new shortcuts (e.g. ctrl+alt+left/right) +- **Performance Boost**: Faster rendering for a smoother experience +- **UI Enhancements**: Refined interface based on user feedback +- **New Features**: Anthropic Claude 2.1, `/help` command, and Flattener tool +- **For Developers**: Code quality upgrades and snackbar notifications + +### What's New in 1.5.0 - Nov 19, 2023 + +- **Continued Voice**: Engage with hands-free interaction for a seamless experience +- **Visualization Tool**: Create data representations with our new visualization capabilities +- **Ollama Local Models**: Leverage local models support with our comprehensive guide +- **Text Tools**: Enjoy tools including highlight differences to refine your content +- **Mermaid Diagramming**: Render complex diagrams with our Mermaid language support +- **OpenAI 1106 Chat Models**: Experience the cutting-edge capabilities of the latest OpenAI models +- **SDXL Support**: Enhance your image generation with SDXL support for Prodia +- **Cloudflare OpenAI API Gateway**: Integrate with Cloudflare for a robust API gateway +- **Helicone for Anthropic**: Utilize Helicone's tools for Anthropic models + +Check out the [big-AGI open roadmap](https://github.com/users/enricoros/projects/4/views/2), or +the [past releases changelog](docs/changelog.md). + ## ✨ Key Features 👊 ![Ask away, paste a ton, copy the gems](docs/pixels/big-AGI-compo1.png) +[More](docs/pixels/big-AGI-compo2b.png), [screenshots](docs/pixels). -- **AI Personas** -- **Polished UI**: installable web app, mobile-friendly, token counters, etc. -- **Fast UX**: Microphone, Camera OCR, Drag files, Voice Synthesis -- **Models**: [OpenAI](https://platform.openai.com/overview), [Anthropic](https://www.anthropic.com/product), [Azure](https://oai.azure.com/), [OpenRouter](https://openrouter.ai/), [Local models](https://github.com/oobabooga/text-generation-webui), and more -- **Private**: use your own API keys and self-host if you like -- **Advanced**: PDF import & Summarization, code execution -- **Integrations**: ElevenLabs, Helicone, Paste.gg, Prodia and more +- **AI Personas**: Tailor your AI interactions with customizable personas +- **Sleek UI/UX**: A smooth, intuitive, and mobile-responsive interface +- **Efficient Interaction**: Voice commands, OCR, and drag-and-drop file uploads +- **Multiple AI Models**: Choose from a variety of leading AI providers +- **Privacy First**: Self-host and use your own API keys for full control +- **Advanced Tools**: Execute code, import PDFs, and summarize documents +- **Seamless Integrations**: Enhance functionality with various third-party services +- **Open Roadmap**: Contribute to the progress of big-AGI ## 💖 Support @@ -53,95 +90,7 @@ Or fork & run on Vercel
-## 🧠 Latest Drops - -#### Next - -- **Cloudflare API Gateway** support -- **Helicone for Anthropic** support -- **Text Tools** - incl. highlight differences - -#### 1.4.0: Sept/Oct: scale OUT - -- **Expanded Model Support**: Azure and [OpenRouter](https://openrouter.ai/docs#models) models, including gpt-4-32k -- **Share and clone** conversations with public links -- Removed the 20 chats hard limit ([Ashesh3](https://github.com/enricoros/big-agi/pull/158)) -- Latex Rendering -- Augmented Chat modes (Labs) - -#### July/Aug: More Better Faster - -- **Camera OCR** - real-world AI - take a picture of a text, and chat with it -- **Anthropic models** support, e.g. Claude -- **Backup/Restore** - save chats, and restore them later -- **[Local model support with Oobabooga server](docs/config-local-oobabooga)** - run your own LLMs! -- **Flatten conversations** - conversations summarizer with 4 modes -- **Fork conversations** - create a new chat, to experiment with different endings -- New commands: /s to add a System message, and /a for an Assistant message -- New Chat modes: Write-only - just appends the message, without assistant response -- Fix STOP generation - in sync with the Vercel team to fix a long-standing NextJS issue -- Fixes on the HTML block - particularly useful to see error pages - -#### June: scale UP - -- **[New OpenAI Models](https://openai.com/blog/function-calling-and-other-api-updates) support** - 0613 models, including 16k and 32k -- **Cleaner UI** - with rationalized Settings, Modals, and Configurators -- **Dynamic Models Configurator** - easy connection with different model vendors -- **Multiple Model Vendors Support** framework to support many LLM vendors -- **Per-model Options** (temperature, tokens, etc.) for fine-tuning AI behavior to your needs -- Support for GPT-4-32k -- Improved Dialogs and Messages -- Much Enhanced DX: TRPC integration, modularization, pluggable UI, etc - -#### April / May: more #big-agi-energy - -- **[Google Search](docs/pixels/feature_react_google.png)** active in ReAct - add your keys to Settings > Google - Search -- **[Reason+Act](docs/pixels/feature_react_turn_on.png)** preview feature - activate with 2-taps on the 'Chat' button -- **[Image Generation](docs/pixels/feature_imagine_command.png)** using Prodia (BYO Keys) - /imagine - or menu option -- **[Voice Synthesis](docs/pixels/feature_voice_1.png)** 📣 with ElevenLabs, including selection of custom voices -- **[Precise Token Counter](docs/pixels/feature_token_counter.png)** 📈 extra-useful to pack the context window -- **[Install Mobile APP](docs/pixels/feature_pwa.png)** 📲 looks like native (@harlanlewis) -- **[UI language](docs/pixels/feature_language.png)** with auto-detect, and future app language! (@tbodyston) -- **PDF Summarization** 🧩🤯 - ask questions to a PDF! (@fredliubojin) -- **Code Execution: [Codepen](https://codepen.io/)/[Replit](https://replit.com/)** 💻 (@harlanlewis) -- **[SVG Drawing](docs/pixels/feature_svg_drawing.png)** - draw with AI 🎨 -- Chats: multiple chats, AI titles, Import/Export, Selection mode -- Rendering: Markdown, SVG, improved Code blocks -- Integrations: OpenAI organization ID -- [Cloudflare deployment instructions](docs/deploy-cloudflare.md), - [awesome-agi](https://github.com/enricoros/awesome-agi) -- [Typing Avatars](docs/pixels/gif_typing_040123.gif) ⌨️ - - -#### March: first release - -- **[AI Personas](docs/pixels/feature_purpose_two.png)** - including Code, Science, Corporate, and Chat 🎭 -- **Privacy**: user-owned API keys 🔑 and localStorage 🛡️ -- **Context** - Attach or [Drag & Drop files](docs/pixels/feature_drop_target.png) to add them to the prompt 📁 -- **Syntax highlighting** - for multiple languages 🌈 -- **Code Execution: Sandpack** - - [now on branch]((https://github.com/enricoros/big-agi/commit/f678a0d463d5e9cf0733f577e11bd612b7902d89)) `variant-code-execution` -- Chat with GPT-4 and 3.5 Turbo 🧠💨 -- Real-time streaming of AI responses ⚡ -- **Voice Input** 🎙️ - works great on Chrome / Windows -- Integration: **[Paste.gg](docs/pixels/feature_paste_gg.png)** integration for chat sharing 📥 -- Integration: **[Helicone](https://www.helicone.ai/)** integration for API observability 📊 -- 🌙 Dark model - Wide mode ⛶ - -
- -## Why this? 💡 - -Because the official Chat ___lacks important features___, is ___more limited than the api___, at times -___slow or unavailable___, and you cannot deploy it yourself, remix it, add features, or share it with -your friends. -Our users report that ___big-AGI is faster___, ___more reliable___, and ___features rich___ -with features that matter to them. - -![Much features, so fun](docs/pixels/big-AGI-compo2b.png) - -## Develop 🧩 +## 🧩 Develop ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=&logo=typescript&logoColor=white) ![React](https://img.shields.io/badge/React-61DAFB?style=&logo=react&logoColor=black) @@ -156,44 +105,37 @@ npm install npm run dev ``` -Now the app should be running on `http://localhost:3000` +The app will be running on `http://localhost:3000` -### Integrations: +Integrations: +* Local models: Ollama, Oobabooga, LocalAi, etc. * [ElevenLabs](https://elevenlabs.io/) Voice Synthesis (bring your own voice too) - Settings > Text To Speech * [Helicone](https://www.helicone.ai/) LLM Observability Platform - Models > OpenAI > Advanced > API Host: 'oai.hconeai.com' * [Paste.gg](https://paste.gg/) Paste Sharing - Chat Menu > Share via paste.gg * [Prodia](https://prodia.com/) Image Generation - Settings > Image Generation > Api Key & Model -## Deploy with Docker 🐳 +## 🐳 Deploy with Docker For more detailed information on deploying with Docker, please refer to the [docker deployment documentation](docs/deploy-docker.md). -### 🔧 Locally built image - -> Firstly, write all your API keys and env vars to an `.env` file, and make sure the env file is using *both build and run*. -> See [docs/environment-variables.md](docs/environment-variables.md) for a list of all environment variables. - -```bash +Build and run: ```bash docker build -t big-agi . -docker run --detach 'big-agi' +docker run -d -p 3000:3000 big-agi ``` -### Pre-built image +Or run the official container: -> Warning: the UI will still be asking for keys, as the image was built without the API keys +- manually: `docker run -d -p 3000:3000 ghcr.io/enricoros/big-agi` +- or, with docker-compose: `docker-compose up` -```bash -docker-compose up -``` - -## Deploy with Cloudflare Pages ☁️ +## ☁️ Deploy on Cloudflare Pages Please refer to the [Cloudflare deployment documentation](docs/deploy-cloudflare.md). -## Deploy with Vercel 🚀 +## 🚀 Deploy on Vercel Create your GitHub fork, create a Vercel project over that fork, and deploy it. Or press the button below for convenience. From b7ca69aa0e14fa853f40cdfdfb243990cf46efe3 Mon Sep 17 00:00:00 2001 From: Lennard Schwarz Date: Fri, 1 Dec 2023 18:31:04 +0100 Subject: [PATCH 6/8] Update realm info --- pages/api/auth/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/api/auth/auth.ts b/pages/api/auth/auth.ts index bedb39641..9bf5eef42 100644 --- a/pages/api/auth/auth.ts +++ b/pages/api/auth/auth.ts @@ -1,7 +1,7 @@ import type { NextApiRequest, NextApiResponse } from 'next' export default function handler(_: NextApiRequest, res: NextApiResponse) { - res.setHeader('WWW-authenticate', 'Basic realm="Secure Area"') + res.setHeader('WWW-authenticate', 'Basic realm="Private Area"') res.statusCode = 401 res.end(`Auth Required.`) } \ No newline at end of file From c82ea978daf1b453bede73a73112095e6e1c1de0 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Sat, 9 Dec 2023 23:05:56 -0800 Subject: [PATCH 7/8] Improve Build/Deploy instructions --- README.md | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 9eeebbd44..685e0c281 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,3 @@ -# `Lenns BIG-AGI` - -# Changes to this fork -Fork with basic auth added. - -## Basic Auth -Add the following environment variables - -BASIC_AUTH_USERNAME= - -BASIC_AUTH_PASSWORD= - -Update the middleware.ts to use the basic auth middleware on all routes in src/pages - # BIG-AGI 🧠✨ Welcome to big-AGI 👋, the GPT application for professionals that need form, function, @@ -96,7 +82,8 @@ the [past releases changelog](docs/changelog.md). ![React](https://img.shields.io/badge/React-61DAFB?style=&logo=react&logoColor=black) ![Next.js](https://img.shields.io/badge/Next.js-000000?style=&logo=vercel&logoColor=white) -Clone this repo, install the dependencies, and run the development server: +Clone this repo, install the dependencies (all locally), and run the development server (which auto-watches the +files for changes): ```bash git clone https://github.com/enricoros/big-agi.git @@ -105,15 +92,21 @@ npm install npm run dev ``` -The app will be running on `http://localhost:3000` +The development app will be running on `http://localhost:3000`. Development builds have the advantage of not requiring +a build step, but can be slower than production builds. Also, development builds won't have timeout on edge functions. -Integrations: +## 🌐 Deploy manually -* Local models: Ollama, Oobabooga, LocalAi, etc. -* [ElevenLabs](https://elevenlabs.io/) Voice Synthesis (bring your own voice too) - Settings > Text To Speech -* [Helicone](https://www.helicone.ai/) LLM Observability Platform - Models > OpenAI > Advanced > API Host: 'oai.hconeai.com' -* [Paste.gg](https://paste.gg/) Paste Sharing - Chat Menu > Share via paste.gg -* [Prodia](https://prodia.com/) Image Generation - Settings > Image Generation > Api Key & Model +The _production_ build of the application is optimized for performance and is performed by the `npm run build` command, +after installing the required dependencies. + +```bash +# .. repeat the steps above up to `npm install`, then: +npm run build +npm run start --port 3000 +``` + +The app will be running on the specified port, e.g. `http://localhost:3000` ## 🐳 Deploy with Docker @@ -129,7 +122,7 @@ docker run -d -p 3000:3000 big-agi Or run the official container: - manually: `docker run -d -p 3000:3000 ghcr.io/enricoros/big-agi` -- or, with docker-compose: `docker-compose up` +- or, with docker-compose: `docker-compose up` or see [the documentation](docs/deploy-docker.md) for a composer file with integrated browsing ## ☁️ Deploy on Cloudflare Pages @@ -141,7 +134,13 @@ Create your GitHub fork, create a Vercel project over that fork, and deploy it. [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fenricoros%2Fbig-agi&env=OPENAI_API_KEY,OPENAI_API_HOST&envDescription=OpenAI%20KEY%20for%20your%20deployment.%20Set%20HOST%20only%20if%20non-default.) +## Integrations: +* Local models: Ollama, Oobabooga, LocalAi, etc. +* [ElevenLabs](https://elevenlabs.io/) Voice Synthesis (bring your own voice too) - Settings > Text To Speech +* [Helicone](https://www.helicone.ai/) LLM Observability Platform - Models > OpenAI > Advanced > API Host: 'oai.hconeai.com' +* [Paste.gg](https://paste.gg/) Paste Sharing - Chat Menu > Share via paste.gg +* [Prodia](https://prodia.com/) Image Generation - Settings > Image Generation > Api Key & Model
From 0945bc1e74fae12f0303e4a9fa59d4a58c998106 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Sun, 10 Dec 2023 00:10:01 -0800 Subject: [PATCH 8/8] Documented HTTP basic Auth. Fixes #269 --- docs/deploy-authentication.md | 39 +++++++++++++++++++++++++ docs/environment-variables.md | 36 +++++++++++++---------- middleware.ts | 27 ----------------- middleware_BASIC_AUTH.ts | 55 +++++++++++++++++++++++++++++++++++ src/server/env.mjs | 4 +++ 5 files changed, 119 insertions(+), 42 deletions(-) create mode 100644 docs/deploy-authentication.md delete mode 100644 middleware.ts create mode 100644 middleware_BASIC_AUTH.ts diff --git a/docs/deploy-authentication.md b/docs/deploy-authentication.md new file mode 100644 index 000000000..f4a5f9d4b --- /dev/null +++ b/docs/deploy-authentication.md @@ -0,0 +1,39 @@ +# Authentication + +`big-AGI` does not come with built-in authentication. To secure your deployment, you can implement authentication +in one of the following ways: + +1. Rebuild `big-AGI` with support for [HTTP Basic Authentication](#http-authentication) +2. Utilize user authentication features provided by your [cloud deployment platform](#cloud-deployments-authentication) +3. Develop a custom authentication solution + +## HTTP Authentication + +[HTTP Basic Authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication) is a simple method +to secure your application. To enable it in `big-AGI`, you **must manually build the application**: + +- Build `big-AGI` with HTTP authentication enabled: + - Clone the repository + - Rename `middleware_BASIC_AUTH.ts` to `middleware_BASIC_AUTH.ts` + - Build: follow the build instructions in [Deploy manually](../README.md#-deploy-manually) or [Deploying with Docker](deploy-docker.md) + +- Configure the following [environment variables](environment-variables.md) before launching `big-AGI`: +```dotenv +HTTP_BASIC_AUTH_USERNAME= +HTTP_BASIC_AUTH_PASSWORD= +``` + +- Start the application + +## Cloud Deployments Authentication + +> This approach allows you to enable authentication without rebuilding the application by using the features +> provided by your cloud platform to manage user accounts and access. + +Many cloud deployment platforms offer built-in authentication mechanisms. Refer to the platform's documentation +for setup instructions: + +1. [CloudFlare Access / Zero Trust](https://www.cloudflare.com/zero-trust/products/access/) +2. [Vercel Authentication](https://vercel.com/docs/security/deployment-protection/methods-to-protect-deployments/vercel-authentication) +3. [Vercel Password Protection](https://vercel.com/docs/security/deployment-protection/methods-to-protect-deployments/password-protection) +4. Let us know when you test more solutions (Heroku, AWS IAM, Google IAP, etc.) diff --git a/docs/environment-variables.md b/docs/environment-variables.md index 785a96e1b..1272e5724 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -44,6 +44,10 @@ PUPPETEER_WSS_ENDPOINT= # Backend Analytics BACKEND_ANALYTICS= + +# Backend HTTP Basic Authentication +HTTP_BASIC_AUTH_USERNAME= +HTTP_BASIC_AUTH_PASSWORD= ``` ## Variables Documentation @@ -94,21 +98,23 @@ It is currently supported for: Enable the app to Talk, Draw, and Google things up. -| Variable | Description | -|:-------------------------|:------------------------------------------------------------------------------------------------------------------------| -| **Text-To-Speech** | [ElevenLabs](https://elevenlabs.io/) is a high quality speech synthesis service | -| `ELEVENLABS_API_KEY` | ElevenLabs API Key - used for calls, etc. | -| `ELEVENLABS_API_HOST` | Custom host for ElevenLabs | -| `ELEVENLABS_VOICE_ID` | Default voice ID for ElevenLabs | -| **Google Custom Search** | [Google Programmable Search Engine](https://programmablesearchengine.google.com/about/) produces links to pages | -| `GOOGLE_CLOUD_API_KEY` | Google Cloud API Key, used with the '/react' command - [Link to GCP](https://console.cloud.google.com/apis/credentials) | -| `GOOGLE_CSE_ID` | Google Custom/Programmable Search Engine ID - [Link to PSE](https://programmablesearchengine.google.com/) | -| **Text-To-Image** | [Prodia](https://prodia.com/) is a reliable image generation service | -| `PRODIA_API_KEY` | Prodia API Key - used with '/imagine ...' | -| **Browse** | | -| `PUPPETEER_WSS_ENDPOINT` | Puppeteer WebSocket endpoint - used for browsing, etc. | -| **Backend** | | -| `BACKEND_ANALYTICS` | Semicolon-separated list of analytics flags (see backend.analytics.ts). Flags: `domain` logs the responding domain. | +| Variable | Description | +|:---------------------------|:------------------------------------------------------------------------------------------------------------------------| +| **Text-To-Speech** | [ElevenLabs](https://elevenlabs.io/) is a high quality speech synthesis service | +| `ELEVENLABS_API_KEY` | ElevenLabs API Key - used for calls, etc. | +| `ELEVENLABS_API_HOST` | Custom host for ElevenLabs | +| `ELEVENLABS_VOICE_ID` | Default voice ID for ElevenLabs | +| **Google Custom Search** | [Google Programmable Search Engine](https://programmablesearchengine.google.com/about/) produces links to pages | +| `GOOGLE_CLOUD_API_KEY` | Google Cloud API Key, used with the '/react' command - [Link to GCP](https://console.cloud.google.com/apis/credentials) | +| `GOOGLE_CSE_ID` | Google Custom/Programmable Search Engine ID - [Link to PSE](https://programmablesearchengine.google.com/) | +| **Text-To-Image** | [Prodia](https://prodia.com/) is a reliable image generation service | +| `PRODIA_API_KEY` | Prodia API Key - used with '/imagine ...' | +| **Browse** | | +| `PUPPETEER_WSS_ENDPOINT` | Puppeteer WebSocket endpoint - used for browsing, etc. | +| **Backend** | | +| `BACKEND_ANALYTICS` | Semicolon-separated list of analytics flags (see backend.analytics.ts). Flags: `domain` logs the responding domain. | +| `HTTP_BASIC_AUTH_USERNAME` | Username for HTTP Basic Authentication. See the [Authentication](deploy-authentication.md) guide. | +| `HTTP_BASIC_AUTH_PASSWORD` | Password for HTTP Basic Authentication. | --- diff --git a/middleware.ts b/middleware.ts deleted file mode 100644 index 06c054a8c..000000000 --- a/middleware.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { NextRequest, NextResponse } from 'next/server' - -export const config = { - matcher: ['/', '/index', '/labs', '/launch', '/news', '/personas' ], -} - -export function middleware(req: NextRequest) { - const basicAuth = req.headers.get('authorization') - const url = req.nextUrl - - const envUsername = process.env.BASIC_AUTH_USERNAME - const envPassword = process.env.BASIC_AUTH_PASSWORD - - if (basicAuth) { - const authValue = basicAuth.split(' ')[1] - const [user, pwd] = atob(authValue).split(':') - - if (user === envUsername && pwd === envPassword) { - return NextResponse.next() - } - } - - // If the user is not authenticated, redirect to the auth page - url.pathname = '/api/auth/auth' - - return NextResponse.rewrite(url) -} \ No newline at end of file diff --git a/middleware_BASIC_AUTH.ts b/middleware_BASIC_AUTH.ts new file mode 100644 index 000000000..1bb820a14 --- /dev/null +++ b/middleware_BASIC_AUTH.ts @@ -0,0 +1,55 @@ +import type { NextRequest } from 'next/server'; +import { NextResponse } from 'next/server'; + + +// noinspection JSUnusedGlobalSymbols +/** + * Middleware to protect with HTTP Basic Authentication. + */ +export function middleware(request: NextRequest) { + + // Validate http basic auth configuration + if (!process.env.HTTP_BASIC_AUTH_USERNAME || !process.env.HTTP_BASIC_AUTH_PASSWORD) { + console.warn('HTTP Basic Authentication is enabled but not configured'); + return new Response('Unauthorized/Unconfigured', unauthResponse); + } + + // Request client authentication if no credentials are provided + const authHeader = request.headers.get('authorization'); + if (!authHeader?.startsWith('Basic ')) + return new Response('Unauthorized', unauthResponse); + + // Request authentication if credentials are invalid + const base64Credentials = authHeader.split(' ')[1]; + const credentials = Buffer.from(base64Credentials, 'base64').toString('ascii'); + const [username, password] = credentials.split(':'); + if ( + !username || !password || + username !== process.env.HTTP_BASIC_AUTH_USERNAME || + password !== process.env.HTTP_BASIC_AUTH_PASSWORD + ) + return new Response('Unauthorized', unauthResponse); + + return NextResponse.next(); +} + + +// Response to send when authentication is required +const unauthResponse: ResponseInit = { + status: 401, + headers: { + 'WWW-Authenticate': 'Basic realm="Secure big-AGI"', + }, +}; + +export const config = { + matcher: [ + // Include root + '/', + // Include pages + '/(call|index|news|personas|link)(.*)', + // Include API routes (the most important part to block) + '/api(.*)', + // Note: this excludes _next, /images etc.. + ], +}; \ No newline at end of file diff --git a/src/server/env.mjs b/src/server/env.mjs index 88be83455..40e218947 100644 --- a/src/server/env.mjs +++ b/src/server/env.mjs @@ -48,6 +48,10 @@ export const env = createEnv({ // Backend: Analytics flags (e.g. which hostname responds) for managed installs BACKEND_ANALYTICS: z.string().optional().transform(list => (list || '').split(';').filter(flag => !!flag)), + // Backend: HTTP Basic Authentication + HTTP_BASIC_AUTH_USERNAME: z.string().optional(), + HTTP_BASIC_AUTH_PASSWORD: z.string().optional(), + }, onValidationError: error => {