Merge branch 'staging' into reasoning-parsing-streaming

e5e2c9fe490a74e2d996980ed57338e19cabdb85

Cohee <18619528+Cohee1207@users.noreply.github.com>

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