Skip to content

Commit 8a3dac0

Browse files
authored
Merge pull request #35 from restackio/nextjs-together-llamaindex
2 parents 22a66da + 54ac73a commit 8a3dac0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+12022
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
![Example UI](./restack-examples-ts-nextjs.png)
148+
_Main application interface_
149+
150+
![Success Web UI](./restack-examples-ts-nextjs-web-ui.png)
151+
_Restack Web UI showing workflow execution_
152+
153+
## Contributing
154+
155+
Feel free to submit issues and enhancement requests.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# (Required) Example-specific environment variables
2+
3+
TOGETHER_API_KEY=
4+
5+
# (Optional) Restack Cloud - You only need to set these if you are using Restack Cloud
6+
7+
RESTACK_ENGINE_ID=
8+
RESTACK_ENGINE_ADDRESS=
9+
RESTACK_ENGINE_API_KEY=
10+
11+
RESTACK_CLOUD_TOKEN=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Build stage
2+
FROM node:20-bullseye AS builder
3+
4+
WORKDIR /app
5+
6+
# Install pnpm
7+
RUN npm install -g pnpm
8+
9+
# Copy package files and env file if it exists
10+
COPY package*.json .env* ./
11+
12+
# Copy package files
13+
COPY package*.json ./
14+
15+
# Install dependencies including TypeScript
16+
RUN pnpm install
17+
RUN pnpm add -D typescript
18+
19+
# Copy source code
20+
COPY . .
21+
22+
# Build TypeScript code
23+
RUN pnpm run build
24+
25+
# Production stage
26+
FROM node:20-bullseye
27+
28+
WORKDIR /app
29+
30+
# Install pnpm
31+
RUN npm install -g pnpm
32+
33+
# Copy package files and built code
34+
COPY --from=builder /app/package*.json ./
35+
COPY --from=builder /app/dist ./dist
36+
37+
# Install production dependencies only
38+
RUN pnpm install --prod
39+
40+
EXPOSE 3000
41+
42+
CMD ["pnpm", "tsx", "dist/services.js"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "restack-examples-ts-nextjs-together-llamaindex-backend",
3+
"version": "0.0.1",
4+
"description": "Basic Node.js backend example for Next.js frontend using Together and LlamaIndex",
5+
"scripts": {
6+
"dev": "dotenv -e .env tsx watch --include src src/services.ts",
7+
"clean": "rm -rf node_modules",
8+
"build": "tsc --build",
9+
"docker:build": "docker build -t restack-nextjs-together-llamaindex-backend .",
10+
"docker:run": "docker run -p 8000:8000 --network restack-net --env-file .env --env RESTACK_ENGINE_ADDRESS=http://localhost:6233 restack-express-together-llamaindex",
11+
"docker:dev": "pnpm docker:build && pnpm docker:run"
12+
},
13+
"dependencies": {
14+
"@restackio/ai": "^0.0.81",
15+
"@temporalio/workflow": "^1.11.2",
16+
"dotenv": "^16.4.5",
17+
"dotenv-cli": "^7.4.1",
18+
"llamaindex": "^0.8.4",
19+
"together-ai": "^0.9.0",
20+
"tsx": "^4.19.2",
21+
"zod": "^3.23.8",
22+
"zod-to-json-schema": "^3.23.5"
23+
},
24+
"devDependencies": {
25+
"@restackio/restack-sdk-cloud-ts": "^1.0.16",
26+
"@types/express": "^5.0.0",
27+
"@types/node": "^20.16.9",
28+
"ts-node": "^10.9.2",
29+
"typescript": "^5.6.3"
30+
}
31+
}

0 commit comments

Comments
 (0)