pw.xpacks.llm.servers
class pw.xpacks.llm.servers.DocumentStoreServer(host, port, document_store, **rest_kwargs)
[source]Creates a REST Server for answering queries to a given instance of DocumentStore
.
It exposes three endpoints:
/v1/retrieve
which is answered usingretrieve
method,/v1/statistics
which is answered usingstatistics
method,/v1/inputs
which is answered usinglist_documents
method,
- Parameters
- host (
str
) – host on which server will run - port (
int
) – port on which server will run - document_store (
DocumentStore
) – instance ofDocumentStore
which is used to answer queries received in the endpoints. - rest_kwargs – optional kwargs to be passed to
pw.io.http.rest_connector
- host (
run(threaded=False, with_cache=True, cache_backend=pw.persistence.Backend.filesystem('./Cache'), **kwargs)
sourceStart the server. Enabling persistence will cache the UDFs
for which cache_strategy
is set.
- Parameters
- threaded (
bool
) – if True, the server will be run in a new thread. - with_cache (
bool
) – if True, caching will be enabled for the UDFs for whichcache_strategy
is set. - cache_backend (
Backend
|None
) – backend used for caching. Only relevant ifwith_cache
is set to True. - **kwargs – optional kwargs to be passed to
pw.run
.
- threaded (
class pw.xpacks.llm.servers.QARestServer(host, port, rag_question_answerer, **rest_kwargs)
[source]Creates a REST Server for answering queries to a given instance of BaseQuestionAnswerer
.
It exposes four endpoints:
/v1/retrieve
which is answered usingretrieve
method,/v1/statistics
which is answered usingstatistics
method,/v1/pw_list_documents
which is answered usinglist_documents
method,/v1/pw_ai_answer
which is answered usinganswer_query
method,
- Parameters
- host (
str
) – host on which server will run - port (
int
) – port on which server will run - rag_question_answerer (
BaseQuestionAnswerer
) – instance ofBaseQuestionAnswerer
which is used to answer queries received in the endpoints. - rest_kwargs – optional kwargs to be passed to
pw.io.http.rest_connector
- host (
run(threaded=False, with_cache=True, cache_backend=pw.persistence.Backend.filesystem('./Cache'), **kwargs)
sourceStart the server. Enabling persistence will cache the UDFs
for which cache_strategy
is set.
- Parameters
- threaded (
bool
) – if True, the server will be run in a new thread. - with_cache (
bool
) – if True, caching will be enabled for the UDFs for whichcache_strategy
is set. - cache_backend (
Backend
|None
) – backend used for caching. Only relevant ifwith_cache
is set to True. - **kwargs – optional kwargs to be passed to
pw.run
.
- threaded (
class pw.xpacks.llm.servers.QASummaryRestServer(host, port, rag_question_answerer, **rest_kwargs)
[source]Creates a REST Server for answering queries to a given instance of SummaryQuestionAnswerer
.
It exposes five endpoints:
/v1/retrieve
which is answered usingretrieve
method,/v1/statistics
which is answered usingstatistics
method,/v1/pw_list_documents
which is answered usinglist_documents
method,/v1/pw_ai_answer
which is answered usinganswer
method,/v1/pw_ai_summary
which is answered usingsummarize_query
method.
- Parameters
- host (
str
) – host on which server will run - port (
int
) – port on which server will run - rag_question_answerer (
SummaryQuestionAnswerer
) – instance ofSummaryQuestionAnswerer
which is used to answer queries received in the endpoints. - rest_kwargs – optional kwargs to be passed to
pw.io.http.rest_connector
- host (
run(threaded=False, with_cache=True, cache_backend=pw.persistence.Backend.filesystem('./Cache'), **kwargs)
sourceStart the server. Enabling persistence will cache the UDFs
for which cache_strategy
is set.
- Parameters
- threaded (
bool
) – if True, the server will be run in a new thread. - with_cache (
bool
) – if True, caching will be enabled for the UDFs for whichcache_strategy
is set. - cache_backend (
Backend
|None
) – backend used for caching. Only relevant ifwith_cache
is set to True. - **kwargs – optional kwargs to be passed to
pw.run
.
- threaded (