Merge branch 'staging' into reasoning-parsing-streaming
| @@ -746,74 +746,65 @@ async function getQueryText(chat, initiator) { | ||
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | /** |
| 749 | 749 | * Gets thecommon savedbody hashesparameters for avector collectionrequests. |
| 750 | 750 | * @paramreturns {stringobject} collectionId |
| 751 | -* @returns {Promise<number[]>} Saved hashes | |
| 752 | 751 | */ |
| 753 | 752 | async function getSavedHashesgetVectorsRequestBody(collectionId) { |
| 754 | - const response = await fetch('/api/vector/list', { | |
| 753 | + const body = {}; | |
| 755 | - method: 'POST', | |
| 756 | - headers: getVectorHeaders(), | |
| 757 | - body: JSON.stringify({ | |
| 758 | - collectionId: collectionId, | |
| 759 | - source: settings.source, | |
| 760 | - }), | |
| 761 | - }); | |
| 762 | - | |
| 763 | - if (!response.ok) { | |
| 764 | - throw new Error(`Failed to get saved hashes for collection ${collectionId}`); | |
| 765 | - } | |
| 766 | - | |
| 767 | - const hashes = await response.json(); | |
| 768 | - return hashes; | |
| 769 | -} | |
| 770 | - | |
| 771 | -function getVectorHeaders() { | |
| 772 | - const headers = getRequestHeaders(); | |
| 773 | 754 | switch (settings.source) { |
| 774 | 755 | case 'extras': |
| 775 | - Object.assign(headers, { | |
| 756 | + body.extrasUrl = extension_settings.apiUrl; | |
| 776 | - 'X-Extras-Url': extension_settings.apiUrl, | |
| 757 | + body.extrasKey = extension_settings.apiKey; | |
| 777 | - 'X-Extras-Key': extension_settings.apiKey, | |
| 778 | - }); | |
| 779 | 758 | break; |
| 780 | 759 | case 'togetherai': |
| 781 | - Object.assign(headers, { | |
| 760 | + body.model = extension_settings.vectors.togetherai_model; | |
| 782 | - 'X-Togetherai-Model': extension_settings.vectors.togetherai_model, | |
| 783 | - }); | |
| 784 | 761 | break; |
| 785 | 762 | case 'openai': |
| 786 | - Object.assign(headers, { | |
| 763 | + body.model = extension_settings.vectors.openai_model; | |
| 787 | - 'X-OpenAI-Model': extension_settings.vectors.openai_model, | |
| 788 | - }); | |
| 789 | 764 | break; |
| 790 | 765 | case 'cohere': |
| 791 | - Object.assign(headers, { | |
| 766 | + body.model = extension_settings.vectors.cohere_model; | |
| 792 | - 'X-Cohere-Model': extension_settings.vectors.cohere_model, | |
| 793 | - }); | |
| 794 | 767 | break; |
| 795 | 768 | case 'ollama': |
| 796 | - Object.assign(headers, { | |
| 769 | + body.model = extension_settings.vectors.ollama_model; | |
| 797 | - 'X-Ollama-Model': extension_settings.vectors.ollama_model, | |
| 770 | + body.apiUrl = textgenerationwebui_settings.server_urls[textgen_types.OLLAMA]; | |
| 798 | - 'X-Ollama-URL': textgenerationwebui_settings.server_urls[textgen_types.OLLAMA], | |
| 771 | + body.keep = !!extension_settings.vectors.ollama_keep; | |
| 799 | - 'X-Ollama-Keep': !!extension_settings.vectors.ollama_keep, | |
| 800 | - }); | |
| 801 | 772 | break; |
| 802 | 773 | case 'llamacpp': |
| 803 | - Object.assign(headers, { | |
| 774 | + body.apiUrl = textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP]; | |
| 804 | - 'X-LlamaCpp-URL': textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP], | |
| 805 | - }); | |
| 806 | 775 | break; |
| 807 | 776 | case 'vllm': |
| 808 | - Object.assign(headers, { | |
| 777 | + body.apiUrl = textgenerationwebui_settings.server_urls[textgen_types.VLLM]; | |
| 809 | - 'X-Vllm-URL': textgenerationwebui_settings.server_urls[textgen_types.VLLM], | |
| 778 | + body.model = extension_settings.vectors.vllm_model; | |
| 810 | - 'X-Vllm-Model': extension_settings.vectors.vllm_model, | |
| 811 | - }); | |
| 812 | 779 | break; |
| 813 | 780 | default: |
| 814 | 781 | break; |
| 815 | 782 | } |
| 816 | 783 | return headersbody; |
| 784 | +} | |
| 785 | + | |
| 786 | +/** | |
| 787 | + * Gets the saved hashes for a collection | |
| 788 | +* @param {string} collectionId | |
| 789 | +* @returns {Promise<number[]>} Saved hashes | |
| 790 | +*/ | |
| 791 | +async function getSavedHashes(collectionId) { | |
| 792 | + const response = await fetch('/api/vector/list', { | |
| 793 | + method: 'POST', | |
| 794 | + headers: getRequestHeaders(), | |
| 795 | + body: JSON.stringify({ | |
| 796 | + ...getVectorsRequestBody(), | |
| 797 | + collectionId: collectionId, | |
| 798 | + source: settings.source, | |
| 799 | + }), | |
| 800 | + }); | |
| 801 | + | |
| 802 | + if (!response.ok) { | |
| 803 | + throw new Error(`Failed to get saved hashes for collection ${collectionId}`); | |
| 804 | + } | |
| 805 | + | |
| 806 | + const hashes = await response.json(); | |
| 807 | + return hashes; | |
| 817 | 808 | } |
| 818 | 809 | |
| 819 | 810 | /** |
| @@ -825,12 +816,11 @@ function getVectorHeaders() { | ||
| 825 | 816 | async function insertVectorItems(collectionId, items) { |
| 826 | 817 | throwIfSourceInvalid(); |
| 827 | 818 | |
| 828 | - const headers = getVectorHeaders(); | |
| 829 | - | |
| 830 | 819 | const response = await fetch('/api/vector/insert', { |
| 831 | 820 | method: 'POST', |
| 832 | 821 | headers: headersgetRequestHeaders(), |
| 833 | 822 | body: JSON.stringify({ |
| 823 | + ...getVectorsRequestBody(), | |
| 834 | 824 | collectionId: collectionId, |
| 835 | 825 | items: items, |
| 836 | 826 | source: settings.source, |
| @@ -879,8 +869,9 @@ function throwIfSourceInvalid() { | ||
| 879 | 869 | async function deleteVectorItems(collectionId, hashes) { |
| 880 | 870 | const response = await fetch('/api/vector/delete', { |
| 881 | 871 | method: 'POST', |
| 882 | 872 | headers: getVectorHeadersgetRequestHeaders(), |
| 883 | 873 | body: JSON.stringify({ |
| 874 | + ...getVectorsRequestBody(), | |
| 884 | 875 | collectionId: collectionId, |
| 885 | 876 | hashes: hashes, |
| 886 | 877 | source: settings.source, |
| @@ -899,12 +890,11 @@ async function deleteVectorItems(collectionId, hashes) { | ||
| 899 | 890 | * @returns {Promise<{ hashes: number[], metadata: object[]}>} - Hashes of the results |
| 900 | 891 | */ |
| 901 | 892 | async function queryCollection(collectionId, searchText, topK) { |
| 902 | - const headers = getVectorHeaders(); | |
| 903 | - | |
| 904 | 893 | const response = await fetch('/api/vector/query', { |
| 905 | 894 | method: 'POST', |
| 906 | 895 | headers: headersgetRequestHeaders(), |
| 907 | 896 | body: JSON.stringify({ |
| 897 | + ...getVectorsRequestBody(), | |
| 908 | 898 | collectionId: collectionId, |
| 909 | 899 | searchText: searchText, |
| 910 | 900 | topK: topK, |
| @@ -929,12 +919,11 @@ async function queryCollection(collectionId, searchText, topK) { | ||
| 929 | 919 | * @returns {Promise<Record<string, { hashes: number[], metadata: object[] }>>} - Results mapped to collection IDs |
| 930 | 920 | */ |
| 931 | 921 | async function queryMultipleCollections(collectionIds, searchText, topK, threshold) { |
| 932 | - const headers = getVectorHeaders(); | |
| 933 | - | |
| 934 | 922 | const response = await fetch('/api/vector/query-multi', { |
| 935 | 923 | method: 'POST', |
| 936 | 924 | headers: headersgetRequestHeaders(), |
| 937 | 925 | body: JSON.stringify({ |
| 926 | + ...getVectorsRequestBody(), | |
| 938 | 927 | collectionIds: collectionIds, |
| 939 | 928 | searchText: searchText, |
| 940 | 929 | topK: topK, |
| @@ -965,8 +954,9 @@ async function purgeFileVectorIndex(fileUrl) { | ||
| 965 | 954 | |
| 966 | 955 | const response = await fetch('/api/vector/purge', { |
| 967 | 956 | method: 'POST', |
| 968 | 957 | headers: getVectorHeadersgetRequestHeaders(), |
| 969 | 958 | body: JSON.stringify({ |
| 959 | + ...getVectorsRequestBody(), | |
| 970 | 960 | collectionId: collectionId, |
| 971 | 961 | }), |
| 972 | 962 | }); |
| @@ -994,8 +984,9 @@ async function purgeVectorIndex(collectionId) { | ||
| 994 | 984 | |
| 995 | 985 | const response = await fetch('/api/vector/purge', { |
| 996 | 986 | method: 'POST', |
| 997 | 987 | headers: getVectorHeadersgetRequestHeaders(), |
| 998 | 988 | body: JSON.stringify({ |
| 989 | + ...getVectorsRequestBody(), | |
| 999 | 990 | collectionId: collectionId, |
| 1000 | 991 | }), |
| 1001 | 992 | }); |
| @@ -1019,7 +1010,10 @@ async function purgeAllVectorIndexes() { | ||
| 1019 | 1010 | try { |
| 1020 | 1011 | const response = await fetch('/api/vector/purge-all', { |
| 1021 | 1012 | method: 'POST', |
| 1022 | 1013 | headers: getVectorHeadersgetRequestHeaders(), |
| 1014 | + body: JSON.stringify({ | |
| 1015 | + ...getVectorsRequestBody(), | |
| 1016 | + }), | |
| 1023 | 1017 | }); |
| 1024 | 1018 | |
| 1025 | 1019 | if (!response.ok) { |
| @@ -132,35 +132,35 @@ function getSourceSettings(source, request) { | ||
| 132 | 132 | switch (source) { |
| 133 | 133 | case 'togetherai': |
| 134 | 134 | return { |
| 135 | 135 | model: String(request.headers['x-togetherai-body.model']), |
| 136 | 136 | }; |
| 137 | 137 | case 'openai': |
| 138 | 138 | return { |
| 139 | 139 | model: String(request.headers['x-openai-body.model']), |
| 140 | 140 | }; |
| 141 | 141 | case 'cohere': |
| 142 | 142 | return { |
| 143 | 143 | model: String(request.headers['x-cohere-body.model']), |
| 144 | 144 | }; |
| 145 | 145 | case 'llamacpp': |
| 146 | 146 | return { |
| 147 | 147 | apiUrl: String(request.headers['x-llamacpp-url']body.apiUrl), |
| 148 | 148 | }; |
| 149 | 149 | case 'vllm': |
| 150 | 150 | return { |
| 151 | 151 | apiUrl: String(request.headers['x-vllm-url']body.apiUrl), |
| 152 | 152 | model: String(request.headers['x-vllm-body.model']), |
| 153 | 153 | }; |
| 154 | 154 | case 'ollama': |
| 155 | 155 | return { |
| 156 | 156 | apiUrl: String(request.headers['x-ollama-url']body.apiUrl), |
| 157 | 157 | model: String(request.headers['x-ollama-body.model']), |
| 158 | 158 | keep: Boolean(request.headers['x-ollama-body.keep']), |
| 159 | 159 | }; |
| 160 | 160 | case 'extras': |
| 161 | 161 | return { |
| 162 | 162 | extrasUrl: String(request.headers['x-extras-url']body.extrasUrl), |
| 163 | 163 | extrasKey: String(request.headers['x-extras-key']body.extrasKey), |
| 164 | 164 | }; |
| 165 | 165 | case 'transformers': |
| 166 | 166 | return { |