-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
443 lines (341 loc) · 13.9 KB
/
models.py
File metadata and controls
443 lines (341 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
from datetime import datetime
import enum
import uuid
from typing import Any, List, Optional
from pydantic import BaseModel, Field
from sqlalchemy import (
Boolean,
DateTime,
Enum,
Float,
Index,
Integer,
JSON,
String,
Text,
UniqueConstraint,
)
from sqlalchemy.orm import Mapped, mapped_column
from database import Base
class RadarMetric(BaseModel):
name: str
value: int = Field(..., ge=0, le=100)
max: int = Field(default=100, ge=1)
class EvidenceSource(BaseModel):
source_id: str
snippet: str
class EvaluationItem(BaseModel):
text: str
source_ids: List[str] = Field(default_factory=list)
class EvaluationResult(BaseModel):
summary: str
summary_source_ids: List[str] = Field(default_factory=list)
title: str
decision: str
match_score: int = Field(..., ge=0, le=100)
radar_metrics: List[RadarMetric] = Field(default_factory=list)
highlights: List[EvaluationItem] = Field(default_factory=list)
risks: List[EvaluationItem] = Field(default_factory=list)
sources: List[EvidenceSource] = Field(default_factory=list)
class EvaluationScoreResult(BaseModel):
title: str
decision: str
match_score: int = Field(..., ge=0, le=100)
class EvaluationSummaryResult(BaseModel):
summary: str
summary_source_ids: List[str] = Field(default_factory=list)
class EvaluationItemsResult(BaseModel):
items: List[EvaluationItem] = Field(default_factory=list)
class ResumeStatus(enum.Enum):
PENDING = "pending"
PARSING = "parsing"
EVALUATING = "evaluating"
COMPLETED = "completed"
FAILED = "failed"
class Resume(Base):
__tablename__ = "resumes"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
user_id: Mapped[str] = mapped_column(String(50), nullable=False)
candidate_name: Mapped[Optional[str]] = mapped_column(String(100), index=True)
phone: Mapped[str] = mapped_column(String(20), nullable=False)
status: Mapped[ResumeStatus] = mapped_column(
Enum(ResumeStatus), default=ResumeStatus.PENDING, nullable=False
)
content: Mapped[Optional[str]] = mapped_column(Text)
evaluation_result: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now, nullable=False)
updated_at: Mapped[datetime] = mapped_column(
DateTime, default=datetime.now, onupdate=datetime.now, nullable=False
)
__table_args__ = (
UniqueConstraint("user_id", "phone", name="_user_phone_uc"),
Index("ix_user_phone", "user_id", "phone"),
)
class ChatMessage(Base):
__tablename__ = "chat_messages"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
user_id: Mapped[str] = mapped_column(String(50), index=True, nullable=False)
role: Mapped[str] = mapped_column(String(50), nullable=False)
content: Mapped[str] = mapped_column(Text, nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now, nullable=False)
class InterviewSession(Base):
__tablename__ = "interview_sessions"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
session_id: Mapped[str] = mapped_column(String(36), default=lambda: str(uuid.uuid4()), unique=True, index=True)
user_id: Mapped[str] = mapped_column(String(50), index=True, nullable=False)
resume_id: Mapped[int] = mapped_column(Integer, index=True, nullable=False)
candidate_name: Mapped[Optional[str]] = mapped_column(String(100), index=True)
interview_identity: Mapped[str] = mapped_column(String(100), index=True, nullable=False)
status: Mapped[str] = mapped_column(String(20), default="draft", nullable=False)
questions: Mapped[list[dict[str, Any]]] = mapped_column(JSON, default=list, nullable=False)
answers: Mapped[list[dict[str, Any]]] = mapped_column(JSON, default=list, nullable=False)
result: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now, nullable=False)
updated_at: Mapped[datetime] = mapped_column(
DateTime, default=datetime.now, onupdate=datetime.now, nullable=False
)
class PromptVersion(Base):
__tablename__ = "prompt_versions"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
prompt_name: Mapped[str] = mapped_column(String(80), index=True, nullable=False)
version_label: Mapped[str] = mapped_column(String(80), nullable=False)
system_instruction: Mapped[str] = mapped_column(Text, nullable=False)
user_template: Mapped[str] = mapped_column(Text, nullable=False)
config_json: Mapped[dict[str, Any]] = mapped_column(JSON, default=dict, nullable=False)
note: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now, nullable=False)
__table_args__ = (
Index("ix_prompt_versions_name_created", "prompt_name", "created_at"),
)
class ModelCallLog(Base):
__tablename__ = "model_call_logs"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
request_id: Mapped[str] = mapped_column(String(36), index=True, nullable=False)
source: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
feature: Mapped[str] = mapped_column(String(80), index=True, nullable=False)
stage: Mapped[str] = mapped_column(String(80), index=True, nullable=False)
model_name: Mapped[str] = mapped_column(String(120), index=True, nullable=False)
prompt_name: Mapped[str] = mapped_column(String(80), index=True, nullable=False)
prompt_version_id: Mapped[Optional[int]] = mapped_column(Integer, index=True, nullable=True)
input_summary: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
output_summary: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
input_tokens: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
output_tokens: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
total_tokens: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
latency_ms: Mapped[int] = mapped_column(Integer, nullable=False)
estimated_cost: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
success: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
fallback_used: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
extra_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now, nullable=False)
__table_args__ = (
Index("ix_model_call_logs_created", "created_at"),
Index("ix_model_call_logs_source_created", "source", "created_at"),
Index("ix_model_call_logs_feature_created", "feature", "created_at"),
Index("ix_model_call_logs_prompt_created", "prompt_name", "created_at"),
)
class QueryRequest(BaseModel):
user_id: str
text: str
candidate_name: Optional[str] = None
resume_id: Optional[int] = None
class EvaluationRequest(BaseModel):
user_id: str
jd_text: str
resume_id: Optional[int] = None
candidate_name: Optional[str] = None
phone: Optional[str] = None
jd_keywords: Optional[List[str]] = None
class JDAnalysisRequest(BaseModel):
jd_text: str
class JDAnalysisResponse(BaseModel):
keywords: List[str] = Field(default_factory=list)
class JDKeywordExtractionResult(BaseModel):
keywords: List[str] = Field(default_factory=list, description="仅包含来自JD原文的关键词")
class ChatRequest(BaseModel):
user_id: str
text: str
role: str = "user"
candidate_name: Optional[str] = None
resume_id: Optional[int] = None
class OCRResponse(BaseModel):
text: str
class ChatSuggestionsResponse(BaseModel):
suggestions: List[str] = Field(default_factory=list)
class InterviewQuestion(BaseModel):
question_id: str
category: str
question: str
intent: str
source_ids: List[str] = Field(default_factory=list)
class InterviewQuestionsResponse(BaseModel):
questions: List[InterviewQuestion] = Field(default_factory=list)
class InterviewQuestionResult(BaseModel):
question_id: str
score: int = Field(..., ge=0, le=100)
feedback: str
strengths: List[str] = Field(default_factory=list)
improvements: List[str] = Field(default_factory=list)
class InterviewEvaluationLLMResult(BaseModel):
overall_feedback: str
strengths: List[str] = Field(default_factory=list)
risks: List[str] = Field(default_factory=list)
question_results: List[InterviewQuestionResult] = Field(default_factory=list)
class InterviewAnswerInput(BaseModel):
question_id: str
question: str
category: str
answer: str
class InterviewStartRequest(BaseModel):
user_id: str
jd_text: str
interview_identity: str
resume_id: Optional[int] = None
candidate_name: Optional[str] = None
phone: Optional[str] = None
jd_keywords: Optional[List[str]] = None
class InterviewSubmitRequest(BaseModel):
user_id: str
jd_text: str
interview_identity: str
session_id: Optional[str] = None
answers: List[InterviewAnswerInput] = Field(default_factory=list)
resume_id: Optional[int] = None
candidate_name: Optional[str] = None
phone: Optional[str] = None
jd_keywords: Optional[List[str]] = None
class InterviewSubmitResult(BaseModel):
total_score: int = Field(..., ge=0, le=100)
verdict: str
overall_feedback: str
strengths: List[str] = Field(default_factory=list)
risks: List[str] = Field(default_factory=list)
question_results: List[InterviewQuestionResult] = Field(default_factory=list)
class InterviewHistoryRequest(BaseModel):
user_id: str
interview_identity: str
resume_id: Optional[int] = None
class InterviewHistoryItem(BaseModel):
session_id: str
interview_identity: str
candidate_name: str
verdict: str
total_score: int = Field(..., ge=0, le=100)
created_at: str
class InterviewHistoryResponse(BaseModel):
items: List[InterviewHistoryItem] = Field(default_factory=list)
class InterviewSessionDetailResponse(BaseModel):
session_id: str
interview_identity: str
candidate_name: str
status: str
questions: List[dict[str, Any]] = Field(default_factory=list)
answers: List[dict[str, Any]] = Field(default_factory=list)
result: dict[str, Any] = Field(default_factory=dict)
created_at: str
updated_at: str
class PromptConfig(BaseModel):
model_name: str
temperature: float = Field(default=0, ge=0, le=2)
top_p: Optional[float] = Field(default=None, ge=0, le=1)
max_tokens: Optional[int] = Field(default=None, ge=1)
class PromptVersionCreateRequest(BaseModel):
prompt_name: str
version_label: str
system_instruction: str
user_template: str
config: PromptConfig
note: Optional[str] = None
class PromptVersionResponse(BaseModel):
id: int
prompt_name: str
version_label: str
system_instruction: str
user_template: str
config: PromptConfig
note: Optional[str] = None
created_at: str
class PromptScenarioField(BaseModel):
name: str
label: str
description: str
multiline: bool = False
class PromptScenarioResponse(BaseModel):
prompt_name: str
label: str
description: str
output_mode: str
output_schema_name: Optional[str] = None
default_system_instruction: str
default_user_template: str
default_config: PromptConfig
fields: List[PromptScenarioField] = Field(default_factory=list)
class PromptPlaygroundRunRequest(BaseModel):
prompt_name: str
prompt_version_id: Optional[int] = None
system_instruction_override: Optional[str] = None
user_template_override: Optional[str] = None
variables: dict[str, Any] = Field(default_factory=dict)
model_name: Optional[str] = None
temperature: Optional[float] = Field(default=None, ge=0, le=2)
top_p: Optional[float] = Field(default=None, ge=0, le=1)
max_tokens: Optional[int] = Field(default=None, ge=1)
save_log: bool = True
class UsageMetricsResponse(BaseModel):
input_tokens: Optional[int] = None
output_tokens: Optional[int] = None
total_tokens: Optional[int] = None
class PromptPlaygroundRunResponse(BaseModel):
request_id: str
log_id: Optional[int] = None
resolved_prompt: dict[str, str]
parsed_output: Any = None
raw_output_preview: str = ""
usage: UsageMetricsResponse = Field(default_factory=UsageMetricsResponse)
latency_ms: int
estimated_cost: Optional[float] = None
success: bool
error_message: Optional[str] = None
class ObservabilitySummaryResponse(BaseModel):
total_calls: int = 0
success_rate: float = 0
fallback_rate: float = 0
avg_latency_ms: float = 0
total_input_tokens: int = 0
total_output_tokens: int = 0
total_tokens: int = 0
total_estimated_cost: float = 0
class ObservabilityLogItemResponse(BaseModel):
id: int
request_id: str
source: str
feature: str
stage: str
model_name: str
prompt_name: str
prompt_version_id: Optional[int] = None
input_summary: str = ""
output_summary: str = ""
input_tokens: Optional[int] = None
output_tokens: Optional[int] = None
total_tokens: Optional[int] = None
latency_ms: int
estimated_cost: Optional[float] = None
success: bool
fallback_used: bool
error_message: Optional[str] = None
created_at: str
class ObservabilityLogsResponse(BaseModel):
items: List[ObservabilityLogItemResponse] = Field(default_factory=list)
total: int = 0
page: int = 1
page_size: int = 20
class ObservabilityTrendPoint(BaseModel):
bucket: str
latency_ms_avg: float = 0
total_tokens: int = 0
total_estimated_cost: float = 0
total_calls: int = 0
class ObservabilityTrendsResponse(BaseModel):
points: List[ObservabilityTrendPoint] = Field(default_factory=list)