Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

nova_sonic_prompt.js 2.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  1. /**
  2. * This function generates a properly formatted conversation for the Amazon Bedrock Nova Sonic model.
  3. * It handles the _conversation variable to maintain conversation history.
  4. *
  5. * @typedef {Object} Vars
  6. * @property {string} [system_message] - System message to set the assistant's behavior
  7. * @property {string} [audio_file] - Path to the audio file to be processed
  8. * @property {Array<Object>} [_conversation] - Previous conversation history
  9. * @property {string} [_conversation[].output] - The assistant's previous response
  10. * @property {Object} [_conversation[].metadata] - Metadata about the previous response
  11. * @property {string} [_conversation[].metadata.userTranscript] - Transcript of the user's previous input
  12. *
  13. * @param {Object} provider - The provider configuration
  14. * @returns {Object} The formatted conversation for Nova Sonic
  15. */
  16. module.exports = async function ({ vars, provider }) {
  17. // Create the messages array starting with system message
  18. const messages = [
  19. {
  20. role: 'system',
  21. content: [
  22. {
  23. type: 'input_text',
  24. text: vars.system_message || 'You are a helpful AI assistant.',
  25. },
  26. ],
  27. },
  28. ];
  29. // Add previous conversation turns if they exist
  30. if (vars._conversation && Array.isArray(vars._conversation)) {
  31. for (const completion of vars._conversation) {
  32. // Add user message with input_text type (for user inputs)
  33. messages.push({
  34. role: 'user',
  35. content: [
  36. {
  37. type: 'input_text',
  38. text: completion?.metadata?.userTranscript || '',
  39. },
  40. ],
  41. });
  42. // Add assistant message with text type (for outputs)
  43. messages.push({
  44. role: 'assistant',
  45. content: [
  46. {
  47. type: 'text',
  48. text: completion.output,
  49. },
  50. ],
  51. });
  52. }
  53. }
  54. // Add the current question as the final user message
  55. messages.push({
  56. role: 'user',
  57. content: [
  58. {
  59. type: 'audio',
  60. text: vars.audio_file || '',
  61. },
  62. ],
  63. });
  64. return messages;
  65. };
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...