Spaces:
Sleeping
Sleeping
NickNYU
commited on
Commit
•
5ea412d
1
Parent(s):
9ecd254
reformat well
Browse files- .idea/llama-xpipe.iml +2 -1
- app.py +4 -2
- core/__pycache__/__init__.cpython-310.pyc +0 -0
- core/__pycache__/lifecycle.cpython-310.pyc +0 -0
- core/__pycache__/logger_factory.cpython-310.pyc +0 -0
- dataset/docstore.json +0 -0
- dataset/graph_store.json +1 -3
- dataset/index_store.json +1 -8
- dataset/vector_store.json +0 -0
- docs/docs.pkl +0 -0
- langchain_manager/manager.py +26 -2
- llama/data_loader.py +2 -1
- llama/{context.py → service_context.py} +59 -0
- llama/storage_context.py +0 -0
- local-requirements.txt +1 -0
- requirements.txt +3 -2
- xpipe_wiki/manager_factory.py +44 -15
- xpipe_wiki/robot_manager.py +4 -4
.idea/llama-xpipe.iml
CHANGED
@@ -2,9 +2,10 @@
|
|
2 |
<module type="PYTHON_MODULE" version="4">
|
3 |
<component name="NewModuleRootManager">
|
4 |
<content url="file://$MODULE_DIR$">
|
|
|
5 |
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
6 |
</content>
|
7 |
-
<orderEntry type="
|
8 |
<orderEntry type="sourceFolder" forTests="false" />
|
9 |
</component>
|
10 |
</module>
|
|
|
2 |
<module type="PYTHON_MODULE" version="4">
|
3 |
<component name="NewModuleRootManager">
|
4 |
<content url="file://$MODULE_DIR$">
|
5 |
+
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
6 |
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
7 |
</content>
|
8 |
+
<orderEntry type="inheritedJdk" />
|
9 |
<orderEntry type="sourceFolder" forTests="false" />
|
10 |
</component>
|
11 |
</module>
|
app.py
CHANGED
@@ -2,11 +2,12 @@ import logging
|
|
2 |
import sys
|
3 |
|
4 |
import streamlit as st
|
|
|
5 |
|
6 |
from xpipe_wiki.manager_factory import XPipeRobotManagerFactory, XPipeRobotRevision
|
7 |
|
8 |
logging.basicConfig(
|
9 |
-
stream=sys.stdout, level=logging.
|
10 |
) # logging.DEBUG for more verbose output
|
11 |
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
|
12 |
|
@@ -29,7 +30,7 @@ with st.sidebar:
|
|
29 |
def main() -> None:
|
30 |
st.header("X-Pipe Wiki 机器人 💬")
|
31 |
robot_manager = XPipeRobotManagerFactory.get_or_create(
|
32 |
-
XPipeRobotRevision.
|
33 |
)
|
34 |
robot = robot_manager.get_robot()
|
35 |
query = st.text_input("X-Pipe Wiki 问题:")
|
@@ -39,4 +40,5 @@ def main() -> None:
|
|
39 |
|
40 |
|
41 |
if __name__ == "__main__":
|
|
|
42 |
main()
|
|
|
2 |
import sys
|
3 |
|
4 |
import streamlit as st
|
5 |
+
from dotenv import load_dotenv
|
6 |
|
7 |
from xpipe_wiki.manager_factory import XPipeRobotManagerFactory, XPipeRobotRevision
|
8 |
|
9 |
logging.basicConfig(
|
10 |
+
stream=sys.stdout, level=logging.INFO
|
11 |
) # logging.DEBUG for more verbose output
|
12 |
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
|
13 |
|
|
|
30 |
def main() -> None:
|
31 |
st.header("X-Pipe Wiki 机器人 💬")
|
32 |
robot_manager = XPipeRobotManagerFactory.get_or_create(
|
33 |
+
XPipeRobotRevision.HUGGINGFACE_VERSION_0
|
34 |
)
|
35 |
robot = robot_manager.get_robot()
|
36 |
query = st.text_input("X-Pipe Wiki 问题:")
|
|
|
40 |
|
41 |
|
42 |
if __name__ == "__main__":
|
43 |
+
load_dotenv()
|
44 |
main()
|
core/__pycache__/__init__.cpython-310.pyc
CHANGED
Binary files a/core/__pycache__/__init__.cpython-310.pyc and b/core/__pycache__/__init__.cpython-310.pyc differ
|
|
core/__pycache__/lifecycle.cpython-310.pyc
CHANGED
Binary files a/core/__pycache__/lifecycle.cpython-310.pyc and b/core/__pycache__/lifecycle.cpython-310.pyc differ
|
|
core/__pycache__/logger_factory.cpython-310.pyc
CHANGED
Binary files a/core/__pycache__/logger_factory.cpython-310.pyc and b/core/__pycache__/logger_factory.cpython-310.pyc differ
|
|
dataset/docstore.json
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
dataset/graph_store.json
CHANGED
@@ -1,3 +1 @@
|
|
1 |
-
{
|
2 |
-
"graph_dict": {}
|
3 |
-
}
|
|
|
1 |
+
{"graph_dict": {}}
|
|
|
|
dataset/index_store.json
CHANGED
@@ -1,8 +1 @@
|
|
1 |
-
{
|
2 |
-
"index_store/data": {
|
3 |
-
"7fd1f2d1-8a3a-4e24-bf42-5c149a73c8dc": {
|
4 |
-
"__type__": "vector_store",
|
5 |
-
"__data__": "{\"index_id\": \"7fd1f2d1-8a3a-4e24-bf42-5c149a73c8dc\", \"summary\": null, \"nodes_dict\": {\"190d619c-e92d-4cc5-b43b-652f66f4d6e0\": \"190d619c-e92d-4cc5-b43b-652f66f4d6e0\", \"1158d24f-29db-457b-aeaa-2a051316796e\": \"1158d24f-29db-457b-aeaa-2a051316796e\", \"520004a6-3eb6-44cf-90ba-a51ed1c6b894\": \"520004a6-3eb6-44cf-90ba-a51ed1c6b894\", \"359cdd4d-6096-4be4-991d-f3cc691c07c9\": \"359cdd4d-6096-4be4-991d-f3cc691c07c9\", \"3e4ffb91-090e-4e84-92cd-e8df8b3a87b8\": \"3e4ffb91-090e-4e84-92cd-e8df8b3a87b8\", \"7aa9b872-c4df-4de6-88c5-55962b913ba9\": \"7aa9b872-c4df-4de6-88c5-55962b913ba9\", \"16aa0efc-39b4-4fa8-93ab-f31b5740670c\": \"16aa0efc-39b4-4fa8-93ab-f31b5740670c\", \"1bebdce9-981b-4100-914d-48da73dc5f96\": \"1bebdce9-981b-4100-914d-48da73dc5f96\", \"bbe72c0d-ab9f-45c0-b581-d051f7aa797e\": \"bbe72c0d-ab9f-45c0-b581-d051f7aa797e\", \"229d36cc-1f60-485a-b44f-c53701b423de\": \"229d36cc-1f60-485a-b44f-c53701b423de\", \"dff86a2f-8cf4-4f01-a8ab-36977bb2db5c\": \"dff86a2f-8cf4-4f01-a8ab-36977bb2db5c\", \"cdf5fa07-4780-4cc2-9073-851996c4f006\": \"cdf5fa07-4780-4cc2-9073-851996c4f006\", \"a27c62d4-e969-46a8-94d8-aa0ce552234e\": \"a27c62d4-e969-46a8-94d8-aa0ce552234e\", \"e85816a0-a950-44c7-af93-dcf15a889490\": \"e85816a0-a950-44c7-af93-dcf15a889490\", \"cce4f38a-e5d4-4561-aab9-d695eef3bacf\": \"cce4f38a-e5d4-4561-aab9-d695eef3bacf\", \"b3716ae7-21ec-4112-979e-d5963c8235d5\": \"b3716ae7-21ec-4112-979e-d5963c8235d5\", \"55362a6d-27e6-46de-8fa8-c87a2039020f\": \"55362a6d-27e6-46de-8fa8-c87a2039020f\", \"785291f8-266d-4458-ba2c-2c110fac1038\": \"785291f8-266d-4458-ba2c-2c110fac1038\", \"c8655cf5-12f3-479a-a3b4-b43a2f6965ba\": \"c8655cf5-12f3-479a-a3b4-b43a2f6965ba\", \"67b2a33e-b9a3-4072-bc89-c1405d60dbe0\": \"67b2a33e-b9a3-4072-bc89-c1405d60dbe0\", \"42256b49-3c47-4fa2-8c64-871a757b9993\": \"42256b49-3c47-4fa2-8c64-871a757b9993\", \"f0a7c6ca-206e-477c-8f0a-416a355532d5\": \"f0a7c6ca-206e-477c-8f0a-416a355532d5\"}, \"doc_id_dict\": {}, \"embeddings_dict\": {}}"
|
6 |
-
}
|
7 |
-
}
|
8 |
-
}
|
|
|
1 |
+
{"index_store/data": {"f0aa9b38-a1b4-4cd8-8261-38f7e28b7053": {"__type__": "vector_store", "__data__": "{\"index_id\": \"f0aa9b38-a1b4-4cd8-8261-38f7e28b7053\", \"summary\": null, \"nodes_dict\": {\"432d9349-9c31-4ff4-b982-7a3d80a383a4\": \"432d9349-9c31-4ff4-b982-7a3d80a383a4\", \"1c93f814-8019-43d5-a583-12e1c1c1d702\": \"1c93f814-8019-43d5-a583-12e1c1c1d702\", \"6850a6e1-7bf9-42c8-873c-fff410bf4f61\": \"6850a6e1-7bf9-42c8-873c-fff410bf4f61\", \"99678815-82b6-4df5-88e5-8f489ef5f0dd\": \"99678815-82b6-4df5-88e5-8f489ef5f0dd\", \"f56f6064-9d14-4290-bfb5-b5992fddbfd8\": \"f56f6064-9d14-4290-bfb5-b5992fddbfd8\", \"d8cd4c80-4fcd-4961-a6f9-e315078bdd3b\": \"d8cd4c80-4fcd-4961-a6f9-e315078bdd3b\", \"3b4b0e7f-dcde-4cf2-94a5-e96fa67d52bb\": \"3b4b0e7f-dcde-4cf2-94a5-e96fa67d52bb\", \"1a275084-07c0-41cb-85d5-20b454630cde\": \"1a275084-07c0-41cb-85d5-20b454630cde\", \"0fdf0b9e-db8c-46d3-a634-67bd4b3939ca\": \"0fdf0b9e-db8c-46d3-a634-67bd4b3939ca\", \"a428ca4f-d82d-4dbd-98ef-63dce24a749d\": \"a428ca4f-d82d-4dbd-98ef-63dce24a749d\", \"1f537ab9-d15c-456a-937e-481b1b84dfd1\": \"1f537ab9-d15c-456a-937e-481b1b84dfd1\", \"598cd507-a5c5-4b6d-a555-037d1fc388d5\": \"598cd507-a5c5-4b6d-a555-037d1fc388d5\", \"65f05413-df67-4a93-80cf-83654439fdd8\": \"65f05413-df67-4a93-80cf-83654439fdd8\", \"dc8cbec7-d6e5-462c-977a-738f1eedcffc\": \"dc8cbec7-d6e5-462c-977a-738f1eedcffc\", \"a5771b3f-00f7-4669-b593-647827e570c8\": \"a5771b3f-00f7-4669-b593-647827e570c8\", \"cc945889-e48c-4262-9654-86d60bfe38b6\": \"cc945889-e48c-4262-9654-86d60bfe38b6\", \"1e6cc8f4-ec6c-474f-8db2-93de82248a28\": \"1e6cc8f4-ec6c-474f-8db2-93de82248a28\", \"d9441ba7-09ec-4726-ae88-df1863261a9f\": \"d9441ba7-09ec-4726-ae88-df1863261a9f\", \"a5aa5af4-12d1-4a01-8e0e-5318ca3b6de4\": \"a5aa5af4-12d1-4a01-8e0e-5318ca3b6de4\", \"009e44e3-4730-485f-add7-e1e517ee1536\": \"009e44e3-4730-485f-add7-e1e517ee1536\", \"3b0649c0-a990-4340-8d4d-b65db3cb432b\": \"3b0649c0-a990-4340-8d4d-b65db3cb432b\", \"bd7b998c-ead4-4d14-a01d-9c4c3d1d5d65\": \"bd7b998c-ead4-4d14-a01d-9c4c3d1d5d65\"}, \"doc_id_dict\": {}, \"embeddings_dict\": {}}"}}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataset/vector_store.json
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
docs/docs.pkl
CHANGED
Binary files a/docs/docs.pkl and b/docs/docs.pkl differ
|
|
langchain_manager/manager.py
CHANGED
@@ -5,8 +5,6 @@ from langchain.embeddings.base import Embeddings as LCEmbeddings
|
|
5 |
from langchain.embeddings.openai import OpenAIEmbeddings
|
6 |
from langchain.llms import AzureOpenAI
|
7 |
|
8 |
-
from core.lifecycle import Lifecycle
|
9 |
-
|
10 |
|
11 |
class BaseLangChainManager(ABC):
|
12 |
def __init__(self) -> None:
|
@@ -39,3 +37,29 @@ class LangChainAzureManager(BaseLangChainManager):
|
|
39 |
# Override
|
40 |
def get_llm(self) -> BaseLanguageModel:
|
41 |
return self.llm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
from langchain.embeddings.openai import OpenAIEmbeddings
|
6 |
from langchain.llms import AzureOpenAI
|
7 |
|
|
|
|
|
8 |
|
9 |
class BaseLangChainManager(ABC):
|
10 |
def __init__(self) -> None:
|
|
|
37 |
# Override
|
38 |
def get_llm(self) -> BaseLanguageModel:
|
39 |
return self.llm
|
40 |
+
|
41 |
+
|
42 |
+
class LangChainHuggingFaceManager(BaseLangChainManager):
|
43 |
+
def __init__(self) -> None:
|
44 |
+
super().__init__()
|
45 |
+
from transformers import AutoTokenizer, AutoModel
|
46 |
+
|
47 |
+
AutoTokenizer.from_pretrained("GanymedeNil/text2vec-large-chinese")
|
48 |
+
|
49 |
+
AutoModel.from_pretrained("GanymedeNil/text2vec-large-chinese")
|
50 |
+
|
51 |
+
self.embedding = OpenAIEmbeddings(client=None, chunk_size=1)
|
52 |
+
self.llm = AzureOpenAI(
|
53 |
+
deployment_name="text-davinci-003",
|
54 |
+
# model_name="text-davinci-003",
|
55 |
+
model="text-davinci-003",
|
56 |
+
client=None,
|
57 |
+
)
|
58 |
+
|
59 |
+
# Override
|
60 |
+
def get_embedding(self) -> LCEmbeddings:
|
61 |
+
return self.embedding
|
62 |
+
|
63 |
+
# Override
|
64 |
+
def get_llm(self) -> BaseLanguageModel:
|
65 |
+
return self.llm
|
llama/data_loader.py
CHANGED
@@ -51,7 +51,8 @@ class GithubLoader(WikiLoader):
|
|
51 |
verbose=True,
|
52 |
concurrent_requests=10,
|
53 |
)
|
54 |
-
|
|
|
55 |
docs = loader.load_data(branch="master")
|
56 |
|
57 |
with open("docs/docs.pkl", "wb") as f:
|
|
|
51 |
verbose=True,
|
52 |
concurrent_requests=10,
|
53 |
)
|
54 |
+
os.environ["http_proxy"] = "http://127.0.0.1:7890"
|
55 |
+
os.environ["https_proxy"] = "http://127.0.0.1:7890"
|
56 |
docs = loader.load_data(branch="master")
|
57 |
|
58 |
with open("docs/docs.pkl", "wb") as f:
|
llama/{context.py → service_context.py}
RENAMED
@@ -66,6 +66,65 @@ class AzureServiceContextManager(ServiceContextManager):
|
|
66 |
)
|
67 |
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
class StorageContextManager(Lifecycle, ABC):
|
70 |
@abstractmethod
|
71 |
def get_storage_context(self) -> StorageContext:
|
|
|
66 |
)
|
67 |
|
68 |
|
69 |
+
class HuggingFaceChineseOptServiceContextManager(ServiceContextManager):
|
70 |
+
lc_manager: BaseLangChainManager
|
71 |
+
service_context: ServiceContext
|
72 |
+
|
73 |
+
def __init__(self, lc_manager: BaseLangChainManager):
|
74 |
+
super().__init__()
|
75 |
+
self.lc_manager = lc_manager
|
76 |
+
|
77 |
+
def get_service_context(self) -> ServiceContext:
|
78 |
+
if self.service_context is None:
|
79 |
+
raise ValueError(
|
80 |
+
"service context is not ready, check for lifecycle statement"
|
81 |
+
)
|
82 |
+
return self.service_context
|
83 |
+
|
84 |
+
def do_init(self) -> None:
|
85 |
+
# define embedding
|
86 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
87 |
+
|
88 |
+
model_name = "GanymedeNil/text2vec-large-chinese"
|
89 |
+
hf_embedding = HuggingFaceEmbeddings(
|
90 |
+
model_name=model_name, model_kwargs={"device": "cpu"}
|
91 |
+
)
|
92 |
+
|
93 |
+
embedding = LangchainEmbedding(hf_embedding)
|
94 |
+
# define LLM
|
95 |
+
llm_predictor = LLMPredictor(self.lc_manager.get_llm())
|
96 |
+
# configure service context
|
97 |
+
self.service_context = ServiceContext.from_defaults(
|
98 |
+
llm_predictor=llm_predictor, embed_model=embedding
|
99 |
+
)
|
100 |
+
|
101 |
+
def do_start(self) -> None:
|
102 |
+
self.logger.info(
|
103 |
+
"[do_start][embedding] last used usage: %d",
|
104 |
+
self.service_context.embed_model.total_tokens_used,
|
105 |
+
)
|
106 |
+
self.logger.info(
|
107 |
+
"[do_start][predict] last used usage: %d",
|
108 |
+
self.service_context.llm_predictor.total_tokens_used,
|
109 |
+
)
|
110 |
+
|
111 |
+
def do_stop(self) -> None:
|
112 |
+
self.logger.info(
|
113 |
+
"[do_stop][embedding] last used usage: %d",
|
114 |
+
self.service_context.embed_model.total_tokens_used,
|
115 |
+
)
|
116 |
+
self.logger.info(
|
117 |
+
"[do_stop][predict] last used usage: %d",
|
118 |
+
self.service_context.llm_predictor.total_tokens_used,
|
119 |
+
)
|
120 |
+
|
121 |
+
def do_dispose(self) -> None:
|
122 |
+
self.logger.info(
|
123 |
+
"[do_dispose] total used token: %d",
|
124 |
+
self.service_context.llm_predictor.total_tokens_used,
|
125 |
+
)
|
126 |
+
|
127 |
+
|
128 |
class StorageContextManager(Lifecycle, ABC):
|
129 |
@abstractmethod
|
130 |
def get_storage_context(self) -> StorageContext:
|
llama/storage_context.py
ADDED
File without changes
|
local-requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
python-dotenv
|
requirements.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
llama_index>=0.6.3
|
2 |
llama_hub
|
3 |
-
|
4 |
ruff
|
5 |
black
|
6 |
-
mypy
|
|
|
|
1 |
llama_index>=0.6.3
|
2 |
llama_hub
|
3 |
+
streamlit
|
4 |
ruff
|
5 |
black
|
6 |
+
mypy
|
7 |
+
accelerate
|
xpipe_wiki/manager_factory.py
CHANGED
@@ -4,39 +4,45 @@ import os
|
|
4 |
from core.helper import LifecycleHelper
|
5 |
from xpipe_wiki.robot_manager import XPipeWikiRobotManager, AzureXPipeWikiRobotManager
|
6 |
|
|
|
7 |
|
8 |
-
|
9 |
-
SIMPLE_OPENAI_VERSION_0 = 1
|
10 |
-
|
11 |
-
|
12 |
|
13 |
|
|
|
|
|
|
|
14 |
|
15 |
|
16 |
class XPipeRobotManagerFactory:
|
17 |
"""
|
18 |
-
CAPABLE: Dict[XPipeRobotRevision, XPipeWikiRobotManager] =
|
|
|
19 |
"""
|
20 |
-
|
|
|
|
|
21 |
@classmethod
|
22 |
def get_or_create(cls, revision: XPipeRobotRevision) -> XPipeWikiRobotManager:
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
@classmethod
|
31 |
def create_simple_openai_version_0(cls) -> AzureXPipeWikiRobotManager:
|
32 |
-
from llama.
|
33 |
from langchain_manager.manager import LangChainAzureManager
|
34 |
|
35 |
service_context_manager = AzureServiceContextManager(
|
36 |
lc_manager=LangChainAzureManager()
|
37 |
)
|
38 |
-
|
39 |
-
from llama.context import LocalStorageContextManager
|
40 |
|
41 |
dataset_path = os.getenv("XPIPE_WIKI_DATASET_PATH", "./dataset")
|
42 |
storage_context_manager = LocalStorageContextManager(
|
@@ -51,3 +57,26 @@ class XPipeRobotManagerFactory:
|
|
51 |
LifecycleHelper.start_if_possible(robot_manager)
|
52 |
return robot_manager
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
from core.helper import LifecycleHelper
|
5 |
from xpipe_wiki.robot_manager import XPipeWikiRobotManager, AzureXPipeWikiRobotManager
|
6 |
|
7 |
+
from multiprocessing import Lock
|
8 |
|
9 |
+
lock = Lock()
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
+
class XPipeRobotRevision(enum.Enum):
|
13 |
+
SIMPLE_OPENAI_VERSION_0 = 1
|
14 |
+
HUGGINGFACE_VERSION_0 = 2
|
15 |
|
16 |
|
17 |
class XPipeRobotManagerFactory:
|
18 |
"""
|
19 |
+
CAPABLE: Dict[XPipeRobotRevision, XPipeWikiRobotManager] =
|
20 |
+
{XPipeRobotRevision.SIMPLE_OPENAI_VERSION_0: XPipeWikiRobotManager()}
|
21 |
"""
|
22 |
+
|
23 |
+
CAPABLE = dict() # type: dict[XPipeRobotRevision, XPipeWikiRobotManager]
|
24 |
+
|
25 |
@classmethod
|
26 |
def get_or_create(cls, revision: XPipeRobotRevision) -> XPipeWikiRobotManager:
|
27 |
+
with lock:
|
28 |
+
if cls.CAPABLE.get(revision) is not None:
|
29 |
+
return cls.CAPABLE[revision]
|
30 |
+
if revision == XPipeRobotRevision.SIMPLE_OPENAI_VERSION_0:
|
31 |
+
manager = cls.create_simple_openai_version_0()
|
32 |
+
elif revision == XPipeRobotRevision.HUGGINGFACE_VERSION_0:
|
33 |
+
manager = cls.create_huggingface_version_0()
|
34 |
+
cls.CAPABLE[revision] = manager
|
35 |
+
return manager
|
36 |
|
37 |
@classmethod
|
38 |
def create_simple_openai_version_0(cls) -> AzureXPipeWikiRobotManager:
|
39 |
+
from llama.service_context import AzureServiceContextManager
|
40 |
from langchain_manager.manager import LangChainAzureManager
|
41 |
|
42 |
service_context_manager = AzureServiceContextManager(
|
43 |
lc_manager=LangChainAzureManager()
|
44 |
)
|
45 |
+
from llama.service_context import LocalStorageContextManager
|
|
|
46 |
|
47 |
dataset_path = os.getenv("XPIPE_WIKI_DATASET_PATH", "./dataset")
|
48 |
storage_context_manager = LocalStorageContextManager(
|
|
|
57 |
LifecycleHelper.start_if_possible(robot_manager)
|
58 |
return robot_manager
|
59 |
|
60 |
+
@classmethod
|
61 |
+
def create_huggingface_version_0(cls) -> AzureXPipeWikiRobotManager:
|
62 |
+
from llama.service_context import HuggingFaceChineseOptServiceContextManager
|
63 |
+
from langchain_manager.manager import LangChainAzureManager
|
64 |
+
|
65 |
+
service_context_manager = HuggingFaceChineseOptServiceContextManager(
|
66 |
+
lc_manager=LangChainAzureManager()
|
67 |
+
)
|
68 |
+
|
69 |
+
from llama.service_context import LocalStorageContextManager
|
70 |
+
|
71 |
+
dataset_path = os.getenv("XPIPE_WIKI_DATASET_PATH", "./dataset")
|
72 |
+
storage_context_manager = LocalStorageContextManager(
|
73 |
+
dataset_path=dataset_path, service_context_manager=service_context_manager
|
74 |
+
)
|
75 |
+
|
76 |
+
robot_manager = AzureXPipeWikiRobotManager(
|
77 |
+
service_context_manager=service_context_manager,
|
78 |
+
storage_context_manager=storage_context_manager,
|
79 |
+
)
|
80 |
+
LifecycleHelper.initialize_if_possible(robot_manager)
|
81 |
+
LifecycleHelper.start_if_possible(robot_manager)
|
82 |
+
return robot_manager
|
xpipe_wiki/robot_manager.py
CHANGED
@@ -3,11 +3,10 @@ from typing import Any
|
|
3 |
|
4 |
from llama_index import load_index_from_storage
|
5 |
from llama_index.indices.query.base import BaseQueryEngine
|
6 |
-
from pydantic import dataclasses
|
7 |
|
8 |
from core.helper import LifecycleHelper
|
9 |
from core.lifecycle import Lifecycle
|
10 |
-
from llama.
|
11 |
|
12 |
|
13 |
class XPipeWikiRobot(ABC):
|
@@ -24,7 +23,7 @@ class AzureOpenAIXPipeWikiRobot(XPipeWikiRobot):
|
|
24 |
self.query_engine = query_engine
|
25 |
|
26 |
def ask(self, question: str) -> Any:
|
27 |
-
return self.query_engine.query(question)
|
28 |
|
29 |
|
30 |
class XPipeWikiRobotManager(Lifecycle):
|
@@ -58,7 +57,8 @@ class AzureXPipeWikiRobotManager(XPipeWikiRobotManager):
|
|
58 |
LifecycleHelper.start_if_possible(self.service_context_manager)
|
59 |
LifecycleHelper.start_if_possible(self.storage_context_manager)
|
60 |
index = load_index_from_storage(
|
61 |
-
storage_context=self.storage_context_manager.get_storage_context()
|
|
|
62 |
)
|
63 |
self.query_engine = index.as_query_engine(
|
64 |
service_context=self.service_context_manager.get_service_context()
|
|
|
3 |
|
4 |
from llama_index import load_index_from_storage
|
5 |
from llama_index.indices.query.base import BaseQueryEngine
|
|
|
6 |
|
7 |
from core.helper import LifecycleHelper
|
8 |
from core.lifecycle import Lifecycle
|
9 |
+
from llama.service_context import ServiceContextManager, StorageContextManager
|
10 |
|
11 |
|
12 |
class XPipeWikiRobot(ABC):
|
|
|
23 |
self.query_engine = query_engine
|
24 |
|
25 |
def ask(self, question: str) -> Any:
|
26 |
+
return self.query_engine.query(question).response
|
27 |
|
28 |
|
29 |
class XPipeWikiRobotManager(Lifecycle):
|
|
|
57 |
LifecycleHelper.start_if_possible(self.service_context_manager)
|
58 |
LifecycleHelper.start_if_possible(self.storage_context_manager)
|
59 |
index = load_index_from_storage(
|
60 |
+
storage_context=self.storage_context_manager.get_storage_context(),
|
61 |
+
service_context=self.service_context_manager.get_service_context(),
|
62 |
)
|
63 |
self.query_engine = index.as_query_engine(
|
64 |
service_context=self.service_context_manager.get_service_context()
|