pw.xpacks.llm.servers
class 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/retrievewhich is answered using- retrievemethod,
- /v1/statisticswhich is answered using- statisticsmethod,
- /v1/inputswhich is answered using- list_documentsmethod,
- Parameters- host (str) – host on which server will run
- port (int) – port on which server will run
- document_store (DocumentStore) – instance ofDocumentStorewhich 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_strategyis set.
- cache_backend (Backend|None) – backend used for caching. Only relevant ifwith_cacheis set to True.
- **kwargs – optional kwargs to be passed to pw.run.
 
- threaded (
class 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/retrievewhich is answered using- retrievemethod,
- /v1/statisticswhich is answered using- statisticsmethod,
- /v1/pw_list_documentswhich is answered using- list_documentsmethod,
- /v1/pw_ai_answerwhich is answered using- answer_querymethod,
- /v2/list_documentswhich is answered using- list_documentsmethod,
- /v2/answerwhich is answered using- answer_querymethod,
- Parameters- host (str) – host on which server will run
- port (int) – port on which server will run
- rag_question_answerer (BaseQuestionAnswerer) – instance ofBaseQuestionAnswererwhich 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_strategyis set.
- cache_backend (Backend|None) – backend used for caching. Only relevant ifwith_cacheis set to True.
- **kwargs – optional kwargs to be passed to pw.run.
 
- threaded (
class 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/retrievewhich is answered using- retrievemethod,
- /v1/statisticswhich is answered using- statisticsmethod,
- /v1/pw_list_documentswhich is answered using- list_documentsmethod,
- /v1/pw_ai_answerwhich is answered using- answermethod,
- /v1/pw_ai_summarywhich is answered using- summarize_querymethod.
- /v2/list_documentswhich is answered using- list_documentsmethod,
- /v2/answerwhich is answered using- answer_querymethod,
- /v2/summarizewhich is answered using- summarize_querymethod.
- Parameters- host (str) – host on which server will run
- port (int) – port on which server will run
- rag_question_answerer (SummaryQuestionAnswerer) – instance ofSummaryQuestionAnswererwhich 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_strategyis set.
- cache_backend (Backend|None) – backend used for caching. Only relevant ifwith_cacheis set to True.
- **kwargs – optional kwargs to be passed to pw.run.
 
- threaded (