Add appendLastPath util function and use it in hypamemory
This commit is contained in:
@@ -2,6 +2,7 @@ import localforage from "localforage";
|
|||||||
import { globalFetch } from "src/ts/storage/globalApi";
|
import { globalFetch } from "src/ts/storage/globalApi";
|
||||||
import { runEmbedding } from "../transformers";
|
import { runEmbedding } from "../transformers";
|
||||||
import { alertError } from "src/ts/alert";
|
import { alertError } from "src/ts/alert";
|
||||||
|
import { appendLastPath } from "src/ts/util";
|
||||||
|
|
||||||
|
|
||||||
export class HypaProcesser{
|
export class HypaProcesser{
|
||||||
@@ -50,11 +51,7 @@ export class HypaProcesser{
|
|||||||
return [0]
|
return [0]
|
||||||
}
|
}
|
||||||
|
|
||||||
let replaceUrl = new URL(this.customEmbeddingUrl)
|
const replaceUrl = appendLastPath(this.customEmbeddingUrl,'embeddings')
|
||||||
|
|
||||||
if(replaceUrl.pathname !== '/embeddings'){
|
|
||||||
replaceUrl.pathname = '/embeddings'
|
|
||||||
}
|
|
||||||
|
|
||||||
gf = await globalFetch(replaceUrl.toString(), {
|
gf = await globalFetch(replaceUrl.toString(), {
|
||||||
body:{
|
body:{
|
||||||
|
|||||||
@@ -492,4 +492,34 @@ export function trimUntilPunctuation(s:string){
|
|||||||
result = result.slice(0, -1)
|
result = result.slice(0, -1)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends the given last path to the provided URL.
|
||||||
|
*
|
||||||
|
* @param {string} url - The base URL to which the last path will be appended.
|
||||||
|
* @param {string} lastPath - The path to be appended to the URL.
|
||||||
|
* @returns {string} The modified URL with the last path appended.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* appendLastPath("https://github.com/kwaroran/RisuAI","/commits/main")
|
||||||
|
* return 'https://github.com/kwaroran/RisuAI/commits/main'
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* appendLastPath("https://github.com/kwaroran/RisuAI/","/commits/main")
|
||||||
|
* return 'https://github.com/kwaroran/RisuAI/commits/main
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* appendLastPath("http://127.0.0.1:7997","embeddings")
|
||||||
|
* return 'http://127.0.0.1:7997/embeddings'
|
||||||
|
*/
|
||||||
|
export function appendLastPath(url, lastPath) {
|
||||||
|
// Remove trailing slash from url if exists
|
||||||
|
url = url.replace(/\/$/, '');
|
||||||
|
|
||||||
|
// Remove leading slash from lastPath if exists
|
||||||
|
lastPath = lastPath.replace(/^\//, '');
|
||||||
|
|
||||||
|
// Concat the url and lastPath
|
||||||
|
return url + '/' + lastPath;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user