Skip to content

Commit a6d8670

Browse files
MKY508claude
andcommitted
style: format Python files with ruff
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b480303 commit a6d8670

File tree

9 files changed

+25
-30
lines changed

9 files changed

+25
-30
lines changed

.backend.pid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
50516
1+
9703

.frontend.pid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
50541
1+
9726

apps/api/app/api/v1/schema.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,9 @@ def _detect_relationships(tables: list[TableInfo]) -> list[RelationshipSuggestio
9595

9696
if matched_table and matched_table != table.name:
9797
# 检查目标表是否有 id 列
98-
target_table_info = next(
99-
(t for t in tables if t.name == matched_table), None
100-
)
98+
target_table_info = next((t for t in tables if t.name == matched_table), None)
10199
if target_table_info:
102-
has_id = any(
103-
c.name.lower() == "id" for c in target_table_info.columns
104-
)
100+
has_id = any(c.name.lower() == "id" for c in target_table_info.columns)
105101
if has_id:
106102
suggestions.append(
107103
RelationshipSuggestion(
@@ -137,9 +133,7 @@ async def get_schema(
137133
# 自动检测关系
138134
suggestions = _detect_relationships(tables)
139135

140-
return APIResponse.ok(
141-
data=SchemaInfo(tables=tables, suggestions=suggestions)
142-
)
136+
return APIResponse.ok(data=SchemaInfo(tables=tables, suggestions=suggestions))
143137
except Exception as e:
144138
raise HTTPException(
145139
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
@@ -210,9 +204,7 @@ async def get_relationships(
210204
)
211205
relationships = result.scalars().all()
212206

213-
return APIResponse.ok(
214-
data=[TableRelationshipResponse.model_validate(r) for r in relationships]
215-
)
207+
return APIResponse.ok(data=[TableRelationshipResponse.model_validate(r) for r in relationships])
216208

217209

218210
@router.post(

apps/api/app/db/tables.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,8 @@ class TableRelationship(Base, UUIDMixin, TimestampMixin):
187187
source_column: Mapped[str] = mapped_column(String(100), nullable=False)
188188
target_table: Mapped[str] = mapped_column(String(100), nullable=False)
189189
target_column: Mapped[str] = mapped_column(String(100), nullable=False)
190-
relationship_type: Mapped[str] = mapped_column(
191-
String(10), default="1:N"
192-
) # 1:1, 1:N, N:1, N:M
193-
join_type: Mapped[str] = mapped_column(
194-
String(20), default="LEFT"
195-
) # LEFT, INNER, RIGHT, FULL
190+
relationship_type: Mapped[str] = mapped_column(String(10), default="1:N") # 1:1, 1:N, N:1, N:M
191+
join_type: Mapped[str] = mapped_column(String(20), default="LEFT") # LEFT, INNER, RIGHT, FULL
196192
description: Mapped[str | None] = mapped_column(Text)
197193
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
198194

apps/api/app/models/schema.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ def to_prompt(self, language: str = "zh") -> str:
109109
return ""
110110

111111
if language == "zh":
112-
lines = ["## 表关系定义", "以下是预定义的表关系,生成多表查询时请使用这些 JOIN 条件:", ""]
112+
lines = [
113+
"## 表关系定义",
114+
"以下是预定义的表关系,生成多表查询时请使用这些 JOIN 条件:",
115+
"",
116+
]
113117
else:
114118
lines = [
115119
"## Table Relationships",

apps/api/app/models/semantic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def to_prompt(self, language: str = "zh") -> str:
7777
lines.append(f" {term.description}")
7878
if term.examples:
7979
examples_str = ", ".join(f'"{e}"' for e in term.examples[:3])
80-
lines.append(f" 示例: {examples_str}" if language == "zh" else f" Examples: {examples_str}")
80+
lines.append(
81+
f" 示例: {examples_str}" if language == "zh" else f" Examples: {examples_str}"
82+
)
8183

8284
return "\n".join(lines)

apps/api/app/services/execution.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ async def _get_semantic_context(self) -> SemanticContext:
145145
# 如果有指定连接,获取全局术语和该连接的术语
146146
if self.connection_id:
147147
query = query.where(
148-
(SemanticTerm.connection_id.is_(None)) | (SemanticTerm.connection_id == self.connection_id)
148+
(SemanticTerm.connection_id.is_(None))
149+
| (SemanticTerm.connection_id == self.connection_id)
149150
)
150151
else:
151152
# 只获取全局术语
@@ -154,9 +155,7 @@ async def _get_semantic_context(self) -> SemanticContext:
154155
result = await self.db.execute(query.order_by(SemanticTerm.term))
155156
terms = result.scalars().all()
156157

157-
return SemanticContext(
158-
terms=[SemanticTermResponse.model_validate(t) for t in terms]
159-
)
158+
return SemanticContext(terms=[SemanticTermResponse.model_validate(t) for t in terms])
160159

161160
async def _get_relationship_context(self, max_relationships: int = 15) -> RelationshipContext:
162161
"""获取表关系上下文
@@ -245,7 +244,9 @@ async def execute_stream(
245244
logger.info("Getting conversation history...")
246245
history = await self._get_conversation_history(conversation_id, limit=10)
247246

248-
system_prompt = self._build_system_prompt(db_config, semantic_context, relationship_context)
247+
system_prompt = self._build_system_prompt(
248+
db_config, semantic_context, relationship_context
249+
)
249250

250251
engine = GptmeEngine(
251252
model=model_config.get("model"),

apps/api/app/services/gptme_engine.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ async def _execute_sql(
200200
result = db_manager.execute_query(sql, read_only=True)
201201
return result.data, result.rows_count
202202

203-
def _build_chart_from_config(
204-
self, config: dict, data: list[dict]
205-
) -> dict | None:
203+
def _build_chart_from_config(self, config: dict, data: list[dict]) -> dict | None:
206204
"""根据 AI 提供的配置构建图表数据
207205
208206
Args:

apps/web/src/components/settings/SchemaSettings.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export function SchemaSettings({ connectionId }: SchemaSettingsProps) {
9696

9797
// 构建节点和边
9898
useEffect(() => {
99+
console.log("schemaInfo:", schemaInfo);
100+
console.log("tables:", schemaInfo?.tables);
99101
if (!schemaInfo?.tables) return;
100102

101103
// 创建表节点

0 commit comments

Comments
 (0)