chatInputToMessage.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { MessageContent } from "../../aiChatInput/interface";
  2. export default function chatInputToMessage(inputContent: MessageContent) {
  3. const { references, attachments, inputContents, setup } = inputContent;
  4. let inputs: any[] = [];
  5. if (attachments?.length) {
  6. attachments.forEach((item: any) => {
  7. const { name, url } = item;
  8. if (name.includes('.png') || name.includes('.jpg') || name.includes('.jpeg')) {
  9. inputs.push({
  10. ...item,
  11. type: 'input_image',
  12. image_url: url,
  13. detail: 'auto',
  14. });
  15. } else {
  16. inputs.push({
  17. ...item,
  18. type: 'input_file',
  19. file_url: url,
  20. filename: name,
  21. });
  22. }
  23. });
  24. }
  25. if (inputContents?.length) {
  26. inputContents.forEach((item: any) => {
  27. inputs.push({
  28. type: 'input_text',
  29. text: item.text,
  30. });
  31. });
  32. }
  33. return {
  34. role: "user",
  35. content: [{
  36. type: 'message',
  37. role: 'user',
  38. content: inputs,
  39. }],
  40. model: setup?.model,
  41. references,
  42. setup: setup ?? {}
  43. };
  44. }