Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
3229ec11
Commit
3229ec11
authored
Jan 06, 2024
by
Timothy J. Baek
Browse files
feat: rag apis added to frontend
parent
cd86c369
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
0 deletions
+109
-0
src/lib/apis/rag/index.ts
src/lib/apis/rag/index.ts
+108
-0
src/lib/constants.ts
src/lib/constants.ts
+1
-0
No files found.
src/lib/apis/rag/index.ts
0 → 100644
View file @
3229ec11
import
{
RAG_API_BASE_URL
}
from
'
$lib/constants
'
;
export
const
uploadDocToVectorDB
=
async
(
token
:
string
,
collection_name
:
string
,
file
:
File
)
=>
{
const
data
=
new
FormData
();
data
.
append
(
'
file
'
,
file
);
data
.
append
(
'
collection_name
'
,
collection_name
);
let
error
=
null
;
const
res
=
await
fetch
(
`
${
RAG_API_BASE_URL
}
/doc`
,
{
method
:
'
POST
'
,
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
authorization
:
`Bearer
${
token
}
`
},
body
:
data
})
.
then
(
async
(
res
)
=>
{
if
(
!
res
.
ok
)
throw
await
res
.
json
();
return
res
.
json
();
})
.
catch
((
err
)
=>
{
error
=
err
.
detail
;
console
.
log
(
err
);
return
null
;
});
if
(
error
)
{
throw
error
;
}
return
res
;
};
export
const
uploadWebToVectorDB
=
async
(
token
:
string
,
collection_name
:
string
,
url
:
string
)
=>
{
let
error
=
null
;
const
res
=
await
fetch
(
`
${
RAG_API_BASE_URL
}
/web`
,
{
method
:
'
POST
'
,
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
authorization
:
`Bearer
${
token
}
`
},
body
:
JSON
.
stringify
({
url
:
url
,
collection_name
:
collection_name
})
})
.
then
(
async
(
res
)
=>
{
if
(
!
res
.
ok
)
throw
await
res
.
json
();
return
res
.
json
();
})
.
catch
((
err
)
=>
{
error
=
err
.
detail
;
console
.
log
(
err
);
return
null
;
});
if
(
error
)
{
throw
error
;
}
return
res
;
};
export
const
queryVectorDB
=
async
(
token
:
string
,
collection_name
:
string
,
query
:
string
,
k
:
number
)
=>
{
let
error
=
null
;
const
searchParams
=
new
URLSearchParams
();
searchParams
.
set
(
'
query
'
,
query
);
if
(
k
)
{
searchParams
.
set
(
'
k
'
,
k
.
toString
());
}
const
res
=
await
fetch
(
`
${
RAG_API_BASE_URL
}
/query/
${
collection_name
}
/?
${
searchParams
.
toString
()}
`
,
{
method
:
'
GET
'
,
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
authorization
:
`Bearer
${
token
}
`
}
}
)
.
then
(
async
(
res
)
=>
{
if
(
!
res
.
ok
)
throw
await
res
.
json
();
return
res
.
json
();
})
.
catch
((
err
)
=>
{
error
=
err
.
detail
;
console
.
log
(
err
);
return
null
;
});
if
(
error
)
{
throw
error
;
}
return
res
;
};
src/lib/constants.ts
View file @
3229ec11
...
...
@@ -5,6 +5,7 @@ export const WEBUI_BASE_URL = dev ? `http://${location.hostname}:8080` : ``;
export
const
WEBUI_API_BASE_URL
=
`
${
WEBUI_BASE_URL
}
/api/v1`
;
export
const
OLLAMA_API_BASE_URL
=
`
${
WEBUI_BASE_URL
}
/ollama/api`
;
export
const
OPENAI_API_BASE_URL
=
`
${
WEBUI_BASE_URL
}
/openai/api`
;
export
const
RAG_API_BASE_URL
=
`
${
WEBUI_BASE_URL
}
/rag/api/v1`
;
export
const
WEB_UI_VERSION
=
'
v1.0.0-alpha-static
'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment