Spaces:
Sleeping
Sleeping
NickNYU
commited on
Commit
·
9ecd254
1
Parent(s):
01d6691
fix changes
Browse files- core/helper.py +4 -4
- langchain_manager/manager.py +9 -7
- xpipe_wiki/manager_factory.py +10 -7
- xpipe_wiki/robot_manager.py +8 -7
core/helper.py
CHANGED
@@ -4,28 +4,28 @@ from core.lifecycle import Lifecycle
|
|
4 |
class LifecycleHelper:
|
5 |
@classmethod
|
6 |
def initialize_if_possible(cls, ls: Lifecycle) -> None:
|
7 |
-
if isinstance(ls, Lifecycle) and ls.
|
8 |
ls.lifecycle_state.phase
|
9 |
):
|
10 |
ls.initialize()
|
11 |
|
12 |
@classmethod
|
13 |
def start_if_possible(cls, ls: Lifecycle) -> None:
|
14 |
-
if isinstance(ls, Lifecycle) and ls.
|
15 |
ls.lifecycle_state.phase
|
16 |
):
|
17 |
ls.start()
|
18 |
|
19 |
@classmethod
|
20 |
def stop_if_possible(cls, ls: Lifecycle) -> None:
|
21 |
-
if isinstance(ls, Lifecycle) and ls.
|
22 |
ls.lifecycle_state.phase
|
23 |
):
|
24 |
ls.stop()
|
25 |
|
26 |
@classmethod
|
27 |
def dispose_if_possible(cls, ls: Lifecycle) -> None:
|
28 |
-
if isinstance(ls, Lifecycle) and ls.
|
29 |
ls.lifecycle_state.phase
|
30 |
):
|
31 |
ls.dispose()
|
|
|
4 |
class LifecycleHelper:
|
5 |
@classmethod
|
6 |
def initialize_if_possible(cls, ls: Lifecycle) -> None:
|
7 |
+
if isinstance(ls, Lifecycle) and ls.lifecycle_state.can_initialize(
|
8 |
ls.lifecycle_state.phase
|
9 |
):
|
10 |
ls.initialize()
|
11 |
|
12 |
@classmethod
|
13 |
def start_if_possible(cls, ls: Lifecycle) -> None:
|
14 |
+
if isinstance(ls, Lifecycle) and ls.lifecycle_state.can_start(
|
15 |
ls.lifecycle_state.phase
|
16 |
):
|
17 |
ls.start()
|
18 |
|
19 |
@classmethod
|
20 |
def stop_if_possible(cls, ls: Lifecycle) -> None:
|
21 |
+
if isinstance(ls, Lifecycle) and ls.lifecycle_state.can_stop(
|
22 |
ls.lifecycle_state.phase
|
23 |
):
|
24 |
ls.stop()
|
25 |
|
26 |
@classmethod
|
27 |
def dispose_if_possible(cls, ls: Lifecycle) -> None:
|
28 |
+
if isinstance(ls, Lifecycle) and ls.lifecycle_state.can_dispose(
|
29 |
ls.lifecycle_state.phase
|
30 |
):
|
31 |
ls.dispose()
|
langchain_manager/manager.py
CHANGED
@@ -24,16 +24,18 @@ class BaseLangChainManager(ABC):
|
|
24 |
class LangChainAzureManager(BaseLangChainManager):
|
25 |
def __init__(self) -> None:
|
26 |
super().__init__()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Override
|
29 |
def get_embedding(self) -> LCEmbeddings:
|
30 |
-
return
|
31 |
|
32 |
# Override
|
33 |
def get_llm(self) -> BaseLanguageModel:
|
34 |
-
return
|
35 |
-
deployment_name="text-davinci-003",
|
36 |
-
# model_name="text-davinci-003",
|
37 |
-
model="text-davinci-003",
|
38 |
-
client=None,
|
39 |
-
)
|
|
|
24 |
class LangChainAzureManager(BaseLangChainManager):
|
25 |
def __init__(self) -> None:
|
26 |
super().__init__()
|
27 |
+
self.embedding = OpenAIEmbeddings(client=None, chunk_size=1)
|
28 |
+
self.llm = AzureOpenAI(
|
29 |
+
deployment_name="text-davinci-003",
|
30 |
+
# model_name="text-davinci-003",
|
31 |
+
model="text-davinci-003",
|
32 |
+
client=None,
|
33 |
+
)
|
34 |
|
35 |
# Override
|
36 |
def get_embedding(self) -> LCEmbeddings:
|
37 |
+
return self.embedding
|
38 |
|
39 |
# Override
|
40 |
def get_llm(self) -> BaseLanguageModel:
|
41 |
+
return self.llm
|
|
|
|
|
|
|
|
|
|
xpipe_wiki/manager_factory.py
CHANGED
@@ -9,20 +9,22 @@ class XPipeRobotRevision(enum.Enum):
|
|
9 |
SIMPLE_OPENAI_VERSION_0 = 1
|
10 |
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
CAPABLE: Dict[XPipeRobotRevision, XPipeWikiRobotManager] = {XPipeRobotRevision.SIMPLE_OPENAI_VERSION_0: XPipeWikiRobotManager()}
|
15 |
-
"""
|
16 |
|
17 |
|
18 |
class XPipeRobotManagerFactory:
|
|
|
|
|
|
|
|
|
19 |
@classmethod
|
20 |
def get_or_create(cls, revision: XPipeRobotRevision) -> XPipeWikiRobotManager:
|
21 |
-
if CAPABLE.get(revision) is not None:
|
22 |
-
return CAPABLE[revision]
|
23 |
if revision == XPipeRobotRevision.SIMPLE_OPENAI_VERSION_0:
|
24 |
manager = cls.create_simple_openai_version_0()
|
25 |
-
CAPABLE[revision] = manager
|
26 |
return manager
|
27 |
|
28 |
@classmethod
|
@@ -48,3 +50,4 @@ class XPipeRobotManagerFactory:
|
|
48 |
LifecycleHelper.initialize_if_possible(robot_manager)
|
49 |
LifecycleHelper.start_if_possible(robot_manager)
|
50 |
return robot_manager
|
|
|
|
9 |
SIMPLE_OPENAI_VERSION_0 = 1
|
10 |
|
11 |
|
12 |
+
|
13 |
+
|
|
|
|
|
14 |
|
15 |
|
16 |
class XPipeRobotManagerFactory:
|
17 |
+
"""
|
18 |
+
CAPABLE: Dict[XPipeRobotRevision, XPipeWikiRobotManager] = {XPipeRobotRevision.SIMPLE_OPENAI_VERSION_0: XPipeWikiRobotManager()}
|
19 |
+
"""
|
20 |
+
CAPABLE = dict()
|
21 |
@classmethod
|
22 |
def get_or_create(cls, revision: XPipeRobotRevision) -> XPipeWikiRobotManager:
|
23 |
+
if cls.CAPABLE.get(revision) is not None:
|
24 |
+
return cls.CAPABLE[revision]
|
25 |
if revision == XPipeRobotRevision.SIMPLE_OPENAI_VERSION_0:
|
26 |
manager = cls.create_simple_openai_version_0()
|
27 |
+
cls.CAPABLE[revision] = manager
|
28 |
return manager
|
29 |
|
30 |
@classmethod
|
|
|
50 |
LifecycleHelper.initialize_if_possible(robot_manager)
|
51 |
LifecycleHelper.start_if_possible(robot_manager)
|
52 |
return robot_manager
|
53 |
+
|
xpipe_wiki/robot_manager.py
CHANGED
@@ -36,6 +36,7 @@ class XPipeWikiRobotManager(Lifecycle):
|
|
36 |
class AzureXPipeWikiRobotManager(XPipeWikiRobotManager):
|
37 |
service_context_manager: ServiceContextManager
|
38 |
storage_context_manager: StorageContextManager
|
|
|
39 |
|
40 |
def __init__(
|
41 |
self,
|
@@ -47,13 +48,7 @@ class AzureXPipeWikiRobotManager(XPipeWikiRobotManager):
|
|
47 |
self.storage_context_manager = storage_context_manager
|
48 |
|
49 |
def get_robot(self) -> XPipeWikiRobot:
|
50 |
-
|
51 |
-
storage_context=self.storage_context_manager.get_storage_context()
|
52 |
-
)
|
53 |
-
query_engine = index.as_query_engine(
|
54 |
-
service_context=self.service_context_manager.get_service_context()
|
55 |
-
)
|
56 |
-
return AzureOpenAIXPipeWikiRobot(query_engine)
|
57 |
|
58 |
def do_init(self) -> None:
|
59 |
LifecycleHelper.initialize_if_possible(self.service_context_manager)
|
@@ -62,6 +57,12 @@ class AzureXPipeWikiRobotManager(XPipeWikiRobotManager):
|
|
62 |
def do_start(self) -> None:
|
63 |
LifecycleHelper.start_if_possible(self.service_context_manager)
|
64 |
LifecycleHelper.start_if_possible(self.storage_context_manager)
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
def do_stop(self) -> None:
|
67 |
LifecycleHelper.stop_if_possible(self.storage_context_manager)
|
|
|
36 |
class AzureXPipeWikiRobotManager(XPipeWikiRobotManager):
|
37 |
service_context_manager: ServiceContextManager
|
38 |
storage_context_manager: StorageContextManager
|
39 |
+
query_engine: BaseQueryEngine
|
40 |
|
41 |
def __init__(
|
42 |
self,
|
|
|
48 |
self.storage_context_manager = storage_context_manager
|
49 |
|
50 |
def get_robot(self) -> XPipeWikiRobot:
|
51 |
+
return AzureOpenAIXPipeWikiRobot(self.query_engine)
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
def do_init(self) -> None:
|
54 |
LifecycleHelper.initialize_if_possible(self.service_context_manager)
|
|
|
57 |
def do_start(self) -> None:
|
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()
|
65 |
+
)
|
66 |
|
67 |
def do_stop(self) -> None:
|
68 |
LifecycleHelper.stop_if_possible(self.storage_context_manager)
|