From df02eda297b360844e3544935a752030e6fadf1f Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Wed, 18 Mar 2026 18:23:18 +0800 Subject: [PATCH] [docs/dart] Fix rendering of various lists --- .../docs/docs/deployment/any-platform.mdx | 108 +++++++++--------- .../docs/docs/deployment/cloud-run.mdx | 30 ++--- src/content/docs/docs/frameworks/shelf.mdx | 26 ++--- .../docs/docs/integrations/google-genai.mdx | 26 ++--- .../docs/docs/integrations/vertex-ai.mdx | 28 ++--- src/content/docs/docs/local-observability.mdx | 12 +- 6 files changed, 115 insertions(+), 115 deletions(-) diff --git a/src/content/docs/docs/deployment/any-platform.mdx b/src/content/docs/docs/deployment/any-platform.mdx index 8a89473d..6601a717 100644 --- a/src/content/docs/docs/deployment/any-platform.mdx +++ b/src/content/docs/docs/deployment/any-platform.mdx @@ -463,80 +463,80 @@ You can deploy Genkit flows as web services using any platform that can host a D 1. Create a directory for the Genkit sample project: -```bash -mkdir -p ~/tmp/genkit-any-project -cd ~/tmp/genkit-any-project -``` + ```bash + mkdir -p ~/tmp/genkit-any-project + cd ~/tmp/genkit-any-project + ``` 2. Initialize a Dart project: -```bash -dart create -t console-simple . -``` + ```bash + dart create -t console-simple . + ``` 3. Add Genkit dependencies: -```bash -dart pub add genkit genkit_shelf shelf shelf_router genkit_google_genai -``` + ```bash + dart pub add genkit genkit_shelf shelf shelf_router genkit_google_genai + ``` 4. Create a sample app using Genkit and Shelf: -```dart title="bin/server.dart" -import 'dart:io'; -import 'package:genkit/genkit.dart'; -import 'package:genkit_shelf/genkit_shelf.dart'; -import 'package:genkit_google_genai/genkit_google_genai.dart'; -import 'package:shelf/shelf.dart'; -import 'package:shelf/shelf_io.dart' as io; -import 'package:shelf_router/shelf_router.dart'; -import 'package:schemantic/schemantic.dart'; - -void main() async { - final ai = Genkit( - plugins: [googleAI(apiKey: Platform.environment['GOOGLE_API_KEY'])], - model: googleAI.gemini('gemini-2.5-flash'), - ); - - final flow = ai.defineFlow( - name: 'flow', - fn: (String input, _) async => 'Processed $input', - inputSchema: .string(), - outputSchema: .string(), - ); - - final router = Router(); - // Mount the flow handler - router.post('/flow', shelfHandler(flow)); - - // Create a handler pipeline (e.g., adding logging) - final handler = const Pipeline() - .addMiddleware(logRequests()) - .addHandler(router.call); - - // Start the server - final port = int.parse(Platform.environment['PORT'] ?? '8080'); - final server = await io.serve(handler, InternetAddress.anyIPv4, port); - print('Server running on port ${server.port}'); -} -``` + ```dart title="bin/server.dart" + import 'dart:io'; + import 'package:genkit/genkit.dart'; + import 'package:genkit_shelf/genkit_shelf.dart'; + import 'package:genkit_google_genai/genkit_google_genai.dart'; + import 'package:shelf/shelf.dart'; + import 'package:shelf/shelf_io.dart' as io; + import 'package:shelf_router/shelf_router.dart'; + import 'package:schemantic/schemantic.dart'; + + void main() async { + final ai = Genkit( + plugins: [googleAI(apiKey: Platform.environment['GOOGLE_API_KEY'])], + model: googleAI.gemini('gemini-2.5-flash'), + ); + + final flow = ai.defineFlow( + name: 'flow', + fn: (String input, _) async => 'Processed $input', + inputSchema: .string(), + outputSchema: .string(), + ); + + final router = Router(); + // Mount the flow handler + router.post('/flow', shelfHandler(flow)); + + // Create a handler pipeline (e.g., adding logging) + final handler = const Pipeline() + .addMiddleware(logRequests()) + .addHandler(router.call); + + // Start the server + final port = int.parse(Platform.environment['PORT'] ?? '8080'); + final server = await io.serve(handler, InternetAddress.anyIPv4, port); + print('Server running on port ${server.port}'); + } + ``` 5. **Compile for Deployment**: Dart applications can be compiled into self-contained executables (AOT compilation), which makes them easy to deploy without needing the full Dart SDK on the target server. -```bash -dart compile exe bin/server.dart -o server -``` + ```bash + dart compile exe bin/server.dart -o server + ``` The resulting `server` file is a standalone executable (on the same architecture). 6. **Deploy**: - Upload the `server` executable to your hosting provider and configure it to run. Ensure you set the necessary environment variables: + Upload the `server` executable to your hosting provider and configure it to run. Ensure you set the necessary environment variables: - - `PORT`: The port your server should listen on (defaults to 8080 in the code above). - - `GOOGLE_API_KEY`: Your Google GenAI API key. + - `PORT`: The port your server should listen on (defaults to 8080 in the code above). + - `GOOGLE_API_KEY`: Your Google GenAI API key. diff --git a/src/content/docs/docs/deployment/cloud-run.mdx b/src/content/docs/docs/deployment/cloud-run.mdx index a93a48e4..ecffa981 100644 --- a/src/content/docs/docs/deployment/cloud-run.mdx +++ b/src/content/docs/docs/deployment/cloud-run.mdx @@ -452,9 +452,9 @@ You can easy deploy your Genkit Dart flows to Cloud Run as a containerized servi 2. Link the project to a billing account. 3. Configure the Google Cloud CLI: -```bash -gcloud init -``` + ```bash + gcloud init + ``` ## 2. Prepare your Dart project @@ -531,21 +531,21 @@ Most flows require API keys (like `GOOGLE_API_KEY` for Gemini). You should use [ 1. Create a secret for your API key: -```bash -gcloud secrets create google-api-key --data-file=- -# (Press Enter, paste your API key, then press Ctrl+D) -``` + ```bash + gcloud secrets create google-api-key --data-file=- + # (Press Enter, paste your API key, then press Ctrl+D) + ``` 2. Deploy the service, referencing the secret: -```bash -gcloud run deploy genkit-server \ - --source . \ - --port 3400 \ - --allow-unauthenticated \ - --region us-central1 \ - --set-secrets GOOGLE_API_KEY=google-api-key:latest -``` + ```bash + gcloud run deploy genkit-server \ + --source . \ + --port 3400 \ + --allow-unauthenticated \ + --region us-central1 \ + --set-secrets GOOGLE_API_KEY=google-api-key:latest + ``` _Note: Replace `3400` with your default port if different, but Cloud Run defaults to passing 8080 as `PORT` env var, which your code should respect._ diff --git a/src/content/docs/docs/frameworks/shelf.mdx b/src/content/docs/docs/frameworks/shelf.mdx index eef4b915..bc8d0a7d 100644 --- a/src/content/docs/docs/frameworks/shelf.mdx +++ b/src/content/docs/docs/frameworks/shelf.mdx @@ -199,18 +199,18 @@ Since a Genkit Shelf application is just a standard Dart HTTP server, you can de 1. **Create a Dockerfile**: -```dockerfile -FROM dart:stable AS build -WORKDIR /app -COPY pubspec.* ./ -RUN dart pub get -COPY . . -RUN dart compile exe bin/server.dart -o bin/server - -FROM scratch -COPY --from=build /runtime/ / -COPY --from=build /app/bin/server /app/bin/ -CMD ["/app/bin/server"] -``` + ```dockerfile + FROM dart:stable AS build + WORKDIR /app + COPY pubspec.* ./ + RUN dart pub get + COPY . . + RUN dart compile exe bin/server.dart -o bin/server + + FROM scratch + COPY --from=build /runtime/ / + COPY --from=build /app/bin/server /app/bin/ + CMD ["/app/bin/server"] + ``` 2. **Build and Deploy** (e.g., using Cloud Build and Cloud Run). diff --git a/src/content/docs/docs/integrations/google-genai.mdx b/src/content/docs/docs/integrations/google-genai.mdx index 7a7e2ea2..4ebe9fb0 100644 --- a/src/content/docs/docs/integrations/google-genai.mdx +++ b/src/content/docs/docs/integrations/google-genai.mdx @@ -1112,19 +1112,19 @@ void main() { Requires a Gemini API Key, which you can get from [Google AI Studio](https://aistudio.google.com/apikey). -1. **Environment variables**: Set `GEMINI_API_KEY` -2. **Plugin configuration**: Pass `apiKey` when initializing the plugin (shown above) -3. **Per-request**: Override the API key for specific requests in the config: - -```dart -final response = await ai.generate( - model: googleAI.gemini('gemini-2.5-flash'), - prompt: 'Your prompt here', - config: GeminiOptions( - apiKey: 'different-api-key', // Use a different API key for this request - ), -); -``` +1. **Environment variables**: Set `GEMINI_API_KEY` +2. **Plugin configuration**: Pass `apiKey` when initializing the plugin (shown above) +3. **Per-request**: Override the API key for specific requests in the config: + + ```dart + final response = await ai.generate( + model: googleAI.gemini('gemini-2.5-flash'), + prompt: 'Your prompt here', + config: GeminiOptions( + apiKey: 'different-api-key', // Use a different API key for this request + ), + ); + ``` ## Language Models diff --git a/src/content/docs/docs/integrations/vertex-ai.mdx b/src/content/docs/docs/integrations/vertex-ai.mdx index 80ad7a39..917e49d4 100644 --- a/src/content/docs/docs/integrations/vertex-ai.mdx +++ b/src/content/docs/docs/integrations/vertex-ai.mdx @@ -42,33 +42,33 @@ The plugin requires you to specify your Google Cloud project ID, the [region](ht You can also pass this value directly: -```dart -vertexAI(projectId: 'my-project-id') -``` + ```dart + vertexAI(projectId: 'my-project-id') + ``` - By default, `vertexAI` gets the Vertex AI API location from the `GCLOUD_LOCATION` environment variable. You can also pass this value directly: -```dart -vertexAI(location: 'us-central1') -``` + ```dart + vertexAI(location: 'us-central1') + ``` - To provide API credentials, you need to set up Google Cloud Application Default Credentials. - 1. To specify your credentials: + 1. To specify your credentials: - - If you're running your flow from a Google Cloud environment (Cloud Functions, Cloud Run, and so on), this is set automatically. + - If you're running your flow from a Google Cloud environment (Cloud Functions, Cloud Run, and so on), this is set automatically. - - On your local dev environment, do this by running: + - On your local dev environment, do this by running: -```shell -gcloud auth application-default login -``` + ```shell + gcloud auth application-default login + ``` - - For other environments, see the [Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) docs. + - For other environments, see the [Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) docs. -2. In addition, make sure the account is granted the Vertex AI User IAM role (`roles/aiplatform.user`). See the Vertex AI [access control](https://cloud.google.com/vertex-ai/generative-ai/docs/access-control) docs. + 2. In addition, make sure the account is granted the Vertex AI User IAM role (`roles/aiplatform.user`). See the Vertex AI [access control](https://cloud.google.com/vertex-ai/generative-ai/docs/access-control) docs. ## Usage diff --git a/src/content/docs/docs/local-observability.mdx b/src/content/docs/docs/local-observability.mdx index eaa25c12..06e18fcb 100644 --- a/src/content/docs/docs/local-observability.mdx +++ b/src/content/docs/docs/local-observability.mdx @@ -22,14 +22,14 @@ Logs are automatically correlated with the current trace context when using `Zon To view traces locally: -1. Start the Genkit Developer UI: +1. Start the Genkit Developer UI: -```bash -genkit start -- dart run -``` + ```bash + genkit start -- dart run + ``` -2. Run your flow or action. -3. Open the Developer UI (typically at `http://localhost:4000`) to view traces and metrics. +2. Run your flow or action. +3. Open the Developer UI (typically at `http://localhost:4000`) to view traces and metrics.