pilot.linkstec 0.0.22__py3-none-any.whl → 0.0.26__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.
- pilot/conver/commentRemover.py +100 -0
- pilot/conver/converfileEncodding.py +4 -32
- pilot/generater/vertexai.py +9 -86
- pilot/job/job_interface.py +1 -0
- {pilot_linkstec-0.0.22.dist-info → pilot_linkstec-0.0.26.dist-info}/METADATA +1 -1
- {pilot_linkstec-0.0.22.dist-info → pilot_linkstec-0.0.26.dist-info}/RECORD +9 -8
- {pilot_linkstec-0.0.22.dist-info → pilot_linkstec-0.0.26.dist-info}/WHEEL +0 -0
- {pilot_linkstec-0.0.22.dist-info → pilot_linkstec-0.0.26.dist-info}/licenses/LICENSE +0 -0
- {pilot_linkstec-0.0.22.dist-info → pilot_linkstec-0.0.26.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
class CommentRemover:
|
|
6
|
+
"""
|
|
7
|
+
ColdFusion (.cfm, .cfc) と JavaScript (.js) のコメント削除クラス
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
def __init__(self, file_path: str):
|
|
11
|
+
self.file_path = Path(file_path)
|
|
12
|
+
self.text = ''
|
|
13
|
+
self.cleaned_text = ''
|
|
14
|
+
|
|
15
|
+
def load(self, encoding='utf-8'):
|
|
16
|
+
try:
|
|
17
|
+
with self.file_path.open('r', encoding=encoding) as f:
|
|
18
|
+
self.text = f.read()
|
|
19
|
+
except Exception as e:
|
|
20
|
+
print(f"Failed to load file {self.file_path}: {e}", file=sys.stderr)
|
|
21
|
+
raise
|
|
22
|
+
|
|
23
|
+
def save(self, output_path: str, encoding='utf-8'):
|
|
24
|
+
try:
|
|
25
|
+
with open(output_path, 'w', encoding=encoding) as f:
|
|
26
|
+
f.write(self.cleaned_text)
|
|
27
|
+
except Exception as e:
|
|
28
|
+
print(f"Failed to save file {output_path}: {e}", file=sys.stderr)
|
|
29
|
+
raise
|
|
30
|
+
|
|
31
|
+
def remove_comments(self):
|
|
32
|
+
ext = self.file_path.suffix.lower()
|
|
33
|
+
if ext in ['.cfm', '.cfc']:
|
|
34
|
+
self.cleaned_text = self.remove_coldfusion_comments(self.text)
|
|
35
|
+
elif ext == '.js':
|
|
36
|
+
self.cleaned_text = self.remove_js_comments(self.text)
|
|
37
|
+
elif ext in ['.cbl', '.cob', '.cobol']:
|
|
38
|
+
self.cleaned_text = self.remove_cobol_comments(self.text)
|
|
39
|
+
else:
|
|
40
|
+
print(f"Unsupported file extension: {ext}, no comment removal applied.", file=sys.stderr)
|
|
41
|
+
self.cleaned_text = self.text
|
|
42
|
+
|
|
43
|
+
def remove_coldfusion_comments(self, text: str) -> str:
|
|
44
|
+
pattern_cftag = r'<!---(?:.|\n)*?--->'
|
|
45
|
+
pattern_block = r'/\*(?:.|\n)*?\*/'
|
|
46
|
+
pattern_line = r'//.*?$'
|
|
47
|
+
|
|
48
|
+
text = re.sub(pattern_cftag, '', text, flags=re.MULTILINE)
|
|
49
|
+
text = re.sub(pattern_block, '', text, flags=re.MULTILINE)
|
|
50
|
+
text = re.sub(pattern_line, '', text, flags=re.MULTILINE)
|
|
51
|
+
return text
|
|
52
|
+
|
|
53
|
+
def remove_js_comments(self, text: str) -> str:
|
|
54
|
+
pattern_block = r'/\*(?:.|\n)*?\*/'
|
|
55
|
+
pattern_line = r'//.*?$'
|
|
56
|
+
|
|
57
|
+
text = re.sub(pattern_block, '', text, flags=re.MULTILINE)
|
|
58
|
+
text = re.sub(pattern_line, '', text, flags=re.MULTILINE)
|
|
59
|
+
return text
|
|
60
|
+
|
|
61
|
+
def remove_cobol_comments(self, text: str) -> str:
|
|
62
|
+
"""
|
|
63
|
+
COBOLのコメント行、および方言の行内コメント *>以降を削除
|
|
64
|
+
|
|
65
|
+
・固定形式コメント行
|
|
66
|
+
行頭が '*'(先頭1文字目が*)の行はコメント → 削除
|
|
67
|
+
または7文字目が '*'の行もコメント → 削除
|
|
68
|
+
|
|
69
|
+
・行内コメント (方言)
|
|
70
|
+
'*> '以降はコメント → 削除
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
lines = text.splitlines()
|
|
74
|
+
cleaned_lines = []
|
|
75
|
+
|
|
76
|
+
for line in lines:
|
|
77
|
+
# 固定長形式にあわせて7文字目 (index 6)を判定
|
|
78
|
+
# 行長が7未満でも対応 (存在しなければFalse)
|
|
79
|
+
is_comment_line = False
|
|
80
|
+
|
|
81
|
+
if line.startswith('*'):
|
|
82
|
+
is_comment_line = True
|
|
83
|
+
elif len(line) >= 7 and line[6] == '*':
|
|
84
|
+
is_comment_line = True
|
|
85
|
+
|
|
86
|
+
if is_comment_line:
|
|
87
|
+
# コメント行なのでスキップ
|
|
88
|
+
continue
|
|
89
|
+
|
|
90
|
+
# 行内コメント *> の扱い
|
|
91
|
+
# 行の途中に '*> ' (*>に続く空白も含む) があればその位置で切り捨てる
|
|
92
|
+
comment_pos = line.find('*>')
|
|
93
|
+
if comment_pos != -1:
|
|
94
|
+
# 行内コメント開始位置でカット(空白も含め全部削除)
|
|
95
|
+
# 例えば 'MOVE X TO Y *> このコメント' => 'MOVE X TO Y '
|
|
96
|
+
line = line[:comment_pos].rstrip()
|
|
97
|
+
|
|
98
|
+
cleaned_lines.append(line)
|
|
99
|
+
|
|
100
|
+
return '\n'.join(cleaned_lines)
|
|
@@ -10,14 +10,15 @@ def nkf_convert(file_path, nkf_args):
|
|
|
10
10
|
:param nkf_args: nkf に渡す引数のリスト(例: ['-w'])
|
|
11
11
|
"""
|
|
12
12
|
# nkfコマンドの引数にファイルパスを追加
|
|
13
|
-
|
|
13
|
+
cmd = ['nkf'] + nkf_args + [file_path]
|
|
14
14
|
|
|
15
|
-
cmd =
|
|
15
|
+
#cmd = 'nkf32' + ' ' + arg1 + ' '+ arg2 +' '+ file_path
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
try:
|
|
19
19
|
# nkfを実行し標準出力を取得
|
|
20
|
-
result = subprocess.run(
|
|
20
|
+
result = subprocess.run(
|
|
21
|
+
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
|
|
21
22
|
print(f"nkfの実行完了しました: {file_path}")
|
|
22
23
|
except subprocess.CalledProcessError as e:
|
|
23
24
|
print(f"nkfの実行でエラーが発生しました: {e.stderr.decode()}", file=sys.stderr)
|
|
@@ -46,32 +47,3 @@ def nkf_convert(file_path, nkf_args):
|
|
|
46
47
|
# output = nkf_convert(file_path, nkf_args)
|
|
47
48
|
|
|
48
49
|
|
|
49
|
-
if __name__ == "__main__":
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
target_dir = r'D:\work\fullsource'
|
|
53
|
-
nkf_args = ['-w', '--overwrite']
|
|
54
|
-
#extensions = (
|
|
55
|
-
# '.cfc', '.cfm', '.cob', '.cobol', '.cpy', '.csh', '.css', '.ctl',
|
|
56
|
-
# '.htm', '.html', '.js', '.sh', '.sql', '.tpl', '.txt'
|
|
57
|
-
#)
|
|
58
|
-
extensions = ('.cnd','.cng','int')
|
|
59
|
-
for root, dirs, files in os.walk(target_dir):
|
|
60
|
-
for file in files:
|
|
61
|
-
if file.lower().endswith(extensions):
|
|
62
|
-
filepath = os.path.join(root, file)
|
|
63
|
-
output = nkf_convert([filepath], nkf_args)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
#if output is not None:
|
|
67
|
-
# 結果を標準出力にバイナリのまま書き出す場合
|
|
68
|
-
# sys.stdout.buffer.write(output)
|
|
69
|
-
|
|
70
|
-
# あるいはUTF-8等に応じてデコードして表示する場合
|
|
71
|
-
# 一旦utf-8デコードを試みる例(必要に応じて変更してください)
|
|
72
|
-
# try:
|
|
73
|
-
# decoded_output = output.decode('utf-8')
|
|
74
|
-
# print(decoded_output)
|
|
75
|
-
# except UnicodeDecodeError:
|
|
76
|
-
# print("utf-8へのデコードに失敗しました。バイナリデータとして出力します。", file=sys.stderr)
|
|
77
|
-
# sys.stdout.buffer.write(output)
|
pilot/generater/vertexai.py
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
import re
|
|
2
1
|
import threading
|
|
3
2
|
from typing import Dict, Any, Optional
|
|
4
3
|
|
|
5
4
|
import tiktoken
|
|
6
|
-
from vertexai.generative_models import GenerativeModel, ChatSession
|
|
7
|
-
|
|
5
|
+
from vertexai.generative_models import GenerativeModel, ChatSession
|
|
6
|
+
import os
|
|
8
7
|
|
|
9
8
|
class VertexAISingleton:
|
|
10
9
|
_instance: Optional['VertexAISingleton'] = None
|
|
10
|
+
|
|
11
|
+
|
|
11
12
|
_lock = threading.Lock()
|
|
12
13
|
_tokenizer_cache = {}
|
|
13
14
|
encoding = None
|
|
14
15
|
|
|
15
|
-
|
|
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):
|
|
16
|
+
def __new__(cls, model_name: str = "gemini-2.5-pro"):
|
|
22
17
|
if cls._instance is None:
|
|
23
18
|
with cls._lock:
|
|
24
19
|
if cls._instance is None:
|
|
@@ -26,36 +21,18 @@ class VertexAISingleton:
|
|
|
26
21
|
cls._instance._initialized = False
|
|
27
22
|
return cls._instance
|
|
28
23
|
|
|
29
|
-
def __init__(self, model_name: str = "gemini-2.5-pro"
|
|
24
|
+
def __init__(self, model_name: str = "gemini-2.5-pro"):
|
|
30
25
|
if not self._initialized:
|
|
31
26
|
with self._lock:
|
|
32
27
|
if not self._initialized:
|
|
33
28
|
self.model = GenerativeModel(model_name)
|
|
34
29
|
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
|
|
40
30
|
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
|
|
45
31
|
|
|
46
32
|
def generate_content(self, prompt: str) -> Dict[str, Any]:
|
|
47
33
|
"""複数スレッドから安全に呼び出し可能"""
|
|
48
34
|
try:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
generation_config = types.GenerateContentConfig(
|
|
52
|
-
system_instruction = self.system_prompt
|
|
53
|
-
)
|
|
54
|
-
prompt = self.exchange_prompt(prompt)
|
|
55
|
-
response = self.model.generate_content(
|
|
56
|
-
contents=prompt, # 引数名を明示
|
|
57
|
-
generation_config = generation_config # 正しい名前で渡す
|
|
58
|
-
)
|
|
35
|
+
response = self.model.generate_content(prompt)
|
|
59
36
|
return {
|
|
60
37
|
"prompt": prompt,
|
|
61
38
|
"response": self._remove_code_fence(response.text),
|
|
@@ -91,61 +68,7 @@ class VertexAISingleton:
|
|
|
91
68
|
lines = lines[:-1]
|
|
92
69
|
return "\n".join(lines)
|
|
93
70
|
|
|
94
|
-
|
|
95
|
-
def exchange_prompt(self, prompt: str) -> str:
|
|
96
|
-
# EXEC SQL ... END-EXEC. のSQL部分を抽出してフラット化
|
|
97
|
-
rtn_prompt = self.fix_initialize(prompt)
|
|
98
|
-
rtn_prompt = self.extract_and_flatten_sql(rtn_prompt)
|
|
99
|
-
return rtn_prompt
|
|
100
|
-
|
|
101
|
-
def fix_initialize(self, text: str) -> str:
|
|
102
|
-
# SECTION ... EXIT. ブロック内のINITIALIZE文を処理
|
|
103
|
-
def process_section_block(match):
|
|
104
|
-
section_content = match.group(0)
|
|
105
|
-
|
|
106
|
-
# INITIALIZE の行を結合する(SECTION-EXIT間のみ)
|
|
107
|
-
# INITIALIZEで始まる行の次の行が空白+文字列の場合に結合
|
|
108
|
-
pattern_init = r'^(\s*INITIALIZE\s+[^\n]*)\n(\s+[^\n]+(?:\s+[^\n]+)*)'
|
|
109
|
-
|
|
110
|
-
def repl_init(m):
|
|
111
|
-
init_line = m.group(1).rstrip()
|
|
112
|
-
next_lines = m.group(2).strip()
|
|
113
|
-
return f'{init_line} {next_lines}'
|
|
114
|
-
|
|
115
|
-
section_content = re.sub(pattern_init, repl_init, section_content, flags=re.MULTILINE)
|
|
116
|
-
|
|
117
|
-
# ブロック内 COUNT(*) → COUNT(1) へ置換する
|
|
118
|
-
section_content = re.sub(r'COUNT\(\s*\*\s*\)', 'COUNT(1)', section_content, flags=re.IGNORECASE)
|
|
119
|
-
|
|
120
|
-
return section_content
|
|
121
|
-
|
|
122
|
-
# SECTION から EXIT. までのブロックを検索して処理
|
|
123
|
-
section_pattern = r'(\w+\s+SECTION\s*\..*?EXIT\s*\.)'
|
|
124
|
-
text = re.sub(section_pattern, process_section_block, text, flags=re.DOTALL | re.IGNORECASE)
|
|
125
|
-
|
|
126
|
-
return text
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def extract_and_flatten_sql(self, code):
|
|
130
|
-
# EXEC SQL ... END-EXEC. にマッチ
|
|
131
|
-
pattern = r"EXEC SQL(.*?)END-EXEC\.?"
|
|
132
|
-
|
|
133
|
-
def repl(m):
|
|
134
|
-
# .*?でSQL部分取得
|
|
135
|
-
raw_sql = m.group(1)
|
|
136
|
-
# コメント(*以降)除去(複数行まとめてOK)
|
|
137
|
-
no_comment = re.sub(r"\*.*", "", raw_sql)
|
|
138
|
-
# 改行/連続スペースを単一スペースに
|
|
139
|
-
flattened = re.sub(r"\s+", " ", no_comment).strip()
|
|
140
|
-
# 置換内容
|
|
141
|
-
return f"EXEC SQL {flattened} END-EXEC."
|
|
142
|
-
|
|
143
|
-
# 全て置換
|
|
144
|
-
result = re.sub(pattern, repl, code, flags=re.DOTALL | re.IGNORECASE)
|
|
145
|
-
return result
|
|
146
|
-
|
|
147
|
-
|
|
148
71
|
@classmethod
|
|
149
|
-
def get_instance(cls, model_name: str = "gemini-2.5-pro"
|
|
72
|
+
def get_instance(cls, model_name: str = "gemini-2.5-pro") -> 'VertexAISingleton':
|
|
150
73
|
"""インスタンスを取得"""
|
|
151
|
-
return cls(model_name
|
|
74
|
+
return cls(model_name)
|
pilot/job/job_interface.py
CHANGED
|
@@ -6,12 +6,13 @@ pilot/control/control_interface.py,sha256=zGv380oQgAKPAIHDHeFdPYzhj2Ngo2T66NWlNl
|
|
|
6
6
|
pilot/control/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
7
|
pilot/control/impl/base_controller.py,sha256=h-A2X4BD_4GGQ0BjCXv_tcO8XdM8_YjXHDIZzvdzyjQ,1634
|
|
8
8
|
pilot/conver/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
pilot/conver/
|
|
9
|
+
pilot/conver/commentRemover.py,sha256=S8uwp9Glp0bdv4EFqf62WIcOTLiJZdracG2FAMKY1EY,3777
|
|
10
|
+
pilot/conver/converfileEncodding.py,sha256=EK2zrVbRjSPEljR3myq_ZEDJkM7i79ol9lbVM_Khbok,1596
|
|
10
11
|
pilot/conver/nkf_converter.py,sha256=JqgThmXcdnTGMsLIHUEwe8sc0VGMqDaKCIQTg-UE3WE,1148
|
|
11
12
|
pilot/generater/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
-
pilot/generater/vertexai.py,sha256=
|
|
13
|
+
pilot/generater/vertexai.py,sha256=SOFfl0qCuLhfjeIoSU7Tk-I7ZB6ZrOyGme2rXDYCGzk,2599
|
|
13
14
|
pilot/job/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
-
pilot/job/job_interface.py,sha256=
|
|
15
|
+
pilot/job/job_interface.py,sha256=EKtuj0IcdolP494aAgTtctgamyQIoFXVwRORwOQck7A,124
|
|
15
16
|
pilot/job/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
17
|
pilot/job/impl/base_job.py,sha256=iojwBJApivsCmHG9HRCJrWUwtbBc_GrCI31xac0JYtE,14053
|
|
17
18
|
pilot/logging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -27,8 +28,8 @@ pilot/unit/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
27
28
|
pilot/unit/impl/base_unit.py,sha256=LsFPpL28aSNv5rsZhfKv6CWhAw1XR4n-A6FOn2RBrZo,1272
|
|
28
29
|
pilot/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
30
|
pilot/util/files.py,sha256=v9uzfzo3Aq4xgnUIASEZeBJoA2nD9Qz_EA3P-FwzGFQ,1896
|
|
30
|
-
pilot_linkstec-0.0.
|
|
31
|
-
pilot_linkstec-0.0.
|
|
32
|
-
pilot_linkstec-0.0.
|
|
33
|
-
pilot_linkstec-0.0.
|
|
34
|
-
pilot_linkstec-0.0.
|
|
31
|
+
pilot_linkstec-0.0.26.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
32
|
+
pilot_linkstec-0.0.26.dist-info/METADATA,sha256=VFQ5kT7gvl2A7WrXJaw5iiBoQLrCohvC5Klq6mmcis4,679
|
|
33
|
+
pilot_linkstec-0.0.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
34
|
+
pilot_linkstec-0.0.26.dist-info/top_level.txt,sha256=BijnVJdXnIPxxx3s60M848seL4Z12gNUPod6KPJxK9c,6
|
|
35
|
+
pilot_linkstec-0.0.26.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|