Skip to content

Commit

Permalink
Refactor and enhance configurations in prompty.ts and update script m…
Browse files Browse the repository at this point in the history
…odels in sample package
  • Loading branch information
pelikhan committed Sep 4, 2024
1 parent b30095c commit 2822fe4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
32 changes: 23 additions & 9 deletions packages/core/src/prompty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export interface PromptyFrontmatter {
outputs?: JSONSchemaObject
model?: {
api?: "chat" | "completion"
configuration?:
| { type?: string; name?: string; organization?: string }
| {
type?: string
api_version?: string
azure_deployment: string
azure_endpoint: string
}
configuration?: {
type?: string
name?: string
organization?: string
api_version?: string
azure_deployment: string
azure_endpoint: string
}
parameters?: {
response_format: "json_object"
max_tokens?: number
Expand Down Expand Up @@ -83,15 +83,29 @@ export function promptyParse(text: string): PromptyDocument {

export function promptyToGenAIScript(doc: PromptyDocument) {
const { frontmatter, messages } = doc
const { name, description, tags, sample, inputs, outputs } = frontmatter
const { name, description, tags, sample, inputs, outputs, model } =
frontmatter
const {
api = "chat",
configuration,

Check failure on line 90 in packages/core/src/prompty.ts

View workflow job for this annotation

GitHub Actions / build

The "api" variable is assigned a default value of "chat", but there is no handling for when the "api" value in the model is not "chat". This could lead to unexpected behavior.
parameters: modelParameters,
} = model ?? {}
const parameters = inputs ? structuredClone(inputs) : undefined
if (parameters && sample && typeof sample === "object")
for (const p in sample) {
const s = sample[p]
if (s !== undefined && parameters[p].type !== "object")
parameters[p].default = s
}

let modelName: string = undefined
if (api !== "chat") throw new Error("completion api not supported")
if (configuration?.azure_deployment)
modelName = `azure:${configuration.azure_deployment}`
else if (configuration?.type) modelName = `openai:${configuration.type}`

const meta = deleteUndefinedValues(<PromptArgs>{
model: modelName,
title: name,
description,
tags,
Expand Down
1 change: 1 addition & 0 deletions packages/sample/src/basic.genai.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
script({
model: "azure:gpt-4o",
title: "Basic Prompt",
description: "A basic prompt that uses the chat API to answer questions",
parameters: {
Expand Down
1 change: 1 addition & 0 deletions packages/sample/src/chat.genai.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
script({
model: "azure:gpt-35-turbo",
title: "Contoso Chat Prompt",
description: "A retail assistent for Contoso Outdoors products retailer.",
parameters: {
Expand Down

0 comments on commit 2822fe4

Please sign in to comment.