Skip to content

Dev #1545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 150 commits into from
May 27, 2025
Merged

Dev #1545

Changes from 1 commit
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
ab5142f
disk space script
pelikhan May 9, 2025
53768f2
add glossary script
pelikhan May 10, 2025
cbbc919
tweak
pelikhan May 10, 2025
5bbd404
✨ feat: improve glossary and add "tiny" model alias
pelikhan May 10, 2025
7af903a
updated glossary
pelikhan May 10, 2025
3f5fb78
✨ feat: revamp glossary and enhance GenAIScript features
pelikhan May 10, 2025
6e56ca2
✨ chore: Upgrade dependencies across multiple packages
pelikhan May 10, 2025
1aea590
Merge pull request #1542 from microsoft/glossary
pelikhan May 10, 2025
43af316
render description as markdown
pelikhan May 10, 2025
46e7b24
Add package manager selection support in CLI and refine Azure credent…
pelikhan May 12, 2025
8dbc1f0
Mcp-images (#1543)
pelikhan May 12, 2025
42473ab
Add metadata support to requests (#1548)
pelikhan May 13, 2025
a6219a2
Call tools (#1546)
pelikhan May 13, 2025
2472e30
✨: Enhance stored completions and metadata handling
pelikhan May 13, 2025
5b507b0
new line
pelikhan May 13, 2025
9f07efc
Release 1.136.0
pelikhan May 13, 2025
fe36d61
[skip ci] updated version numbers
pelikhan May 13, 2025
cbdc102
fix: regression in vscode copuilot chat support
pelikhan May 13, 2025
b2911b2
Release 1.136.1
pelikhan May 13, 2025
3bab921
[skip ci] updated version numbers
pelikhan May 13, 2025
bb84e21
✨: Add metadata handling support across components
pelikhan May 13, 2025
307f8eb
Release 1.136.2
pelikhan May 13, 2025
a99c748
[skip ci] updated version numbers
pelikhan May 13, 2025
bb9c94e
normalize metadata
pelikhan May 13, 2025
733d8c9
missing --yes
pelikhan May 13, 2025
e2d2288
Release 1.136.3
pelikhan May 13, 2025
2c10981
[skip ci] updated version numbers
pelikhan May 13, 2025
4373706
✨ feat: add runId to expansion variables for unique tracking
pelikhan May 13, 2025
e8c71fa
emphasize on create pr
pelikhan May 14, 2025
0980008
typo
pelikhan May 14, 2025
f5cc9b7
Use CLI for GitHub token resolution (#1550)
pelikhan May 14, 2025
e573385
3rd party license update
pelikhan May 14, 2025
53f6461
✨ chore: Update CI workflow and script configurations
pelikhan May 15, 2025
2c77279
:truck: Rename job to `generate-alt-text`
pelikhan May 15, 2025
8636654
fix image encoding
pelikhan May 15, 2025
6900073
Release 1.136.4
pelikhan May 15, 2025
aa385ba
[skip ci] updated version numbers
pelikhan May 15, 2025
dd49d51
:sparkles: Update workflows and refine logging mechanism
pelikhan May 15, 2025
b52df92
updated action
pelikhan May 15, 2025
c18f9d9
updated workflow
pelikhan May 15, 2025
7bbcf1d
handle github images
pelikhan May 15, 2025
380fd03
duplicate section
pelikhan May 15, 2025
4ab22ee
:fire: Remove unused file pattern in GitHub Action
pelikhan May 15, 2025
51df602
:construction: Adjust trace logic for CI environment
pelikhan May 15, 2025
a2e5d9f
Show UI element when no script is selected (#1551)
pelikhan May 15, 2025
207df95
es2024 (#1552)
pelikhan May 15, 2025
773b4ec
fix tokens
pelikhan May 15, 2025
fb9fd6f
Release 1.136.5
pelikhan May 15, 2025
39c1dc8
link to azure openai
pelikhan May 15, 2025
42bf584
✨ enhance: Add await to promiseExample invocation
pelikhan May 15, 2025
02ac6d1
Release 1.136.6
pelikhan May 15, 2025
34c6673
[skip ci] updated version numbers
pelikhan May 15, 2025
d10944a
:sparkles: Enhance logging for Azure token generation
pelikhan May 15, 2025
2137e97
fix docker docs
pelikhan May 15, 2025
26d7cb4
typos
pelikhan May 15, 2025
25de583
make iat more resilient
pelikhan May 15, 2025
2863098
updated prompts
pelikhan May 15, 2025
3838c9f
removing promptfoo dependency
pelikhan May 15, 2025
e35ef69
Release 1.136.7
pelikhan May 15, 2025
4b21c59
[skip ci] updated version numbers
pelikhan May 15, 2025
b6c6dbb
updated docs
pelikhan May 15, 2025
fc5f869
Removing-transformers (#1553)
pelikhan May 15, 2025
d4a87a2
add clean option
pelikhan May 15, 2025
d0413fe
✨ Add TestHost setup with beforeEach in tests
pelikhan May 15, 2025
4365858
Release 1.137.0
pelikhan May 15, 2025
d77039e
[skip ci] updated version numbers
pelikhan May 15, 2025
b37ef2a
updated pdf rendering outdated dependency (#1554)
pelikhan May 16, 2025
73aa1bb
fixing permissions
pelikhan May 16, 2025
d10b1e5
:sparkles: Enhance prettyValue API and update model selection
pelikhan May 16, 2025
e817c85
Release 1.137.1
pelikhan May 16, 2025
0cffe65
[skip ci] updated version numbers
pelikhan May 16, 2025
d6703b5
🎨 chore: add private field to package.json
pelikhan May 16, 2025
c6f0ca6
Support for parsing mermaid diagrams (#1538)
pelikhan May 16, 2025
66a4afd
Release 1.137.2
pelikhan May 16, 2025
5e98132
[skip ci] updated version numbers
pelikhan May 16, 2025
71fc490
clean command
pelikhan May 16, 2025
6f977a4
mermaid blog post
pelikhan May 16, 2025
59087b4
Release 1.137.3
pelikhan May 16, 2025
bf5e617
[skip ci] updated version numbers
pelikhan May 16, 2025
0a4dfce
✨ feat: add support for downloading workflow artifacts (#1555)
pelikhan May 16, 2025
c20cb2c
🚀: Refactor GitHub client to use a `normalizeInt` utility (#1556)
pelikhan May 16, 2025
2c096a6
:sparkles: Standardize blog metadata and enhance clarity
pelikhan May 16, 2025
53e25c0
✨ refactor CLI and VSCode functionalities
pelikhan May 16, 2025
10da5ff
Release 1.137.4
pelikhan May 16, 2025
58e6c3d
[skip ci] updated version numbers
pelikhan May 16, 2025
4090a64
Generate-image-retry (#1557)
pelikhan May 16, 2025
8c11f0f
Release 1.137.5
pelikhan May 16, 2025
102a4e4
[skip ci] updated version numbers
pelikhan May 16, 2025
eb49188
update prd
pelikhan May 16, 2025
c932e7e
renamed file
pelikhan May 16, 2025
7ac5cdf
move cross-fetch-oai in dependencies
pelikhan May 16, 2025
33d7cb5
✨: Update GenAIScript instructions to include ESM support
pelikhan May 16, 2025
383a97f
Release 1.137.6
pelikhan May 16, 2025
b88e21b
[skip ci] updated version numbers
pelikhan May 16, 2025
9a20104
more docs
pelikhan May 16, 2025
5df5547
rotate labels
pelikhan May 16, 2025
e9d79df
Release 1.137.7
pelikhan May 16, 2025
78e34e1
[skip ci] updated version numbers
pelikhan May 16, 2025
4038523
🎉 feat: add CI check to skip CLI trace generation
pelikhan May 17, 2025
ae35309
migration github models (#1558)
pelikhan May 17, 2025
7812af7
refresh lock files (#1559)
pelikhan May 17, 2025
dc134e4
✨ feat: clarify error handling for mermaid diagrams
pelikhan May 17, 2025
f6954ab
Release 1.138.0
pelikhan May 17, 2025
712967c
[skip ci] updated version numbers
pelikhan May 17, 2025
a77781c
approximate tokens for large strings (#1560)
pelikhan May 17, 2025
7c7cbf1
[genai] generated blog posts
pelikhan May 18, 2025
1914bb2
[genai] generated blog posts
pelikhan May 19, 2025
1b8028c
✨ Enhance message conversion logic with filtering (#1562)
pelikhan May 19, 2025
ca67735
Release 1.138.1
pelikhan May 19, 2025
d5d83db
[skip ci] updated version numbers
pelikhan May 19, 2025
51d6ba0
don't estimate tokens on message - too much compute
pelikhan May 19, 2025
59c9bfb
git pull (#1563)
pelikhan May 19, 2025
239cb54
Release 1.138.2
pelikhan May 19, 2025
fbdeb40
[skip ci] updated version numbers
pelikhan May 19, 2025
75f827f
wording
pelikhan May 19, 2025
5e75621
[genai] generated blog posts
pelikhan May 20, 2025
09284ff
✨ feat: add support for updating GitHub issues
pelikhan May 20, 2025
99ba7ed
Release 1.138.3
pelikhan May 20, 2025
ed0ab1e
[skip ci] updated version numbers
pelikhan May 20, 2025
b1f8c56
ignore .http files
pelikhan May 20, 2025
8774696
[genai] generated blog posts
pelikhan May 21, 2025
83f1532
✨ chore: update dependencies across multiple packages
pelikhan May 21, 2025
f35b8c5
🩹: Remove sensitive debug logging for tokens
pelikhan May 21, 2025
47f7941
✨: Improve body formatting in traceFetchPost
pelikhan May 21, 2025
744c97c
Release 1.138.4
pelikhan May 21, 2025
e294b8f
[skip ci] updated version numbers
pelikhan May 21, 2025
d4ec1fc
✨ chore: Update dependencies across multiple packages
pelikhan May 21, 2025
fad1a6a
Release 1.138.5
pelikhan May 21, 2025
e4c8567
[skip ci] updated version numbers
pelikhan May 21, 2025
8d81ea8
[genai] generated blog posts
pelikhan May 22, 2025
2027081
✨ refactor collectFolders to specify return type
pelikhan May 22, 2025
49e3fd2
don't fix node_modules (#1568)
pelikhan May 22, 2025
cf3ba03
✨ feat: add asset URL resolution for GitHub uploads (#1569)
pelikhan May 22, 2025
834b673
OpenAPI (#1571)
pelikhan May 23, 2025
e2ff5e8
Release 1.139.0
pelikhan May 23, 2025
7bd372c
[skip ci] updated version numbers
pelikhan May 23, 2025
1335c46
complete the sentence (#1572)
mrjf May 24, 2025
7b96f4c
web api improvements (#1573)
pelikhan May 24, 2025
750a135
✨ refactor: simplify OpenAPI server schema check logic
pelikhan May 24, 2025
c6bad43
[genai] generated blog posts
pelikhan May 25, 2025
30c850a
[genai] generated blog posts
pelikhan May 26, 2025
a199d13
use query argument in openapi
pelikhan May 26, 2025
da4a1a8
✨ enhance: refine OpenAPI server schemas and handlers
pelikhan May 26, 2025
03d5ed8
[genai] generated blog posts
pelikhan May 27, 2025
35cc515
require node v22
pelikhan May 27, 2025
d984d71
add dev container info
pelikhan May 27, 2025
e8966c1
split configuration page (#1576)
pelikhan May 27, 2025
c34948e
added docker model runner
pelikhan May 27, 2025
900f286
Release 1.140.0
pelikhan May 27, 2025
b674bab
[skip ci] updated version numbers
pelikhan May 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add metadata support to requests (#1548)
* add metadata/store to requests

* ✨ Add metadata handling for caching and completions

Introduced metadata support for enhanced caching and API queries.

* ✨ refactor chat storage logic in session execution

Simplified assignment of `store` variable by refining metadata check.
  • Loading branch information
pelikhan authored May 13, 2025
commit 42473ab0439c6fa34aae5ac96993ca6cf9b69a87
6 changes: 1 addition & 5 deletions demo/genaisrc/haiku.genai.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
script({ model: "echo"})
script({ metadata: { name: "haiku" } })
$`Write a haiku about code`
await env.output.image(
"https://github.com/microsoft/genaiscript/blob/main/docs/public/images/favicon.png?raw=true",
"icon"
)
4 changes: 4 additions & 0 deletions docs/public/schemas/llms.json
Original file line number Diff line number Diff line change
@@ -124,6 +124,10 @@
"type": "boolean",
"description": "Indicates if the provider uses a single model"
},
"metadata": {
"type": "boolean",
"description": "Indicates if metadata is supported along with 'store' field"
},
"aliases": {
"type": "object",
"description": "List of model aliases for the provider",
21 changes: 21 additions & 0 deletions docs/src/content/docs/reference/scripts/medata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: Metadata
description: Metadata for the script
keywords: [metadata, script]
sidebar:
order: 110
---

Metadata is a map of key-value pairs that is used to enable stored completions. A feature in OpenAI and Azure OpenAI that allows you to store and retrieve completions for a given prompt. This is used for distillation and evaluation purposes.

```js
script({
metadata: {
name: "my_script",
},
})
```

Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.

Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
9 changes: 9 additions & 0 deletions packages/core/src/chat.ts
Original file line number Diff line number Diff line change
@@ -1190,6 +1190,7 @@ export async function executeChatSession(
topLogprobs,
cache,
inner,
metadata,
partialCb,
} = genOptions
assert(!!model, "model is required")
@@ -1228,6 +1229,7 @@ export async function executeChatSession(
? getChatCompletionCache(typeof cache === "string" ? cache : "chat")
: undefined
const chatTrace = trace.startTraceDetails(`💬 chat`, { expanded: true })
const store = !!metadata ? true : undefined
const timer = measure("chat")
const cacheImage = async (url: string) =>
await fileCacheImage(url, {
@@ -1287,6 +1289,8 @@ export async function executeChatSession(
req = {
model,
temperature,
store,
metadata: store ? metadata : undefined,
reasoning_effort: reasoningEffort,
top_p: topP,
tool_choice:
@@ -1499,6 +1503,11 @@ function updateChatFeatures(
req.max_completion_tokens = req.max_tokens
delete req.max_tokens
}
if (req.store && !features?.metadata) {
dbg(`metadata: disabled, not supported by ${provider}`)
delete req.metadata
delete req.store
}

deleteUndefinedValues(req)
}
3 changes: 2 additions & 1 deletion packages/core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -248,6 +248,7 @@ export const MODEL_PROVIDERS = Object.freeze<
hidden?: boolean
imageGeneration?: boolean
singleModel?: boolean
metadata?: boolean
responseType?: "json" | "json_object" | "json_schema"
reasoningEfforts?: Record<string, number>
aliases?: Record<string, string>
@@ -443,4 +444,4 @@ export const CACHE_SHA_LENGTH = 32
export const MCP_RESOURCE_PROTOCOL = TOOL_ID

export const RESOURCE_MAX_SIZE = 1024 * 1024 * 10 // 10MB
export const MIN_NODE_VERSION_MAJOR = 20
export const MIN_NODE_VERSION_MAJOR = 20
3 changes: 3 additions & 0 deletions packages/core/src/expander.ts
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ import { installGlobalPromptContext } from "./globals"
import { mark } from "./performance"
import { nodeIsPackageTypeModule } from "./nodepackage"
import { parseModelIdentifier } from "./models"
import { metadataMerge } from "./metadata"

/**
* Executes a prompt expansion process based on the provided prompt script, variables, and options.
@@ -253,6 +254,7 @@ export async function expandTemplate(
template.flexTokens
const fenceFormat = options.fenceFormat ?? template.fenceFormat
const cache = options.cache ?? template.cache
const metadata = metadataMerge(template.metadata, options.metadata)
let seed = options.seed ?? normalizeInt(env.vars["seed"]) ?? template.seed
if (seed !== undefined) seed = seed >> 0
let logprobs = options.logprobs || template.logprobs
@@ -445,6 +447,7 @@ export async function expandTemplate(
logprobs,
topLogprobs,
disposables,
metadata,
fallbackTools: options.fallbackTools,
}
}
4 changes: 2 additions & 2 deletions packages/core/src/generation.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,8 @@ export interface GenerationOptions
ModelOptions,
EmbeddingsModelOptions,
ContentSafetyOptions,
ScriptRuntimeOptions {
ScriptRuntimeOptions,
MetadataOptions {
inner: boolean // Indicates if the process is an inner operation
runId?: string
runDir?: string
@@ -26,7 +27,6 @@ export interface GenerationOptions
outputTrace?: MarkdownTrace
maxCachedTemperature?: number // Maximum temperature for caching purposes
maxCachedTopP?: number // Maximum top-p value for caching
fallbackTools?: boolean // Disables model tools
label?: string // Optional label for the operation
cliInfo?: {
files: string[] // Information about files in the CLI context
2 changes: 2 additions & 0 deletions packages/core/src/llms.json
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
"listModels": true,
"imageGeneration": true,
"responseFormat": "json_schema",
"metadata": true,
"aliases": {
"large": "gpt-4.1",
"small": "gpt-4.1-mini",
@@ -58,6 +59,7 @@
"speech": true,
"imageGeneration": true,
"aliases": {},
"metadata": true,
"models": {
"o1-preview": {
"tools": false
28 changes: 28 additions & 0 deletions packages/core/src/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export function metadataValidate(
metadata: Record<string, string>
): Record<string, string> | undefined {
if (!metadata) return undefined
const entries = Object.entries(metadata)
if (entries.length > 16)
throw new Error("Metadata can only have 16 entries")
for (const [key, value] of entries) {
if (typeof key !== "string" || key.length > 64)
throw new Error("Invalid metadata key")
if (typeof value !== "string" || value.length > 512)
throw new Error("Invalid metadata value")
}
return metadata
}

export function metadataMerge(
source: Record<string, string> | undefined,
update: Record<string, string> | undefined
): Record<string, string> | undefined {
if (!source) return update
if (!update) return source
const res = {
...(source || {}),
...(update || {}),
}
return metadataValidate(res)
}
2 changes: 2 additions & 0 deletions packages/core/src/promptrunner.ts
Original file line number Diff line number Diff line change
@@ -188,6 +188,7 @@ export async function runTemplate(
topLogprobs,
disposables,
cache,
metadata
} = await expandTemplate(prj, template, options, env)
const { output, generator, secrets, dbg: envDbg, ...restEnv } = env

@@ -279,6 +280,7 @@ export async function runTemplate(
logprobs,
topLogprobs,
fallbackTools,
metadata,
stats: runStats,
}
const chatResult = await executeChatSession(
5 changes: 4 additions & 1 deletion packages/core/src/template.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ import { host } from "./host"
import { JSON5TryParse } from "./json5"
import { humanize } from "./inflection"
import { promptyParse, promptyToGenAIScript } from "./prompty"
import { metadataValidate } from "./metadata"
import { deleteUndefinedValues } from "./cleaners"

/**
* Extracts a template ID from the given filename by removing specific extensions
@@ -45,7 +47,8 @@ export function parsePromptScriptMeta(
meta.group = meta.group || "system"
}
meta.defTools = parsePromptScriptTools(jsSource)
return meta
meta.metadata = metadataValidate(meta.metadata)
return deleteUndefinedValues(meta)
}

function parsePromptScriptTools(jsSource: string) {
13 changes: 12 additions & 1 deletion packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
@@ -783,6 +783,15 @@ interface McpToolAnnotations {
}
}

interface MetadataOptions {
/**
* Set of 16 key-value pairs that can be attached to an object.
* This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
* Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
*/
metadata?: Record<string, string>
}

interface PromptScript
extends PromptLike,
ModelOptions,
@@ -793,7 +802,8 @@ interface PromptScript
SecretDetectionOptions,
GitIgnoreFilterOptions,
ScriptRuntimeOptions,
McpToolAnnotations {
McpToolAnnotations,
MetadataOptions {
/**
* Which provider to prefer when picking a model.
*/
@@ -1774,6 +1784,7 @@ type PromptSystemArgs = Omit<
| "files"
| "modelConcurrency"
| "redteam"
| "metadata"
>

type StringLike = string | WorkspaceFile | WorkspaceFile[]
6 changes: 6 additions & 0 deletions packages/sample/genaisrc/metadata.genai.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
script({
metadata: { name: "metadata", tool: "genaiscript" },
temperature: 1,
})

$`Write a joke in emojis.`
Loading
Oops, something went wrong.