pilot.linkstec 0.0.16__py3-none-any.whl → 0.0.18__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pilot.linkstec might be problematic. Click here for more details.
- pilot/config/config_reader.py +0 -2
- pilot/generater/vertexai.py +91 -5
- pilot/processor/__init__.py +0 -0
- pilot/processor/code_processor.py +8 -0
- pilot/processor/code_processor_pipeline.py +14 -0
- {pilot_linkstec-0.0.16.dist-info → pilot_linkstec-0.0.18.dist-info}/METADATA +1 -1
- {pilot_linkstec-0.0.16.dist-info → pilot_linkstec-0.0.18.dist-info}/RECORD +10 -7
- {pilot_linkstec-0.0.16.dist-info → pilot_linkstec-0.0.18.dist-info}/WHEEL +0 -0
- {pilot_linkstec-0.0.16.dist-info → pilot_linkstec-0.0.18.dist-info}/licenses/LICENSE +0 -0
- {pilot_linkstec-0.0.16.dist-info → pilot_linkstec-0.0.18.dist-info}/top_level.txt +0 -0
pilot/config/config_reader.py
CHANGED
pilot/generater/vertexai.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import re
|
|
1
2
|
import threading
|
|
2
3
|
from typing import Dict, Any, Optional
|
|
3
4
|
|
|
@@ -11,7 +12,13 @@ class VertexAISingleton:
|
|
|
11
12
|
_tokenizer_cache = {}
|
|
12
13
|
encoding = None
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
SQL_SYSTEM_PROMPT_EN = (
|
|
16
|
+
"If there is any SQL-related processing \n"
|
|
17
|
+
"1. If there is an SQL statement like \"SELECT COUNT(X) INTO :COLUMN FROM TABLE_NAME;\" please recognize TABLE_NAME as a table."
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def __new__(cls, model_name: str = "gemini-2.5-pro", system_prompt: Optional[str] = None):
|
|
15
22
|
if cls._instance is None:
|
|
16
23
|
with cls._lock:
|
|
17
24
|
if cls._instance is None:
|
|
@@ -19,18 +26,29 @@ class VertexAISingleton:
|
|
|
19
26
|
cls._instance._initialized = False
|
|
20
27
|
return cls._instance
|
|
21
28
|
|
|
22
|
-
def __init__(self, model_name: str = "gemini-2.5-pro"):
|
|
29
|
+
def __init__(self, model_name: str = "gemini-2.5-pro", system_prompt: Optional[str] = None):
|
|
23
30
|
if not self._initialized:
|
|
24
31
|
with self._lock:
|
|
25
32
|
if not self._initialized:
|
|
26
33
|
self.model = GenerativeModel(model_name)
|
|
27
34
|
self.encoding = tiktoken.get_encoding("cl100k_base")
|
|
35
|
+
# system_promptにSQL_SYSTEM_PROMPT_ENを追加
|
|
36
|
+
if system_prompt:
|
|
37
|
+
self.system_prompt = f"{system_prompt.rstrip()}\n\n{self.SQL_SYSTEM_PROMPT_EN}"
|
|
38
|
+
else:
|
|
39
|
+
self.system_prompt = self.SQL_SYSTEM_PROMPT_EN
|
|
28
40
|
self._initialized = True
|
|
41
|
+
else:
|
|
42
|
+
# 既存インスタンスでもsystem_promptを更新可能に
|
|
43
|
+
if system_prompt is not None:
|
|
44
|
+
self.system_prompt = f"{system_prompt.rstrip()}\n\n{self.SQL_SYSTEM_PROMPT_EN}" if system_prompt else self.SQL_SYSTEM_PROMPT_EN
|
|
29
45
|
|
|
30
46
|
def generate_content(self, prompt: str) -> Dict[str, Any]:
|
|
31
47
|
"""複数スレッドから安全に呼び出し可能"""
|
|
32
48
|
try:
|
|
33
|
-
|
|
49
|
+
# system_promptがあれば先頭に付与
|
|
50
|
+
full_prompt = f"{self.system_prompt}\n{prompt}" if getattr(self, "system_prompt", None) else prompt
|
|
51
|
+
response = self.model.generate_content(self.exchange_prompt(full_prompt))
|
|
34
52
|
return {
|
|
35
53
|
"prompt": prompt,
|
|
36
54
|
"response": self._remove_code_fence(response.text),
|
|
@@ -66,7 +84,75 @@ class VertexAISingleton:
|
|
|
66
84
|
lines = lines[:-1]
|
|
67
85
|
return "\n".join(lines)
|
|
68
86
|
|
|
87
|
+
|
|
88
|
+
def exchange_prompt(self, prompt: str) -> str:
|
|
89
|
+
# EXEC SQL ... END-EXEC. のSQL部分を抽出してフラット化
|
|
90
|
+
rtn_prompt = ""
|
|
91
|
+
rtn_prompt = self.fix_initialize(rtn_prompt)
|
|
92
|
+
rtn_prompt = self.extract_and_flatten_sql(rtn_prompt)
|
|
93
|
+
return rtn_prompt
|
|
94
|
+
|
|
95
|
+
def fix_initialize(self, text: str) -> str:
|
|
96
|
+
# SECTION ... EXIT. ブロック内のINITIALIZE文を処理
|
|
97
|
+
def process_section_block(match):
|
|
98
|
+
section_content = match.group(0)
|
|
99
|
+
|
|
100
|
+
# INITIALIZE の行を結合する(SECTION-EXIT間のみ)
|
|
101
|
+
# INITIALIZEで始まる行の次の行が空白+文字列の場合に結合
|
|
102
|
+
pattern_init = r'^(\s*INITIALIZE\s+[^\n]*)\n(\s+[^\n]+(?:\s+[^\n]+)*)'
|
|
103
|
+
|
|
104
|
+
def repl_init(m):
|
|
105
|
+
init_line = m.group(1).rstrip()
|
|
106
|
+
next_lines = m.group(2).strip()
|
|
107
|
+
return f'{init_line} {next_lines}'
|
|
108
|
+
|
|
109
|
+
section_content = re.sub(pattern_init, repl_init, section_content, flags=re.MULTILINE)
|
|
110
|
+
|
|
111
|
+
# ブロック内 COUNT(*) → COUNT(1) へ置換する
|
|
112
|
+
section_content = re.sub(r'COUNT\(\s*\*\s*\)', 'COUNT(1)', section_content, flags=re.IGNORECASE)
|
|
113
|
+
|
|
114
|
+
return section_content
|
|
115
|
+
|
|
116
|
+
# SECTION から EXIT. までのブロックを検索して処理
|
|
117
|
+
section_pattern = r'(\w+\s+SECTION\s*\..*?EXIT\s*\.)'
|
|
118
|
+
text = re.sub(section_pattern, process_section_block, text, flags=re.DOTALL | re.IGNORECASE)
|
|
119
|
+
|
|
120
|
+
return text
|
|
121
|
+
|
|
122
|
+
def replace_aaa_in_section(code: str) -> str:
|
|
123
|
+
"""
|
|
124
|
+
SECTION.~EXIT.ブロック中のAAAをBBBに置換し、全体をstrで返す
|
|
125
|
+
"""
|
|
126
|
+
pattern = r"SECTION.(.*?)(EXIT.)"
|
|
127
|
+
|
|
128
|
+
def repl(m):
|
|
129
|
+
block = m.group(1)
|
|
130
|
+
block_modified = block.replace("AAA", "BBB")
|
|
131
|
+
return f"SECTION.{block_modified}EXIT."
|
|
132
|
+
|
|
133
|
+
result = re.sub(pattern, repl, code, flags=re.DOTALL | re.IGNORECASE)
|
|
134
|
+
return result
|
|
135
|
+
|
|
136
|
+
def extract_and_flatten_sql(self, code):
|
|
137
|
+
# EXEC SQL ... END-EXEC. にマッチ
|
|
138
|
+
pattern = r"EXEC SQL(.*?)END-EXEC\.?"
|
|
139
|
+
|
|
140
|
+
def repl(m):
|
|
141
|
+
# .*?でSQL部分取得
|
|
142
|
+
raw_sql = m.group(1)
|
|
143
|
+
# コメント(*以降)除去(複数行まとめてOK)
|
|
144
|
+
no_comment = re.sub(r"\*.*", "", raw_sql)
|
|
145
|
+
# 改行/連続スペースを単一スペースに
|
|
146
|
+
flattened = re.sub(r"\s+", " ", no_comment).strip()
|
|
147
|
+
# 置換内容
|
|
148
|
+
return f"EXEC SQL {flattened} END-EXEC."
|
|
149
|
+
|
|
150
|
+
# 全て置換
|
|
151
|
+
result = re.sub(pattern, repl, code, flags=re.DOTALL | re.IGNORECASE)
|
|
152
|
+
return result
|
|
153
|
+
|
|
154
|
+
|
|
69
155
|
@classmethod
|
|
70
|
-
def get_instance(cls, model_name: str = "gemini-2.5-pro") -> 'VertexAISingleton':
|
|
156
|
+
def get_instance(cls, model_name: str = "gemini-2.5-pro", system_prompt: Optional[str] = None) -> 'VertexAISingleton':
|
|
71
157
|
"""インスタンスを取得"""
|
|
72
|
-
return cls(model_name)
|
|
158
|
+
return cls(model_name, system_prompt)
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from pilot.processor.code_processor import CodeProcessor
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CodeProcessorPipeline:
|
|
7
|
+
def __init__(self, processors: List[CodeProcessor]):
|
|
8
|
+
self.processors = processors
|
|
9
|
+
|
|
10
|
+
def run(self, lines: List[str]) -> List[str]:
|
|
11
|
+
result = lines
|
|
12
|
+
for processor in self.processors:
|
|
13
|
+
result = processor.process(result)
|
|
14
|
+
return result
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
pilot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
pilot/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
pilot/config/config_reader.py,sha256=
|
|
3
|
+
pilot/config/config_reader.py,sha256=MchG-9j-Xfy8AquL_6tlvqQR65MFJ3c3hwWBl6IF2jw,3750
|
|
4
4
|
pilot/control/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
pilot/control/control_interface.py,sha256=zGv380oQgAKPAIHDHeFdPYzhj2Ngo2T66NWlNloA7vY,124
|
|
6
6
|
pilot/control/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -9,13 +9,16 @@ pilot/conver/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
9
9
|
pilot/conver/converfileEncodding.py,sha256=UqjcWO0bzkuTRHLEWrWJkeo3p-P7WuYE7jFKveyPekA,2781
|
|
10
10
|
pilot/conver/nkf_converter.py,sha256=JqgThmXcdnTGMsLIHUEwe8sc0VGMqDaKCIQTg-UE3WE,1148
|
|
11
11
|
pilot/generater/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
-
pilot/generater/vertexai.py,sha256=
|
|
12
|
+
pilot/generater/vertexai.py,sha256=howYy2fTFWZXr9QEXRs7Z6bNobdBUfZW2bs5au8G0A0,6480
|
|
13
13
|
pilot/job/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
14
|
pilot/job/job_interface.py,sha256=LL0hfuFfnKnkpQD99jv1hkaAIAFM-JJPrX3PFxN6O_A,120
|
|
15
15
|
pilot/job/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
pilot/job/impl/base_job.py,sha256=iojwBJApivsCmHG9HRCJrWUwtbBc_GrCI31xac0JYtE,14053
|
|
17
17
|
pilot/logging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
18
|
pilot/logging/logger.py,sha256=TF7eGr3w8GK5v4sf71lDt97uVoBtCgqrZuCdbMmeQBU,1815
|
|
19
|
+
pilot/processor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
pilot/processor/code_processor.py,sha256=aIjRZ3eoiuLL7_g1LyEF0yhC3puVBZou3JJdKF1sQ2E,183
|
|
21
|
+
pilot/processor/code_processor_pipeline.py,sha256=ZW2JQeAUbH_sYmgh3oI2O10FhbRS9ZNNBnNjjImH9GM,406
|
|
19
22
|
pilot/splitters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
23
|
pilot/splitters/cobolsplitter.py,sha256=oPwxKRjA7TyXWaWV3jdy59lJZy1mRn6yxD9ivqFYCuY,5461
|
|
21
24
|
pilot/unit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -24,8 +27,8 @@ pilot/unit/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
24
27
|
pilot/unit/impl/base_unit.py,sha256=LsFPpL28aSNv5rsZhfKv6CWhAw1XR4n-A6FOn2RBrZo,1272
|
|
25
28
|
pilot/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
29
|
pilot/util/files.py,sha256=v9uzfzo3Aq4xgnUIASEZeBJoA2nD9Qz_EA3P-FwzGFQ,1896
|
|
27
|
-
pilot_linkstec-0.0.
|
|
28
|
-
pilot_linkstec-0.0.
|
|
29
|
-
pilot_linkstec-0.0.
|
|
30
|
-
pilot_linkstec-0.0.
|
|
31
|
-
pilot_linkstec-0.0.
|
|
30
|
+
pilot_linkstec-0.0.18.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
31
|
+
pilot_linkstec-0.0.18.dist-info/METADATA,sha256=QVVptyux79NTqMg3eU5xeR317qLJELBm87GhJFzNeb8,679
|
|
32
|
+
pilot_linkstec-0.0.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
33
|
+
pilot_linkstec-0.0.18.dist-info/top_level.txt,sha256=BijnVJdXnIPxxx3s60M848seL4Z12gNUPod6KPJxK9c,6
|
|
34
|
+
pilot_linkstec-0.0.18.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|