pilot.linkstec 0.0.24__py3-none-any.whl → 0.0.25__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/generater/vertexai.py +8 -83
- {pilot_linkstec-0.0.24.dist-info → pilot_linkstec-0.0.25.dist-info}/METADATA +1 -1
- {pilot_linkstec-0.0.24.dist-info → pilot_linkstec-0.0.25.dist-info}/RECORD +6 -6
- {pilot_linkstec-0.0.24.dist-info → pilot_linkstec-0.0.25.dist-info}/WHEEL +0 -0
- {pilot_linkstec-0.0.24.dist-info → pilot_linkstec-0.0.25.dist-info}/licenses/LICENSE +0 -0
- {pilot_linkstec-0.0.24.dist-info → pilot_linkstec-0.0.25.dist-info}/top_level.txt +0 -0
pilot/generater/vertexai.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
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
|
|
@@ -12,13 +11,7 @@ class VertexAISingleton:
|
|
|
12
11
|
_tokenizer_cache = {}
|
|
13
12
|
encoding = None
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
"For SQL-related processing, analysis, and modifications:\n"
|
|
17
|
-
"1. When analyzing SQL statements such as \"SELECT COUNT(X) INTO :COLUMN FROM TABLE_NAME;\", please identify TABLE_NAME as a database table.\n"
|
|
18
|
-
"2. Extract and document all table names, column references, and SQL operations for comprehensive program analysis."
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
def __new__(cls, model_name: str = "gemini-2.5-pro", system_prompt: Optional[str] = None):
|
|
14
|
+
def __new__(cls, model_name: str = "gemini-2.5-pro"):
|
|
22
15
|
if cls._instance is None:
|
|
23
16
|
with cls._lock:
|
|
24
17
|
if cls._instance is None:
|
|
@@ -26,32 +19,18 @@ class VertexAISingleton:
|
|
|
26
19
|
cls._instance._initialized = False
|
|
27
20
|
return cls._instance
|
|
28
21
|
|
|
29
|
-
def __init__(self, model_name: str = "gemini-2.5-pro"
|
|
22
|
+
def __init__(self, model_name: str = "gemini-2.5-pro"):
|
|
30
23
|
if not self._initialized:
|
|
31
24
|
with self._lock:
|
|
32
25
|
if not self._initialized:
|
|
33
|
-
|
|
34
|
-
self.system_prompt = f"{system_prompt.rstrip()}\n\n{self.SQL_SYSTEM_PROMPT_EN}"
|
|
35
|
-
else:
|
|
36
|
-
self.system_prompt = self.SQL_SYSTEM_PROMPT_EN
|
|
37
|
-
self.model = GenerativeModel(model_name=model_name,system_instruction = self.system_prompt)
|
|
26
|
+
self.model = GenerativeModel(model_name)
|
|
38
27
|
self.encoding = tiktoken.get_encoding("cl100k_base")
|
|
39
|
-
# system_promptにSQL_SYSTEM_PROMPT_ENを追加
|
|
40
|
-
|
|
41
28
|
self._initialized = True
|
|
42
|
-
else:
|
|
43
|
-
# 既存インスタンスでもsystem_promptを更新可能に
|
|
44
|
-
if system_prompt is not None:
|
|
45
|
-
self.system_prompt = f"{system_prompt.rstrip()}\n\n{self.SQL_SYSTEM_PROMPT_EN}" if system_prompt else self.SQL_SYSTEM_PROMPT_EN
|
|
46
29
|
|
|
47
30
|
def generate_content(self, prompt: str) -> Dict[str, Any]:
|
|
48
31
|
"""複数スレッドから安全に呼び出し可能"""
|
|
49
32
|
try:
|
|
50
|
-
|
|
51
|
-
prompt = self.exchange_prompt(prompt)
|
|
52
|
-
response = self.model.generate_content(
|
|
53
|
-
contents=prompt # 引数名を明示
|
|
54
|
-
)
|
|
33
|
+
response = self.model.generate_content(prompt)
|
|
55
34
|
return {
|
|
56
35
|
"prompt": prompt,
|
|
57
36
|
"response": self._remove_code_fence(response.text),
|
|
@@ -87,61 +66,7 @@ class VertexAISingleton:
|
|
|
87
66
|
lines = lines[:-1]
|
|
88
67
|
return "\n".join(lines)
|
|
89
68
|
|
|
90
|
-
|
|
91
|
-
def exchange_prompt(self, prompt: str) -> str:
|
|
92
|
-
# EXEC SQL ... END-EXEC. のSQL部分を抽出してフラット化
|
|
93
|
-
rtn_prompt = self.fix_initialize(prompt)
|
|
94
|
-
rtn_prompt = self.extract_and_flatten_sql(rtn_prompt)
|
|
95
|
-
return rtn_prompt
|
|
96
|
-
|
|
97
|
-
def fix_initialize(self, text: str) -> str:
|
|
98
|
-
# SECTION ... EXIT. ブロック内のINITIALIZE文を処理
|
|
99
|
-
def process_section_block(match):
|
|
100
|
-
section_content = match.group(0)
|
|
101
|
-
|
|
102
|
-
# INITIALIZE の行を結合する(SECTION-EXIT間のみ)
|
|
103
|
-
# INITIALIZEで始まる行の次の行が空白+文字列の場合に結合
|
|
104
|
-
pattern_init = r'^(\s*INITIALIZE\s+[^\n]*)\n(\s+[^\n]+(?:\s+[^\n]+)*)'
|
|
105
|
-
|
|
106
|
-
def repl_init(m):
|
|
107
|
-
init_line = m.group(1).rstrip()
|
|
108
|
-
next_lines = m.group(2).strip()
|
|
109
|
-
return f'{init_line} {next_lines}'
|
|
110
|
-
|
|
111
|
-
section_content = re.sub(pattern_init, repl_init, section_content, flags=re.MULTILINE)
|
|
112
|
-
|
|
113
|
-
# ブロック内 COUNT(*) → COUNT(1) へ置換する
|
|
114
|
-
section_content = re.sub(r'COUNT\(\s*\*\s*\)', 'COUNT(1)', section_content, flags=re.IGNORECASE)
|
|
115
|
-
|
|
116
|
-
return section_content
|
|
117
|
-
|
|
118
|
-
# SECTION から EXIT. までのブロックを検索して処理
|
|
119
|
-
section_pattern = r'(\w+\s+SECTION\s*\..*?EXIT\s*\.)'
|
|
120
|
-
text = re.sub(section_pattern, process_section_block, text, flags=re.DOTALL | re.IGNORECASE)
|
|
121
|
-
|
|
122
|
-
return text
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
def extract_and_flatten_sql(self, code):
|
|
126
|
-
# EXEC SQL ... END-EXEC. にマッチ
|
|
127
|
-
pattern = r"EXEC SQL(.*?)END-EXEC\.?"
|
|
128
|
-
|
|
129
|
-
def repl(m):
|
|
130
|
-
# .*?でSQL部分取得
|
|
131
|
-
raw_sql = m.group(1)
|
|
132
|
-
# コメント(*以降)除去(複数行まとめてOK)
|
|
133
|
-
no_comment = re.sub(r"\*.*", "", raw_sql)
|
|
134
|
-
# 改行/連続スペースを単一スペースに
|
|
135
|
-
flattened = re.sub(r"\s+", " ", no_comment).strip()
|
|
136
|
-
# 置換内容
|
|
137
|
-
return f"EXEC SQL {flattened} END-EXEC."
|
|
138
|
-
|
|
139
|
-
# 全て置換
|
|
140
|
-
result = re.sub(pattern, repl, code, flags=re.DOTALL | re.IGNORECASE)
|
|
141
|
-
return result
|
|
142
|
-
|
|
143
|
-
|
|
144
69
|
@classmethod
|
|
145
|
-
def get_instance(cls, model_name: str = "gemini-2.5-pro"
|
|
70
|
+
def get_instance(cls, model_name: str = "gemini-2.5-pro") -> 'VertexAISingleton':
|
|
146
71
|
"""インスタンスを取得"""
|
|
147
|
-
return cls(model_name
|
|
72
|
+
return cls(model_name)
|
|
@@ -9,7 +9,7 @@ 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=v-hEvPwsUtrxP57yu9f5pUBj7BGImegO4lv10QWM1XA,2591
|
|
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
|
|
@@ -27,8 +27,8 @@ pilot/unit/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
27
27
|
pilot/unit/impl/base_unit.py,sha256=LsFPpL28aSNv5rsZhfKv6CWhAw1XR4n-A6FOn2RBrZo,1272
|
|
28
28
|
pilot/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
29
|
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.
|
|
30
|
+
pilot_linkstec-0.0.25.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
31
|
+
pilot_linkstec-0.0.25.dist-info/METADATA,sha256=KiE-t1APM2fIDKdeSRgx3EEHc1EbgvvEIe5n7AwSV-M,679
|
|
32
|
+
pilot_linkstec-0.0.25.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
33
|
+
pilot_linkstec-0.0.25.dist-info/top_level.txt,sha256=BijnVJdXnIPxxx3s60M848seL4Z12gNUPod6KPJxK9c,6
|
|
34
|
+
pilot_linkstec-0.0.25.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|