Skip to content

Commit f8317c5

Browse files
committed
round 4
1 parent aa4eb0c commit f8317c5

12 files changed

Lines changed: 57 additions & 28 deletions

File tree

packages/core/src/annotations.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ const SEV_EMOJI_MAP: Record<string, string> = Object.freeze({
5454
*
5555
* @param text Input text containing annotations to parse.
5656
* @returns Array of unique Diagnostic objects extracted from the input text.
57+
*
58+
* Extracts details such as file, line, severity, code, and message from annotations.
5759
*/
5860
export function parseAnnotations(text: string): Diagnostic[] {
5961
if (!text) return []
@@ -139,8 +141,8 @@ export function convertDiagnosticToGitHubActionCommand(d: Diagnostic) {
139141
/**
140142
* Converts a Diagnostic object to an Azure DevOps log issue command string.
141143
*
142-
* @param d - Diagnostic object containing severity, message, filename, and range.
143-
* @returns Formatted Azure DevOps command string for warnings and errors, or a debug message for info severity.
144+
* @param d Diagnostic object containing severity, message, filename, and range.
145+
* @returns Formatted Azure DevOps command string for warnings and errors, or a debug message for info severity. Includes filename and line number.
144146
*/
145147
export function convertDiagnosticToAzureDevOpsCommand(d: Diagnostic) {
146148
// Handle 'info' severity separately with a debug message.
@@ -154,7 +156,7 @@ export function convertDiagnosticToAzureDevOpsCommand(d: Diagnostic) {
154156
* Converts annotations in text to a Markdown representation with severity-based admonitions.
155157
*
156158
* @param text Input text containing annotations to convert.
157-
* @returns Formatted Markdown string with severity levels mapped to admonitions, including file and line references.
159+
* @returns Formatted Markdown string with severity levels mapped to admonitions, including file, line references, and optional codes.
158160
*/
159161
export function convertAnnotationsToMarkdown(text: string): string {
160162
// Maps severity levels to Markdown admonition types.

packages/core/src/ast.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export interface FileReference {
1818

1919
/**
2020
* Converts diagnostic data into a CSV-formatted string.
21-
* @param diagnostics - Array of diagnostic objects with severity, filename, range, code, and message.
22-
* @param sep - Separator string for CSV fields.
21+
* @param diagnostics - Array of diagnostic objects containing severity, filename, range, code, and message.
22+
* @param sep - String used to separate CSV fields.
2323
* @returns CSV string with each diagnostic entry on a new line.
2424
*/
2525
export function diagnosticsToCSV(diagnostics: Diagnostic[], sep: string) {
@@ -58,9 +58,9 @@ export const eofPosition: CharPosition = [0x3fffffff, 0] // End of file position
5858

5959
/**
6060
* Organizes templates by directory and identifies the presence of JavaScript or TypeScript files in each directory.
61-
* Filters out templates without filenames or matching the PROMPTY_REGEX.
62-
* @param prj - The project containing the scripts to process.
63-
* @returns An array of objects, each representing a directory with its name and flags indicating the presence of JavaScript and TypeScript files.
61+
* Filters out templates without filenames or those matching the PROMPTY_REGEX.
62+
* @param prj - The project containing the scripts to process, with each script having a filename property.
63+
* @returns Array of objects, each representing a directory with its name and flags indicating the presence of JavaScript and TypeScript files.
6464
*/
6565
export function collectFolders(prj: Project) {
6666
const folders: Record<
@@ -82,7 +82,7 @@ export function collectFolders(prj: Project) {
8282
/**
8383
* Finds a script in the project's scripts list by matching its ID with the system prompt instance.
8484
* @param prj - The project containing the scripts to search.
85-
* @param system - The system prompt instance with the script ID to match.
85+
* @param system - The system prompt instance containing the script ID to match.
8686
* @returns The matching script if found, otherwise undefined.
8787
*/
8888
export function resolveScript(prj: Project, system: SystemPromptInstance) {

packages/core/src/cleaners.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function unmarkdown(text: string) {
8484

8585
/**
8686
* Collapses sequences of three or more consecutive newlines into two consecutive newlines.
87-
* @param res Input string to process.
87+
* @param res The input string to process.
8888
*/
8989
export function collapseNewlines(res: string): string {
9090
return res?.replace(/(\r?\n){3,}/g, "\n\n")

packages/core/src/csv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function CSVTryParse(
8787
* Converts an array of objects into a CSV string.
8888
*
8989
* @param csv - Array of objects to convert to CSV format. Returns an empty string if the input is null or undefined.
90-
* @param options - Configuration for CSV stringification, including headers and delimiter settings.
90+
* @param options - Optional configuration for CSV stringification, including headers and delimiter settings.
9191
* @returns A CSV formatted string representation of the input data.
9292
*/
9393
export function CSVStringify(csv: object[], options?: CSVStringifyOptions) {

packages/core/src/file.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ import { prettyBytes } from "./pretty"
3636

3737
/**
3838
* Resolves the content of a file by decoding, fetching, or parsing it based on its type or source.
39+
*
3940
* @param file - The file object containing filename, content, type, and encoding.
4041
* @param options - Optional parameters for tracing, cancellation handling, and maximum file size.
42+
* - trace - Optional tracing object for logging operations.
43+
* - cancellationToken - Token to handle cancellation of the operation.
44+
* - maxFileSize - Maximum allowed file size for processing.
4145
* @returns The updated file object with resolved content or metadata.
4246
*/
4347
export async function resolveFileContent(
@@ -181,7 +185,7 @@ export function toWorkspaceFile(fileOrFilename: string | WorkspaceFile) {
181185
* Resolves the contents of multiple files asynchronously.
182186
* Iterates through the provided files, resolving their content based on type or source.
183187
* @param files - Array of files to process and resolve content for.
184-
* @param options - Optional parameters for tracing, cancellation handling, and file processing.
188+
* @param options - Optional parameters for tracing, cancellation handling, and maximum file size.
185189
*/
186190
export async function resolveFileContents(
187191
files: WorkspaceFile[],
@@ -251,7 +255,7 @@ export function dataUriToBuffer(filename: string) {
251255

252256
/**
253257
* Resolves and returns the file content as bytes.
254-
* @param filename - The file name, URL, data URI, or WorkspaceFile object to resolve.
258+
* @param filename - The file name, URL, data URI, or WorkspaceFile object to resolve. If a WorkspaceFile object, it uses its encoding and content if available.
255259
* @param options - Optional parameters for tracing and cancellation handling.
256260
* @returns A Uint8Array containing the file content as bytes.
257261
*/

packages/core/src/github.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,15 @@ export async function githubParseEnv(
148148
return Object.freeze(res)
149149
}
150150

151-
// https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#update-a-pull-request
151+
/**
152+
* // Updates the description of a pull request on GitHub.
153+
* // Parameters:
154+
* // - script: The script instance used to generate the footer.
155+
* // - info: Object containing apiUrl, repository, issue, and runUrl.
156+
* // - text: The new description text to update.
157+
* // - commentTag: Tag used to identify and merge the description.
158+
* // Returns an object indicating whether the update was successful and the status text.
159+
*/
152160
export async function githubUpdatePullRequestDescription(
153161
script: PromptScript,
154162
info: Pick<

packages/core/src/image.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export async function imageTransform(
180180
* Encodes an image for use in Language Learning Models (LLMs).
181181
*
182182
* @param url - The source of the image, which can be a URL, Buffer, or Blob.
183-
* @param options - Configuration for image processing, including detail level, trace settings, and cancellation handling.
183+
* @param options - Configuration for image processing, including detail level, trace settings, cancellation handling, and MIME type.
184184
* @returns A promise that resolves to the image encoded as a data URI.
185185
*/
186186
export async function imageEncodeForLLM(

packages/core/src/promptcontext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ const dbg = debug("genaiscript:promptcontext")
3939
* Creates a prompt context for the specified project, variables, trace, options, and model.
4040
*
4141
* @param prj The project for which the context is created.
42-
* @param ev Expansion variables including generator, output, debugging, and other configurations.
42+
* @param ev Expansion variables including generator, output, debugging, run directory, and other configurations.
4343
* @param trace Markdown trace for logging and debugging.
4444
* @param options Generation options such as cancellation tokens, embeddings models, and content safety.
4545
* @param model The model identifier used for context creation.
46-
* @returns A context object providing methods for file operations, web retrieval, searches, execution, and other utilities.
46+
* @returns A context object providing methods for file operations, web retrieval, searches, execution, container operations, and other utilities.
4747
*/
4848
export async function createPromptContext(
4949
prj: Project,

packages/core/src/promptdom.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ export interface FileOutputNode extends PromptNode {
214214
/**
215215
* Creates a text node with the specified value and optional context expansion options.
216216
*
217-
* @param value - The string value for the text node, must be defined and can be awaited.
217+
* @param value - The string value for the text node, must be defined.
218218
* @param options - Configuration for context expansion, applied if provided.
219+
* @returns A text node object with the specified value and options.
219220
*/
220221
export function createTextNode(
221222
value: Awaitable<string>,
@@ -397,7 +398,7 @@ ${trimNewlines(text)}
397398
/**
398399
* Creates a node representing an assistant message in a prompt.
399400
* @param value The content of the assistant message.
400-
* @param options Optional settings for context expansion.
401+
* @param options Optional settings for context expansion. Defaults to an empty object if not provided.
401402
*/
402403
export function createAssistantNode(
403404
value: Awaitable<string>,
@@ -421,6 +422,7 @@ export function createSystemNode(
421422
* @param strings - The template literal strings to include in the node.
422423
* @param args - The arguments to interpolate into the template.
423424
* @param options - Optional settings for context expansion or additional properties.
425+
* @returns The created string template node.
424426
*/
425427
export function createStringTemplateNode(
426428
strings: TemplateStringsArray,
@@ -440,8 +442,8 @@ export function createStringTemplateNode(
440442
/**
441443
* Creates an image node with the given value and optional context expansion options.
442444
*
443-
* @param value - The image data or prompt used to create the node.
444-
* @param options - Context expansion options to include in the node.
445+
* @param value - The image data or prompt used to create the node. Must not be undefined.
446+
* @param options - Optional context expansion options to include in the node.
445447
* @returns The created image node.
446448
*/
447449
export function createImageNode(
@@ -454,9 +456,10 @@ export function createImageNode(
454456

455457
/**
456458
* Creates a schema node with a specified name, value, and optional configuration.
459+
*
457460
* Parameters:
458-
* - name: The name of the schema node.
459-
* - value: The schema definition or a Zod type to be converted to JSON Schema.
461+
* - name: The name of the schema node. Must not be empty.
462+
* - value: The schema definition or a Zod type to be converted to JSON Schema. Automatically converts Zod types if applicable.
460463
* - options: Optional configuration for the schema node.
461464
*/
462465
export function createSchemaNode(
@@ -502,7 +505,8 @@ export function createFileMerge(fn: FileMergeHandler): PromptFileMergeNode {
502505
/**
503506
* Creates and returns an output processor node with a specified handler function.
504507
*
505-
* @param fn - Handler function to process prompt outputs. Must be defined.
508+
* @param fn - Handler function to process prompt outputs. Must be defined.
509+
* @returns An output processor node containing the handler function.
506510
*/
507511
export function createOutputProcessor(
508512
fn: PromptOutputProcessorHandler
@@ -514,6 +518,7 @@ export function createOutputProcessor(
514518
/**
515519
* Creates a node representing a chat participant.
516520
* @param participant - The chat participant to represent in the node.
521+
* @returns A node object representing the chat participant.
517522
*/
518523
export function createChatParticipant(
519524
participant: ChatParticipant
@@ -1216,10 +1221,10 @@ async function deduplicatePromptNode(trace: MarkdownTrace, root: PromptNode) {
12161221
* Parameters:
12171222
* - modelId: Identifier for the model.
12181223
* - node: The prompt node to render.
1219-
* - options: Optional configurations for model templates, tracing, and cancellation.
1224+
* - options: Optional configurations for model templates, tracing, cancellation, and token flexibility.
12201225
*
12211226
* Returns:
1222-
* - A rendered prompt node with associated metadata, messages, and resources.
1227+
* - A rendered prompt node with associated metadata, messages, resources, and disposables.
12231228
*/
12241229
export async function renderPromptNode(
12251230
modelId: string,

packages/core/src/promptfoo.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ function renderPurpose(script: PromptScript): string {
9494
*
9595
* @param script - The script containing prompt details, tests, and redteam configurations.
9696
* @param options - Configuration options including chatInfo, embeddingsInfo, provider, output settings, CLI settings, redteam settings, models, trace options, and cancellation options.
97+
* - chatInfo: Connection info and model aliases for chat models.
98+
* - embeddingsInfo: Connection info for embedding models.
99+
* - provider: The provider identifier.
100+
* - out: Output directory or file path.
101+
* - cli: CLI-specific settings.
102+
* - redteam: Whether redteam configurations are enabled.
103+
* - models: Array of model options and aliases.
104+
* - trace: Trace options for debugging.
105+
* - cancellation options: Options for handling cancellation.
97106
* @returns A configuration object for PromptFoo based on the provided script and options.
98107
*/
99108
export async function generatePromptFooConfiguration(

0 commit comments

Comments
 (0)