aiChatInputContentToMessage.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. export default function AiChatInputContentToMessage(inputContent: any) { // todo: 合入 aiChatInput 后补充类型定义
  2. const { references, attachments, inputContents, setup } = inputContent;
  3. let inputs: any[] = [];
  4. if (attachments?.length) { // todo: attachment 允许传递目录?
  5. attachments.forEach((item: any) => {
  6. const { name, url } = item;
  7. // todo: 如何区分文件是 image 还是 file?
  8. if (name.includes('.png') || name.includes('.jpg') || name.includes('.jpeg')) {
  9. inputs.push({
  10. type: 'input_image',
  11. image_url: url,
  12. detail: 'auto'
  13. });
  14. } else {
  15. inputs.push({
  16. type: 'input_file',
  17. file_url: url, // todo: blob URL?
  18. name: name,
  19. });
  20. }
  21. });
  22. }
  23. if (inputContents?.length) {
  24. inputContents.forEach((item: any) => {
  25. inputs.push({
  26. type: 'input_text',
  27. text: item.text,
  28. });
  29. });
  30. }
  31. // todo: mcp
  32. return {
  33. role: "user",
  34. content: inputs,
  35. // createdAt: created_at, // todo: 产生消息时给 createdat 还是发送时?
  36. // model: model, // todo: inputContent 中未包含 model 信息
  37. references
  38. };
  39. }