-
Notifications
You must be signed in to change notification settings - Fork 17
/
config.py
93 lines (78 loc) · 2.45 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import registry
from utils import get_widget_index_name
widget_index = dict(
type="index.weaviate.WeaviateIndex",
index_name=get_widget_index_name(),
text_key="content",
)
app_info_index = dict(
type="index.weaviate.WeaviateIndex",
index_name="AppInfoV1",
text_key="question",
extra_keys=["answer", "suggested_follow_ups"],
)
scraped_sites_index = dict(
type="index.weaviate.WeaviateIndex",
index_name="IndexV1",
text_key="content",
extra_keys=["url"],
)
dapps_index = dict(
type="index.weaviate.WeaviateIndex",
index_name="Web3Apps",
text_key="description",
extra_keys=["url","name"],
)
api_docs_index = dict(
type="index.weaviate.WeaviateIndex",
index_name="APIDocsV1",
text_key="description",
extra_keys=["spec"],
)
crypto_tokens_index = dict(
type="index.weaviate.WeaviateIndex",
index_name="CryptoTokensV1",
text_key="canonical_id",
extra_keys=["name", "symbol"],
)
default_config = dict(
type="system.System",
chat=dict(
type="chat.chatgpt_function_call.ChatGPTFunctionCallChat",
model_name='gpt-4-0613',
widget_index=widget_index,
top_k=32,
)
)
def initialize(cfg):
if isinstance(cfg, dict):
# recursively initialize objects
_cfg = {k: initialize(v) for k, v in cfg.items()}
if 'type' in _cfg and not _cfg.get('_streaming'):
_type = _cfg.pop('type')
_cls = registry.get_class(_type)
print(f'Initializing instance of type: {_type}')
return _cls(**_cfg)
return _cfg
elif isinstance(cfg, list):
# recursively initialize items in list
_cfg = [initialize(v) for v in cfg]
return _cfg
return cfg
def initialize_streaming(cfg, new_token_handler):
if isinstance(cfg, dict):
# recursively initialize objects
_cfg = {k: initialize_streaming(v, new_token_handler) for k, v in cfg.items()}
if 'type' in _cfg and _cfg.get('_streaming'):
_type = _cfg.pop('type')
_cls = registry.get_class(_type)
print(f'Initializing instance of type: {_type}')
return _cls(new_token_handler=new_token_handler, **_cfg)
return _cfg
elif isinstance(cfg, list):
# recursively initialize items in list
_cfg = [initialize_streaming(v, new_token_handler) for v in cfg]
return _cfg
return cfg
def initialize_system(config):
return initialize(config)