Tnt3o5 commited on
Commit
5c91ccd
·
verified ·
1 Parent(s): 05711b8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +143 -5
README.md CHANGED
@@ -1,5 +1,143 @@
1
- ---
2
- library_name: transformers
3
- tags: []
4
- ---
5
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+
3
+ from openai import OpenAI
4
+
5
+ DEFAULT_QUESTION = """CREATE TABLE entity_a (
6
+ id INTEGER,
7
+ group_id INTEGER,
8
+ org_id INTEGER,
9
+ code VARCHAR(100),
10
+ name VARCHAR(255),
11
+ attr_1 VARCHAR(255),
12
+ attr_2 VARCHAR(255),
13
+ attr_3 TEXT
14
+ );
15
+
16
+ CREATE TABLE entity_b (
17
+ id INTEGER,
18
+ group_id INTEGER,
19
+ entity_a_id INTEGER,
20
+ time_key INTEGER,
21
+ metric_name VARCHAR(255),
22
+ metric_code VARCHAR(100),
23
+ metric_value REAL,
24
+ metric_unit VARCHAR(100)
25
+ );
26
+ ENTITIES = {
27
+ "metric": {
28
+ "metric_code": "METRIC_X",
29
+ "metric_unit": "UNIT_A"
30
+ },
31
+ "entity_a_field": {
32
+ "attr_1": [],
33
+ "attr_2": [],
34
+ "attr_3": [],
35
+ "id": []
36
+ },
37
+ "time_key": [year],
38
+ Query:
39
+
40
+ }
41
+
42
+
43
+ """
44
+
45
+
46
+ class MyModel(object):
47
+ def __init__(self, model_name: str, api_key: str):
48
+ self.model_name = model_name
49
+ self.client = OpenAI(base_url=""", api_key=api_key)
50
+
51
+ def get_prompt(
52
+ self,
53
+ question: str,
54
+ ) -> list[dict[str, str]]:
55
+ return [
56
+ {
57
+ "role": "system",
58
+ "content": """
59
+ You are a problem solving model working on task_description XML block:
60
+ <task_description>You are a specialized Text-to-SQL assistant in the banking domain. Your objective is to translate natural language questions into valid SQLite queries using the provided schema and banking business logic.
61
+
62
+ ### Input:
63
+ - Schema: Table definitions in SQL DDL format.
64
+ - Relationships: Key linking logic between tables (system_data.branch_id = branch.id).
65
+ - Data Content Context:
66
+ Indicator_Categories:
67
+ Group_A:
68
+ description: Primary metrics – inbound type
69
+ rule:
70
+ - metric_code LIKE 'MET_A_%'
71
+
72
+ Group_B:
73
+ description: Primary metrics – outbound type
74
+ rule:
75
+ - metric_code LIKE 'MET_B_%'
76
+
77
+ Group_C:
78
+ description: Stock / snapshot metrics
79
+ rule:
80
+ - metric_code LIKE 'MET_C_%'
81
+
82
+ Group_D:
83
+ description: Exposure / obligation related metrics
84
+ rule:
85
+ - metric_code LIKE 'MET_D_%'
86
+ - metric_code LIKE 'MET_D_TOTAL_%'
87
+ - metric_code = 'MET_D_SPECIAL'
88
+
89
+ Group_E:
90
+ description: Resource mobilization metrics
91
+ rule:
92
+ - metric_code LIKE 'MET_E_%'
93
+
94
+ Group_F:
95
+ description: Ratio & efficiency indicators
96
+ rule:
97
+ - Unit Logic: {Which dmain} data is stored in 'Triệu VND'. If the Question mentions 'Tỷ', multiply the value by 1000.
98
+ - Entities: Extracted key information including data_code, year, and branch filtering criteria.
99
+
100
+ ### Rules:
101
+ 1. ALWAYS perform an INNER JOIN between system_data and branch on system_data.branch_id = branch.id.
102
+ 2. ALWAYS SELECT system_data.data_code, system_data.year, system_data.branch_id, branch.name, system_data.value.
103
+ 3. Use exact Vietnamese accents for location values.
104
+ 4. Use LIKE '%keyword%' for text matching.
105
+ 5. Use UPPERCASE for SQL keywords.
106
+ 6. Output ONLY the SQL query. No explanations or markdown blocks.</task_description>
107
+ You will be given a single task in the question XML block
108
+ Solve only the task in question block.
109
+ Generate only the answer, do not generate anything else
110
+ """,
111
+ },
112
+ {
113
+ "role": "user",
114
+ "content": f"""
115
+
116
+ Now for the real task, solve the task in question block.
117
+ Generate only the solution, do not generate anything else
118
+ <question>{question}</question>
119
+ """,
120
+ },
121
+ ]
122
+
123
+ def invoke(self, question: str) -> str:
124
+ chat_response = self.client.chat.completions.create(
125
+ model=self.model_name,
126
+ messages=self.get_prompt(question),
127
+ temperature=0,
128
+ reasoning_effort="none",
129
+ )
130
+ return chat_response.choices[0].message.content
131
+
132
+
133
+ if __name__ == "__main__":
134
+ parser = argparse.ArgumentParser()
135
+ parser.add_argument("--question", type=str, default=DEFAULT_QUESTION, required=False)
136
+ parser.add_argument("--api-key", type=str, default="", required=False)
137
+ parser.add_argument("--model", type=str, default="model", required=False)
138
+
139
+ args = parser.parse_args()
140
+
141
+ client = MyModel(model_name=args.model, api_key=args.api_key)
142
+
143
+ print(client.invoke(args.question))