Skip to content

Commit decf1fa

Browse files
authored
Merge pull request #545 from DefangLabs/kevin/mastra-llm
2 parents 76a4122 + b4c378a commit decf1fa

8 files changed

Lines changed: 1412 additions & 61 deletions

File tree

.github/workflows/deploy-changed-samples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ jobs:
7979
TEST_DB_POSTGRESDB_SSL_ENABLED: ${{ secrets.TEST_DB_POSTGRESDB_SSL_ENABLED }}
8080
TEST_DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED: ${{ secrets.TEST_DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED }}
8181
TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
82-
TEST_GOOGLE_GENERATIVE_AI_API_KEY: ${{ secrets.TEST_GOOGLE_GENERATIVE_AI_API_KEY }}
8382
TEST_HASURA_GRAPHQL_ADMIN_SECRET: ${{ secrets.TEST_HASURA_GRAPHQL_ADMIN_SECRET }}
8483
TEST_HASURA_GRAPHQL_DATABASE_URL: ${{ secrets.TEST_HASURA_GRAPHQL_DATABASE_URL }}
8584
TEST_JUPYTER_TOKEN: ${{ secrets.TEST_JUPYTER_TOKEN }}
@@ -93,6 +92,7 @@ jobs:
9392
TEST_MODEL: ${{ secrets.TEST_MODEL }}
9493
TEST_MONGO_INITDB_ROOT_USERNAME: ${{ secrets.TEST_MONGO_INITDB_ROOT_USERNAME }}
9594
TEST_MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.TEST_MONGO_INITDB_ROOT_PASSWORD }}
95+
TEST_LLM_MODEL: ${{ secrets.TEST_LLM_MODEL }}
9696
TEST_N8N_ENCRYPTION_KEY: ${{ secrets.TEST_N8N_ENCRYPTION_KEY }}
9797
TEST_NC_DB: ${{ secrets.TEST_NC_DB }}
9898
TEST_NC_S3_ENDPOINT: ${{ secrets.TEST_NC_S3_ENDPOINT }}

samples/mastra-nextjs/.github/workflows/deploy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
- name: Deploy
2121
uses: DefangLabs/defang-github-action@v1.2.0
2222
with:
23-
config-env-vars: POSTGRES_PASSWORD GOOGLE_GENERATIVE_AI_API_KEY GITHUB_TOKEN
23+
config-env-vars: POSTGRES_PASSWORD LLM_MODEL GITHUB_TOKEN
2424
env:
2525
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
26+
LLM_MODEL: ${{ secrets.LLM_MODEL }}
2627
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27-
GOOGLE_GENERATIVE_AI_API_KEY: ${{ secrets.GOOGLE_GENERATIVE_AI_API_KEY }}

samples/mastra-nextjs/README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ To run the application locally for development, use the development compose file
2626
docker compose -f compose.dev.yaml up
2727
```
2828

29+
### `GOOGLE_GENERATIVE_AI_API_KEY`
30+
31+
When running locally with Docker Compose, you will need to set the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable to your GCP API key. You can get the API key from the [Google AI Studio](https://aistudio.google.com/).
32+
33+
### `LLM_MODEL`
34+
35+
When running locally with Docker Compose, you are limited to the models on this list: [Google models](https://mastra.ai/models/providers/google).
36+
2937
This will:
3038

3139
- Start PostgreSQL with volume persistence for local development
@@ -38,26 +46,26 @@ You can access mastra-nextjs at `http://localhost:3000` once the containers are
3846

3947
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration). Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
4048

41-
### `GOOGLE_GENERATIVE_AI_API_KEY`
42-
43-
Your Google Generative AI API key for accessing the Gemini Flash model. You can get this from the [Google AI Studio](https://aistudio.google.com/).
44-
4549
### `POSTGRES_PASSWORD`
4650

4751
The password for your Postgres database. You need to set this before deploying for the first time.
4852

4953
_You can easily set this to a random string using `defang config set POSTGRES_PASSWORD --random`_
5054

51-
### `DB_URL`
55+
### `LLM_MODEL`
56+
57+
_You can easily set this using `defang config set LLM_MODEL=<SELECTED_MODEL>`_
5258

53-
The [PostgreSQL database connection string](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING). This will be automatically configured when using BYOC managed database services. It should look something like this: `postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]`.
59+
The large language model to use for the AI-powered chat. This can be set to models like `anthropic.claude-3-5-sonnet-20241022-v2:0` for AWS or `gemini-2.5-flash` for Google Cloud. Here is a list of supported models for [GCP](https://ai-sdk.dev/providers/ai-sdk-providers/google-vertex#model-capabilities) and [AWS](https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock#model-capabilities). For AWS make sure you [request access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html) to the model in AWS Bedrock console and for GCP make sure you have [request access](https://docs.cloud.google.com/marketplace/docs/enable-ai-models#get-ai-models) to the model in GCP Vertex AI console.
5460

5561
### `DB_SSL`
5662

5763
Set to `true` to enable SSL. Set to `false` to disable SSL, which is used for Defang Playground. (Can be set directly in the Docker Compose file.)
5864

5965
### `GITHUB_TOKEN` (Optional)
6066

67+
_You can easily set this using `defang config set GITHUB_TOKEN=<YOUR_GITHUB_TOKEN>`_
68+
6169
A [GitHub personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token) to increase API rate limits when fetching repository data. This is optional but recommended for better performance.
6270
Setting the permissions to public repositories only is sufficient, unless you want to access private repositories that you have access to.
6371

@@ -89,6 +97,8 @@ The large context window of Gemini Flash allows the agent to hold more code in m
8997
9098
### Defang Playground
9199

100+
When deploying, the Playground environment is limited by resource constraints, so only Google Gemini flash or flash-lite models are supported. That said, I recommend using one of the flash models from this [list](https://ai-sdk.dev/providers/ai-sdk-providers/google-vertex#model-capabilities). If you want to use other models, please use [Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud).
101+
92102
Deploy your application to the Defang Playground by opening up your terminal and typing:
93103

94104
```bash

samples/mastra-nextjs/app/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
"lint": "next lint"
1111
},
1212
"dependencies": {
13+
"@ai-sdk/amazon-bedrock": "^3.0.67",
14+
"@ai-sdk/google-vertex": "^3.0.86",
15+
"@ai-sdk/provider": "^2.0.0",
1316
"@assistant-ui/react": "^0.11.39",
1417
"@assistant-ui/react-ai-sdk": "^1.1.11",
1518
"@assistant-ui/react-markdown": "^0.11.4",
19+
"@aws-sdk/credential-providers": "^3.946.0",
1620
"@mastra/ai-sdk": "^0.2.7",
1721
"@mastra/core": "^0.24.1",
1822
"@mastra/memory": "^0.15.11",

0 commit comments

Comments
 (0)