Skip to content

Commit

Permalink
feat: ✨ add model connection info resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Nov 13, 2024
1 parent d0868d9 commit 30d2440
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/cli/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ import {
} from "../../core/src/server/messages"
import { generatePromptFooConfiguration } from "../../core/src/test"
import { delay } from "es-toolkit"
import {
ModelConnectionInfo,
resolveModelConnectionInfo,
} from "../../core/src/models"

/**
* Parses model specifications from a string and returns a ModelOptions object.
Expand Down Expand Up @@ -72,9 +76,12 @@ function parseModelSpec(m: string): ModelOptions {
* @param script - The PromptScript object for which to determine the provider.
* @returns The resolved provider or undefined if not found.
*/
async function resolveTestProvider(script: PromptScript) {
const token = await host.getLanguageModelConfiguration(script.model)
if (token && token.type === "azure") return token.base
async function resolveTestProvider(info: ModelConnectionInfo) {
switch (info?.type) {
case "azure":
case "azure_serverless":
return info?.base
}
return undefined
}

Expand Down Expand Up @@ -147,13 +154,15 @@ export async function runPromptScriptTests(
? join(out, `${script.id}.promptfoo.yaml`)
: script.filename.replace(GENAI_ANY_REGEX, ".promptfoo.yaml")
logInfo(` ${fn}`)
const { info } = await resolveModelConnectionInfo(script)
if (info.error) throw new Error(info.error)
const testProvider =
options?.testProvider || (await resolveTestProvider(scripts[0]))
options?.testProvider || (await resolveTestProvider(info))
const config = generatePromptFooConfiguration(script, {
out,
cli,
model: options.model,
smallModel: options.smallModel,
model: info.model,
smallModel: info.smallModel,
models: options.models?.map(parseModelSpec),
provider: "provider.mjs",
testProvider,
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PromptScriptRunOptions } from "./server/messages"

/**
* Schema for a global configuration file
*/
export interface GenAIScriptConfiguration {
/**
* Path to the .env file
*/
env?: string

/**
* Common run options
*/
run?: PromptScriptRunOptions
}

0 comments on commit 30d2440

Please sign in to comment.