Skip to content

Commit

Permalink
Simplify prettier setup by moving to top-level (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonybaroneee authored and pavelgj committed May 1, 2024
1 parent 9da1715 commit bf6e71c
Show file tree
Hide file tree
Showing 60 changed files with 686 additions and 665 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ dist
.DS_Store
package-lock.json
js/third_party
.angular

# Discovery file (autogenerated by CLI)
genkit-tools/ui/src/assets/discovery.js

# Sample-specific files
genkit-packages
Expand All @@ -24,4 +28,4 @@ js/samples/rag/*.json
js/samples/cat-eval/__db*.json

# Test files
last_recording.mp4
last_recording.mp4
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go/
public/
.github/
.prettierrc.yaml
1 change: 1 addition & 0 deletions genkit-tools/.prettierrc.yaml → .prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

trailingComma: 'es5'
semi: true
singleQuote: true
bracketSameLine: true
cssDeclarationSorterOrder: 'alphabetical'
plugins: ['prettier-plugin-css-order', 'prettier-plugin-organize-imports']
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Genkit

Project Genkit is a code-first GenAI app development framework that empowers app developers to easily build production-ready AI apps and seamlessly deploy and monitor them with Google Cloud. It is composed of libraries and dev tools intended for development of server-side AI features.

64 changes: 32 additions & 32 deletions docs/_book.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@
# limitations under the License.

guides:
- title: Introduction
path: /genkit
- title: Get started
path: /genkit/get-started
- title: Configuration and plugins
path: /genkit/config
- title: Models
path: /genkit/models
- title: Prompt management
path: /genkit/dotprompt
- title: Flows
path: /genkit/flows
- title: Durable flows
path: /genkit/durable-flows
- title: Authorization and integrity
path: /genkit/auth
- title: Retrieval-augmented generation (RAG)
path: /genkit/rag
- title: Observability
path: /genkit/observability
- title: Evaluation
path: /genkit/evaluation
- title: Monitoring
path: /genkit/monitoring
- title: Developer tools
path: /genkit/devtools
- title: Deploy with Firebase
path: /genkit/firebase
- title: Deploy as an express.js app
path: /genkit/express
- title: Introduction
path: /genkit
- title: Get started
path: /genkit/get-started
- title: Configuration and plugins
path: /genkit/config
- title: Models
path: /genkit/models
- title: Prompt management
path: /genkit/dotprompt
- title: Flows
path: /genkit/flows
- title: Durable flows
path: /genkit/durable-flows
- title: Authorization and integrity
path: /genkit/auth
- title: Retrieval-augmented generation (RAG)
path: /genkit/rag
- title: Observability
path: /genkit/observability
- title: Evaluation
path: /genkit/evaluation
- title: Monitoring
path: /genkit/monitoring
- title: Developer tools
path: /genkit/devtools
- title: Deploy with Firebase
path: /genkit/firebase
- title: Deploy as an express.js app
path: /genkit/express
reference:
- title: Resource summary
path: /genkit/reference/coming-soon
- title: Resource summary
path: /genkit/reference/coming-soon
28 changes: 19 additions & 9 deletions docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,25 @@ receive an error:

```ts
// Error: Authorization required.
await runFlow(selfSummaryFlow, {uid: 'abc-def'});
await runFlow(selfSummaryFlow, { uid: 'abc-def' });

// Error: You may only summarize your own profile data.
await runFlow(selfSummaryFlow, {uid: 'abc-def'}, {
withLocalAuthContext: {uid: 'hij-klm'},
});
await runFlow(
selfSummaryFlow,
{ uid: 'abc-def' },
{
withLocalAuthContext: { uid: 'hij-klm' },
}
);

// Success
await runFlow(selfSummaryFlow, {uid: 'abc-def'}, {
withLocalAuthContext: {uid: 'abc-def'},
});
await runFlow(
selfSummaryFlow,
{ uid: 'abc-def' },
{
withLocalAuthContext: { uid: 'abc-def' },
}
);
```

You can also retrieve the auth context for the flow at any time within the flow
Expand Down Expand Up @@ -85,6 +93,7 @@ export const selfSummaryFlow = flow(

When testing flows with Genkit dev tools, you are able to specify this auth
object in the UI, or on the command line with the `--auth` flag:

```posix-terminal
genkit flow:run selfSummaryFlow '{"uid": "abc-def"}' --auth '{"uid": "abc-def"}'
```
Expand Down Expand Up @@ -200,7 +209,7 @@ alongside the native flows. You have two options:

1. Use whatever server framework you like, and pass the auth context through via
`runFlow()` as noted above.

1. Use the built-in `startFlowsServer()` and provide Express middleware in the
flow config:

Expand Down Expand Up @@ -232,8 +241,9 @@ alongside the native flows. You have two options:

startFlowsServer(); // This will register the middleware
```

For more information about using Express, see the [Cloud Run](/genkit/express)
instructions.

Please note, if you go with (1), you the `middleware` configuration option will
be ignored by `runFlow()`.
be ignored by `runFlow()`.
8 changes: 5 additions & 3 deletions docs/config.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Configuration and plugins

Genkit has a configuration and plugin system. Every Genkit app starts with
Expand All @@ -11,7 +10,10 @@ Here is an example you might have seen in some of the examples:
configureGenkit({
plugins: [
firebase({ projectId: getProjectId() }),
vertexAI({ projectId: getProjectId(), location: getLocation() || 'us-central1' }),
vertexAI({
projectId: getProjectId(),
location: getLocation() || 'us-central1',
}),
],
flowStateStore: 'firebase',
traceStore: 'firebase',
Expand All @@ -37,4 +39,4 @@ instrumentation and enable trace collection.

`logLevel` specifies the verbosity of framework-level logging. Sometimes it's
useful when troubleshooting to see more detailed log messages; set it to
`debug`.
`debug`.
3 changes: 1 addition & 2 deletions docs/devtools.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Dev tooling: local flow runner, playgrounds

You can run Genkit's developer tooling locally using the Genkit CLI:
Expand All @@ -17,4 +16,4 @@ Or resume flows:

```posix-terminal
npx genkit flow:resume myFlow FLOW_ID {"resume":"value"}
```
```
50 changes: 28 additions & 22 deletions docs/dotprompt.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Managing prompts with Dotprompt

Genkit provides the Dotprompt library and text format to help you write and
Expand Down Expand Up @@ -50,8 +49,8 @@ const greetingPrompt = await prompt('greeting');

const result = await greetingPrompt.generate({
input: {
location: "the beach",
style: "a fancy pirate",
location: 'the beach',
style: 'a fancy pirate',
},
});

Expand Down Expand Up @@ -96,7 +95,7 @@ const characterPrompt = await prompt('create_character');

const character = await characterPrompt.generate({
input: {
location: "the beach",
location: 'the beach',
},
});

Expand Down Expand Up @@ -152,11 +151,11 @@ The URL can be `https://` or base64-encoded `data:` URIs for "inline" image
usage. In code, this would be:

```ts
const describeImagePrompt = await prompt("describe_image");
const describeImagePrompt = await prompt('describe_image');

const result = await describeImagePrompt.generate({
input: {
photoUrl: "https://example.com/image.png",
photoUrl: 'https://example.com/image.png',
},
});

Expand All @@ -175,13 +174,13 @@ To create a variant, create a `[name].[variant].prompt` file. For instance, if
you were using GPT-3.5 Turbo in your prompt but wanted to see if Gemini 1.0 Pro
would perform better, you might create two files:

* `my_prompt.prompt`: the "baseline" prompt
* `my_prompt.gemini.prompt`: a variant named "gemini"
- `my_prompt.prompt`: the "baseline" prompt
- `my_prompt.gemini.prompt`: a variant named "gemini"

To use a prompt variant, specify the `variant` option when loading:

```ts
const myPrompt = await prompt('my_prompt', {variant: 'gemini'});
const myPrompt = await prompt('my_prompt', { variant: 'gemini' });
```

The prompt loader will attempt to load the variant of that name, and fall back
Expand All @@ -190,7 +189,7 @@ on whatever criteria makes sense for your application:

```ts
const myPrompt = await prompt('my_prompt', {
variant: isBetaTester(user) ? 'gemini' : null
variant: isBetaTester(user) ? 'gemini' : null,
});
```

Expand All @@ -203,15 +202,19 @@ inspector.
Dotprompt is optimized for organization in the prompt directory. However, there
are a few other ways to load and define prompts:

* `loadPromptFile`: Load a prompt from a file in the prompt directory.
* `loadPromptUrl`: Load a prompt from a URL.
* `definePrompt`: Define a prompt in code.
- `loadPromptFile`: Load a prompt from a file in the prompt directory.
- `loadPromptUrl`: Load a prompt from a URL.
- `definePrompt`: Define a prompt in code.

Examples:

```ts
import { loadPromptFile, loadPromptUrl, definePrompt } from "@genkit-ai/dotprompt";
import { z } from "zod";
import {
loadPromptFile,
loadPromptUrl,
definePrompt,
} from '@genkit-ai/dotprompt';
import { z } from 'zod';

// Load a prompt from a file
const myPrompt = await loadPromptFile('./path/to/my_prompt.prompt');
Expand All @@ -220,12 +223,15 @@ const myPrompt = await loadPromptFile('./path/to/my_prompt.prompt');
const myPrompt = await loadPromptUrl('https://example.com/my_prompt.prompt');

// Define a prompt in code
const myPrompt = definePrompt({
model: 'vertex-ai/gemini-1.0-pro',
input: {
schema: z.object({
name: z.string(),
})
const myPrompt = definePrompt(
{
model: 'vertex-ai/gemini-1.0-pro',
input: {
schema: z.object({
name: z.string(),
}),
},
},
}, `Hello {{name}}, how are you today?`);
`Hello {{name}}, how are you today?`
);
```
Loading

0 comments on commit bf6e71c

Please sign in to comment.