-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for AI prompt agent function
- Loading branch information
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import agent from '../../../functions/ai-prompt/1.0'; | ||
|
||
const validInput = { | ||
prompt: 'Hello', | ||
variables: [{ key: 'name', value: 'John' }], | ||
apiKey: 'validApiKey', | ||
maxTokens: 100, | ||
temperature: 50, | ||
model: 'text-davinci-002', | ||
}; | ||
|
||
const invalidInput = { | ||
prompt: 'Hello', | ||
variables: [{ key: 'name', value: 'John' }], | ||
apiKey: 'invalidApiKey', | ||
maxTokens: 100, | ||
temperature: 50, | ||
model: 'text-davinci-002', | ||
}; | ||
|
||
describe('Agent function', () => { | ||
test('returns the expected result with valid inputs', async () => { | ||
const { result } = await agent(validInput); | ||
expect(result).toBe('Hello John'); | ||
}); | ||
|
||
test('throws an error with invalid inputs', async () => { | ||
await expect(agent(invalidInput)).rejects.toThrow('Invalid API Key'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const generativeAI = async ({ authorization }) => { | ||
if (authorization.apiKey === 'validApiKey') { | ||
return Promise.resolve({ result: 'Hello John' }); | ||
} | ||
return Promise.reject(new Error('Invalid API Key')); | ||
}; | ||
export default generativeAI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters