-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
145 lines (135 loc) · 4.59 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright 2024-present Kensho Technologies, LLC.
from models import (
OpenAIChatModel,
OpenAIAssistantModel,
HFChatModel,
HFModel,
BedRockModel,
GeminiModel,
)
from prompt import PromptCreator
# Tasks: ['CodeTAT-QA', 'TAT-QA', 'CodeFinQA', 'FinKnow', 'FinCode', 'ConvFinQA']
code_prompt_creator = PromptCreator(
{
"FinKnow": "prompts/finknow.json",
"CodeTAT-QA": "prompts/context_code.json",
"CodeFinQA": "prompts/codefinqa_code.json",
"FinCode": "prompts/fincode_code.json",
"ConvFinQA": "prompts/convfinqa.json",
"TAT-QA": "prompts/tatqa_e.json",
}
)
cot_prompt_creator = PromptCreator(
{
"FinKnow": "prompts/finknow.json",
"CodeTAT-QA": "prompts/context_cot.json",
"CodeFinQA": "prompts/codefinqa_cot.json",
"FinCode": "prompts/fincode_cot.json",
"ConvFinQA": "prompts/convfinqa.json",
"TAT-QA": "prompts/tatqa_e.json",
}
)
# All names must be in the form {unique model name}-{cot|code}. The cache is
# defined by the unique model name
_CONFIG = {
"gemini-pro-cot": lambda: (GeminiModel("gemini-pro"), cot_prompt_creator),
"gemini-pro-code": lambda: (GeminiModel("gemini-pro"), code_prompt_creator),
"claude-3-sonnet-code": lambda: (
BedRockModel("anthropic.claude-3-sonnet-20240229-v1:0"),
code_prompt_creator,
),
"claude-3-sonnet-cot": lambda: (
BedRockModel("anthropic.claude-3-sonnet-20240229-v1:0"),
cot_prompt_creator,
),
"gpt-4-code": lambda: (OpenAIChatModel("gpt-4"), code_prompt_creator),
"gpt-4-cot": lambda: (OpenAIChatModel("gpt-4"), cot_prompt_creator),
"gpt-3.5-code": lambda: (OpenAIChatModel("gpt-3.5-turbo"), code_prompt_creator),
"gpt-3.5-cot": lambda: (OpenAIChatModel("gpt-3.5-turbo"), cot_prompt_creator),
# This has a built in code executor, so we only need to give it the cot prompt
"gpt-4-assist-no-code-cot": lambda: (
OpenAIAssistantModel("gpt-4-turbo-preview"),
cot_prompt_creator,
),
"gpt-4-assist-code": lambda: (
OpenAIAssistantModel(
"gpt-4-turbo-preview", tools=[{"type": "code_interpreter"}]
),
cot_prompt_creator,
),
"claude-2-code": lambda: (BedRockModel("anthropic.claude-v2"), code_prompt_creator),
"claude-2-cot": lambda: (BedRockModel("anthropic.claude-v2"), cot_prompt_creator),
"Mistral-7B-v0.1-cot": lambda: (
HFModel("mistralai/Mistral-7B-v0.1", generation_kwargs={"max_new_tokens": 256}),
cot_prompt_creator,
),
# None of the llama 2 models seem to follow the right output format for some reason?
"llama-2-7b-chat-code": lambda: (
HFChatModel("meta-llama/Llama-2-7b-chat-hf"),
code_prompt_creator,
),
"llama-2-7b-chat-cot": lambda: (
HFChatModel("meta-llama/Llama-2-7b-chat-hf"),
cot_prompt_creator,
),
"llama-2-13b-chat-code": lambda: (
HFChatModel("meta-llama/Llama-2-13b-chat-hf"),
code_prompt_creator,
),
"llama-2-13b-chat-cot": lambda: (
HFChatModel("meta-llama/Llama-2-13b-chat-hf"),
cot_prompt_creator,
),
"llama-2-70b-chat-code": lambda: (
HFChatModel("meta-llama/Llama-2-70b-chat-hf", device_map="auto"),
code_prompt_creator,
),
"llama-2-70b-chat-cot": lambda: (
HFChatModel("meta-llama/Llama-2-70b-chat-hf", device_map="auto"),
cot_prompt_creator,
),
"zepyhr-cot": lambda: (
HFChatModel(
"HuggingFaceH4/zephyr-7b-beta",
device_map="auto",
generation_kwargs={"max_new_tokens": 2048, "pad_token_id": 0},
),
cot_prompt_creator,
),
"zepyhr-code": lambda: (
HFChatModel(
"HuggingFaceH4/zephyr-7b-beta",
device_map="auto",
generation_kwargs={"max_new_tokens": 2048, "pad_token_id": 0},
),
code_prompt_creator,
),
}
def load_config(name):
return _CONFIG[name]()
def load_hf_config(
hugging_face_model_name_or_path,
prompt_style,
is_chat_model,
device_map,
max_new_tokens,
):
if is_chat_model:
m = HFChatModel(
hugging_face_model_name_or_path,
device_map=device_map,
generation_kwargs={
"max_new_tokens": max_new_tokens,
},
)
else:
m = HFModel(
hugging_face_model_name_or_path,
device_map=device_map,
generation_kwargs={"max_new_tokens": max_new_tokens},
)
if prompt_style == "cot":
p = cot_prompt_creator
else:
p = code_prompt_creator
return m, p