@ljoukov/llm 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -4
- package/dist/index.cjs +44 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1598,6 +1598,20 @@ function isInlineImageMime(mimeType) {
|
|
|
1598
1598
|
}
|
|
1599
1599
|
return mimeType.startsWith("image/");
|
|
1600
1600
|
}
|
|
1601
|
+
function guessInlineDataFilename(mimeType) {
|
|
1602
|
+
switch (mimeType) {
|
|
1603
|
+
case "application/pdf":
|
|
1604
|
+
return "document.pdf";
|
|
1605
|
+
case "application/json":
|
|
1606
|
+
return "data.json";
|
|
1607
|
+
case "text/markdown":
|
|
1608
|
+
return "document.md";
|
|
1609
|
+
case "text/plain":
|
|
1610
|
+
return "document.txt";
|
|
1611
|
+
default:
|
|
1612
|
+
return "attachment.bin";
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1601
1615
|
function mergeConsecutiveTextParts(parts) {
|
|
1602
1616
|
if (parts.length === 0) {
|
|
1603
1617
|
return [];
|
|
@@ -1740,9 +1754,18 @@ function toOpenAiInput(contents) {
|
|
|
1740
1754
|
parts.push({ type: "input_text", text: part.text });
|
|
1741
1755
|
continue;
|
|
1742
1756
|
}
|
|
1743
|
-
const mimeType = part.mimeType
|
|
1744
|
-
|
|
1745
|
-
|
|
1757
|
+
const mimeType = part.mimeType;
|
|
1758
|
+
if (isInlineImageMime(mimeType)) {
|
|
1759
|
+
const dataUrl = `data:${mimeType};base64,${part.data}`;
|
|
1760
|
+
parts.push({ type: "input_image", image_url: dataUrl, detail: "auto" });
|
|
1761
|
+
continue;
|
|
1762
|
+
}
|
|
1763
|
+
const fileData = decodeInlineDataBuffer(part.data).toString("base64");
|
|
1764
|
+
parts.push({
|
|
1765
|
+
type: "input_file",
|
|
1766
|
+
filename: guessInlineDataFilename(mimeType),
|
|
1767
|
+
file_data: fileData
|
|
1768
|
+
});
|
|
1746
1769
|
}
|
|
1747
1770
|
if (parts.length === 1 && parts[0]?.type === "input_text" && typeof parts[0].text === "string") {
|
|
1748
1771
|
return {
|
|
@@ -1778,19 +1801,29 @@ function toChatGptInput(contents) {
|
|
|
1778
1801
|
});
|
|
1779
1802
|
continue;
|
|
1780
1803
|
}
|
|
1781
|
-
const mimeType = part.mimeType ?? "application/octet-stream";
|
|
1782
|
-
const dataUrl = `data:${mimeType};base64,${part.data}`;
|
|
1783
1804
|
if (isAssistant) {
|
|
1805
|
+
const mimeType = part.mimeType ?? "application/octet-stream";
|
|
1784
1806
|
parts.push({
|
|
1785
1807
|
type: "output_text",
|
|
1786
|
-
text: `[image:${mimeType}]`
|
|
1808
|
+
text: isInlineImageMime(part.mimeType) ? `[image:${mimeType}]` : `[file:${mimeType}]`
|
|
1787
1809
|
});
|
|
1788
1810
|
} else {
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1811
|
+
if (isInlineImageMime(part.mimeType)) {
|
|
1812
|
+
const mimeType = part.mimeType ?? "application/octet-stream";
|
|
1813
|
+
const dataUrl = `data:${mimeType};base64,${part.data}`;
|
|
1814
|
+
parts.push({
|
|
1815
|
+
type: "input_image",
|
|
1816
|
+
image_url: dataUrl,
|
|
1817
|
+
detail: "auto"
|
|
1818
|
+
});
|
|
1819
|
+
} else {
|
|
1820
|
+
const fileData = decodeInlineDataBuffer(part.data).toString("base64");
|
|
1821
|
+
parts.push({
|
|
1822
|
+
type: "input_file",
|
|
1823
|
+
filename: guessInlineDataFilename(part.mimeType),
|
|
1824
|
+
file_data: fileData
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1794
1827
|
}
|
|
1795
1828
|
}
|
|
1796
1829
|
if (parts.length === 0) {
|