Merge branch 'main' into sgoedecke/use-openai-sdk
This commit is contained in:
@@ -130,6 +130,49 @@ model: openai/gpt-4o
|
||||
expect(core.setOutput).toHaveBeenCalledWith('response-file', expect.any(String))
|
||||
})
|
||||
|
||||
it('supports file_input variables to load file contents', async () => {
|
||||
mockExistsSync.mockReturnValue(true)
|
||||
|
||||
// First call: reading the prompt file. Second call: reading file_input referenced file contents.
|
||||
const externalFilePath = 'vars.txt'
|
||||
mockReadFileSync.mockImplementation((path: string) => {
|
||||
if (path === 'test.prompt.yml') {
|
||||
return `messages:\n - role: user\n content: 'Here is the data: {{blob}}'\nmodel: openai/gpt-4o\n`
|
||||
}
|
||||
if (path === externalFilePath) {
|
||||
return 'FILE_CONTENTS'
|
||||
}
|
||||
return ''
|
||||
})
|
||||
|
||||
core.getInput.mockImplementation((name: string) => {
|
||||
switch (name) {
|
||||
case 'prompt-file':
|
||||
return 'test.prompt.yml'
|
||||
case 'file_input':
|
||||
return `blob: ${externalFilePath}`
|
||||
case 'model':
|
||||
return 'openai/gpt-4o'
|
||||
case 'max-tokens':
|
||||
return '200'
|
||||
case 'endpoint':
|
||||
return 'https://models.github.ai/inference'
|
||||
case 'enable-github-mcp':
|
||||
return 'false'
|
||||
default:
|
||||
return ''
|
||||
}
|
||||
})
|
||||
|
||||
await run()
|
||||
|
||||
expect(mockSimpleInference).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
messages: [{role: 'user', content: 'Here is the data: FILE_CONTENTS'}],
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('should fall back to legacy format when not using prompt YAML', async () => {
|
||||
mockExistsSync.mockReturnValue(false)
|
||||
core.getInput.mockImplementation((name: string) => {
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import {describe, it, expect} from 'vitest'
|
||||
import * as path from 'path'
|
||||
import {fileURLToPath} from 'url'
|
||||
import {parseTemplateVariables, replaceTemplateVariables, loadPromptFile, isPromptYamlFile} from '../src/prompt'
|
||||
import {
|
||||
parseTemplateVariables,
|
||||
replaceTemplateVariables,
|
||||
loadPromptFile,
|
||||
isPromptYamlFile,
|
||||
parseFileTemplateVariables,
|
||||
} from '../src/prompt'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
@@ -10,8 +16,8 @@ describe('prompt.ts', () => {
|
||||
describe('parseTemplateVariables', () => {
|
||||
it('should parse simple YAML variables', () => {
|
||||
const input = `
|
||||
a: hello
|
||||
b: world
|
||||
a: hello
|
||||
b: world
|
||||
`
|
||||
const result = parseTemplateVariables(input)
|
||||
expect(result).toEqual({a: 'hello', b: 'world'})
|
||||
@@ -19,10 +25,10 @@ b: world
|
||||
|
||||
it('should parse multiline variables', () => {
|
||||
const input = `
|
||||
var1: hello
|
||||
var2: |
|
||||
This is a
|
||||
multiline string
|
||||
var1: hello
|
||||
var2: |
|
||||
This is a
|
||||
multiline string
|
||||
`
|
||||
const result = parseTemplateVariables(input)
|
||||
expect(result.var1).toBe('hello')
|
||||
@@ -117,4 +123,17 @@ var2: |
|
||||
expect(() => loadPromptFile('non-existent.prompt.yml')).toThrow('Prompt file not found')
|
||||
})
|
||||
})
|
||||
|
||||
describe('parseFileTemplateVariables', () => {
|
||||
it('reads file contents for variables', () => {
|
||||
const configPath = path.join(__dirname, '../__fixtures__/prompts/json-schema.prompt.yml')
|
||||
const data = parseFileTemplateVariables(`sample: ${configPath}`)
|
||||
expect(data.sample).toContain('messages:')
|
||||
expect(data.sample).toContain('responseFormat:')
|
||||
})
|
||||
|
||||
it('errors on missing files', () => {
|
||||
expect(() => parseFileTemplateVariables('x: ./does-not-exist.txt')).toThrow('was not found')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user