|
| 1 | +# Next.js with Together AI and LlamaIndex Integration |
| 2 | + |
| 3 | +This project demonstrates how to build a Next.js application that integrates Together AI and LlamaIndex for AI-powered functionalities. The project consists of a frontend built with Next.js and a backend service handling AI operations. |
| 4 | + |
| 5 | +## Project Structure |
| 6 | + |
| 7 | +- `frontend/`: Next.js frontend application |
| 8 | +- `backend/`: Node.js backend service with Together AI and LlamaIndex integration |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +- Node.js (LTS version) |
| 13 | +- Docker |
| 14 | +- Together AI API key |
| 15 | +- Restack Engine setup |
| 16 | + |
| 17 | +## Getting Started |
| 18 | + |
| 19 | +### 1. Install Restack Web UI |
| 20 | + |
| 21 | +First, install the Restack Web UI using Docker: |
| 22 | + |
| 23 | +```bash |
| 24 | +docker run -d --pull always --name studio -p 5233:5233 -p 6233:6233 -p 7233:7233 ghcr.io/restackio/restack:main |
| 25 | +``` |
| 26 | + |
| 27 | +### 2. Set Up Backend |
| 28 | + |
| 29 | +1. Navigate to the backend directory: |
| 30 | + |
| 31 | +```bash |
| 32 | +cd backend |
| 33 | +``` |
| 34 | + |
| 35 | +2. Install dependencies: |
| 36 | + |
| 37 | +```bash |
| 38 | +npm install |
| 39 | +``` |
| 40 | + |
| 41 | +3. Create a `.env` file with your credentials: |
| 42 | + |
| 43 | +``` |
| 44 | +TOGETHER_API_KEY=your_together_api_key |
| 45 | +
|
| 46 | +# Optional: |
| 47 | +RESTACK_ENGINE_ID=your_engine_id |
| 48 | +RESTACK_ENGINE_ADDRESS=your_engine_address |
| 49 | +RESTACK_ENGINE_API_KEY=your_engine_api_key |
| 50 | +``` |
| 51 | + |
| 52 | +4. Start the backend service: |
| 53 | + |
| 54 | +```bash |
| 55 | +npm run dev |
| 56 | +``` |
| 57 | + |
| 58 | +### 3. Set Up Frontend |
| 59 | + |
| 60 | +1. Navigate to the frontend directory: |
| 61 | + |
| 62 | +```bash |
| 63 | +cd frontend |
| 64 | +``` |
| 65 | + |
| 66 | +2. Install dependencies: |
| 67 | + |
| 68 | +```bash |
| 69 | +npm install |
| 70 | +``` |
| 71 | + |
| 72 | +3. (Optional) Create a `.env` file: |
| 73 | + |
| 74 | +``` |
| 75 | +# Optional: |
| 76 | +RESTACK_ENGINE_ID=your_engine_id |
| 77 | +RESTACK_ENGINE_ADDRESS=your_engine_address |
| 78 | +RESTACK_ENGINE_API_KEY=your_engine_api_key |
| 79 | +``` |
| 80 | + |
| 81 | +4. Start the development server: |
| 82 | + |
| 83 | +```bash |
| 84 | +npm run dev |
| 85 | +``` |
| 86 | + |
| 87 | +Visit [http://localhost:3000](http://localhost:3000) to see the application. |
| 88 | + |
| 89 | +## Available Features |
| 90 | + |
| 91 | +1. **Chat Completion Example**: Demonstrates basic chat completion using Together AI's Llama models |
| 92 | +2. **LlamaIndex Integration**: Shows how to query models using LlamaIndex with Together AI integration |
| 93 | + |
| 94 | +## Docker Deployment |
| 95 | + |
| 96 | +You can deploy both frontend and backend using Docker Compose: |
| 97 | + |
| 98 | +```bash |
| 99 | +docker-compose up -d |
| 100 | +``` |
| 101 | + |
| 102 | +This will: |
| 103 | + |
| 104 | +- Build and start the frontend on port 3000 |
| 105 | +- Build and start the backend on port 8000 |
| 106 | +- Set up proper networking between services |
| 107 | + |
| 108 | +## Deploy on Restack |
| 109 | + |
| 110 | +To deploy this application on Restack: |
| 111 | + |
| 112 | +1. Ensure you have Restack Cloud credentials |
| 113 | +2. Set up required environment variables |
| 114 | +3. Run the deployment script: |
| 115 | + |
| 116 | +```bash |
| 117 | +node restack_up.mjs |
| 118 | +``` |
| 119 | + |
| 120 | +For detailed deployment information, see the [Restack Cloud documentation](https://docs.restack.io/restack-cloud/deployrepo). |
| 121 | + |
| 122 | +## Project Components |
| 123 | + |
| 124 | +### Frontend |
| 125 | + |
| 126 | +- Next.js 14 application |
| 127 | +- Server Actions for workflow triggering |
| 128 | +- Tailwind CSS for styling |
| 129 | +- Type-safe API integration |
| 130 | + |
| 131 | +### Backend |
| 132 | + |
| 133 | +- Node.js backend service |
| 134 | +- Together AI integration for LLM operations |
| 135 | +- LlamaIndex for enhanced AI capabilities |
| 136 | +- Rate-limited API calls (60 RPM) |
| 137 | + |
| 138 | +## Example Workflows |
| 139 | + |
| 140 | +The application includes two main workflows: |
| 141 | + |
| 142 | +1. **Chat Completion Basic**: Generates greeting and farewell messages using Together AI models |
| 143 | +2. **LlamaIndex Together Simple**: Demonstrates LlamaIndex integration with Together AI for complex queries |
| 144 | + |
| 145 | +## Screenshots |
| 146 | + |
| 147 | + |
| 148 | +_Main application interface_ |
| 149 | + |
| 150 | + |
| 151 | +_Restack Web UI showing workflow execution_ |
| 152 | + |
| 153 | +## Contributing |
| 154 | + |
| 155 | +Feel free to submit issues and enhancement requests. |
0 commit comments