You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -50,4 +66,86 @@ Open the application in your browser:
50
66
http://localhost:3000
51
67
```
52
68
53
-
To use the AI features, click on Settings in the dashboard and in put an Open AI API key
69
+
## Multi-tenancy
70
+
71
+
Create a Clerk project and set up these environment variables in your Next.js application:
72
+
73
+
```
74
+
# workspace ID for multi-tenant JWT tokens
75
+
TINYBIRD_WORKSPACE_ID=
76
+
# workspace admin token for multi-tenant JWT tokens
77
+
TINYBIRD_JWT_SECRET=
78
+
79
+
# Clerk publishable key
80
+
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
81
+
# Clerk secret key
82
+
CLERK_SECRET_KEY=
83
+
# Clerk sign in URL
84
+
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
85
+
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
86
+
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/
87
+
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/
88
+
```
89
+
90
+
The [middleware](https://github.com/tinybirdco/ai-analytics-template/blob/main/dashboard/ai-analytics/src/middleware.ts) will get the `org:name` permission from the Clerk user and use it to create a Tinybird JWT token with the `organization` dimension fixed to that value. Read more about Tinybird JWT tokens [here](https://www.tinybird.co/docs/forward/get-started/authentication#json-web-tokens-jwts).
91
+
92
+
[Watch a video of the Clerk + Tinybird JWT token flow](./assets/clerk-tinybird-jwt.mp4)
93
+
94
+
## AI features
95
+
96
+
To use the AI features, click on Settings in the dashboard and input an Open AI API key.
97
+
98
+
See the `search` and `extract-cost-parameters`[API routes](https://github.com/tinybirdco/ai-analytics-template/tree/main/dashboard/ai-analytics/src/app/api) for more details on how the AI features work.
99
+
100
+
[Watch a video of the AI cost calculator](./assets/ai-cost-calculator.mp4)
101
+
102
+
## Vector search
103
+
104
+
The vector search is powered by Tinybird, but embeddings need to be calculated in a separate process. See the [generate-embedding](https://github.com/tinybirdco/ai-analytics-template/blob/main/dashboard/ai-analytics/src/app/api/generate-embedding/route.ts) route for more details.
105
+
106
+
The process is:
107
+
108
+
- The user inputs a query and clicks the search button.
109
+
- The query is sent to the `generate-embedding` route to get the embedding.
110
+
- The embedding is sent to the Tinybird `llm_messages` as a query parameter.
111
+
-`llm_messages` use `cosineDistance` to find the most similar vectors.
112
+
- The frontend shows the table rows with the most similar vectors.
113
+
114
+
## Deployment
115
+
116
+
- Fork and connect this repository to Vercel.
117
+
- Set the environment variables in Vercel.
118
+
- Configure the [CI/CD GitHub actions](https://github.com/tinybirdco/ai-analytics-template/tree/main/.github/workflows) to deploy to Tinybird.
119
+
120
+
## Instrumentation
121
+
122
+
Check the examples folder for instrumentation examples for:
123
+
124
+
- LiteLLM (python)
125
+
- Vercel AI SDK (typescript)
126
+
127
+
## Mock data
128
+
129
+
For local testing, generate mock data with the following commands:
The [generate-llm-events.js](https://github.com/tinybirdco/ai-analytics-template/blob/main/tinybird/mock/generate-llm-events.js) script generates the embeddings.
138
+
139
+
## Contributing
140
+
141
+
Please open an issue or submit a pull request.
142
+
143
+
## Support
144
+
145
+
Join the Tinybird Slack community to get help with your project.
Copy file name to clipboardExpand all lines: dashboard/ai-analytics/README.md
-4Lines changed: 0 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,10 +16,6 @@ bun dev
16
16
17
17
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18
18
19
-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20
-
21
-
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22
-
23
19
## Learn More
24
20
25
21
To learn more about Next.js, take a look at the following resources:
Use the [CI/CD GitHub actions](https://github.com/tinybirdco/ai-analytics-template/tree/main/.github/workflows) in this repository to deploy to Tinybird or the Tinybird CLI:
0 commit comments