131 lines
No EOL
4 KiB
Python
131 lines
No EOL
4 KiB
Python
"""Mock mode for the LLM gateway.
|
|
|
|
When no API key is configured, the gateway returns deterministic canned
|
|
outputs per task name. This allows the API and tests to run offline.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import time
|
|
import uuid
|
|
|
|
# Deterministic canned outputs per task name.
|
|
# Each entry is a dict that will be returned as the task result.
|
|
MOCK_OUTPUTS: dict[str, dict] = {
|
|
"score": {
|
|
"score": 75,
|
|
"rationale": {
|
|
"match": "good",
|
|
"reasons": ["skills align", "location matches"],
|
|
},
|
|
},
|
|
"extract": {
|
|
"company": "Example Corp",
|
|
"title": "Software Engineer",
|
|
"location": "Stockholm",
|
|
"requirements": ["Python", "PostgreSQL", "Docker"],
|
|
},
|
|
"cv_assist": {
|
|
"suggestions": [
|
|
"Led a team of 5 developers to deliver a critical integration",
|
|
"Reduced API latency by 40% through caching and query optimization",
|
|
],
|
|
},
|
|
"cl_critique": {
|
|
"comments": [
|
|
{
|
|
"quote": "I am a hard worker",
|
|
"suggestion": "Replace generic claim with a specific achievement metric",
|
|
"severity": "medium",
|
|
},
|
|
{
|
|
"quote": "Dear Sir/Madam",
|
|
"suggestion": "Address the hiring manager by name if known",
|
|
"severity": "low",
|
|
},
|
|
],
|
|
},
|
|
"critique": {
|
|
"comments": [
|
|
{
|
|
"quote": "sample text",
|
|
"suggestion": "improve clarity",
|
|
"severity": "low",
|
|
},
|
|
],
|
|
},
|
|
"research": {
|
|
"summary": "The company is a mid-size tech firm focused on cloud infrastructure.",
|
|
"key_points": ["Founded in 2015", "Series B funding", "Remote-first culture"],
|
|
},
|
|
"email_classify": {
|
|
"classification": "interview_invite",
|
|
"state_proposal": "interviewing",
|
|
"reason": "The email contains an invitation to schedule an interview.",
|
|
},
|
|
"cv_tailor": {
|
|
"tailored_cv": {
|
|
"summary": "Senior Python Developer with 6+ years building scalable backend systems.",
|
|
"skills": [
|
|
"Python",
|
|
"Fast API",
|
|
"PostgreSQL",
|
|
"Docker",
|
|
"Kubernetes",
|
|
"AWS",
|
|
],
|
|
"experience": [
|
|
{
|
|
"company": "TechCorp",
|
|
"role": "Senior Backend Engineer",
|
|
"bullets": [
|
|
"Led migration of monolith to microservices using Fast API",
|
|
"Reduced API latency by 40% through query optimization and caching",
|
|
],
|
|
},
|
|
],
|
|
},
|
|
"change_log": [
|
|
{"action": "reordered", "detail": "Moved Python and Fast API to top of skills"},
|
|
{"action": "rephrased", "detail": "Rewrote first experience bullet to emphasize Fast API"},
|
|
],
|
|
},
|
|
"deadline_extract": {
|
|
"apply_by": None,
|
|
},
|
|
}
|
|
|
|
# Default mock output for unknown task names.
|
|
DEFAULT_MOCK_OUTPUT: dict = {
|
|
"result": "mock output",
|
|
"task": "unknown",
|
|
}
|
|
|
|
|
|
def get_mock_output(task: str) -> dict:
|
|
"""Return a deterministic mock output for *task*.
|
|
|
|
For unknown tasks, returns DEFAULT_MOCK_OUTPUT with the task name filled in.
|
|
"""
|
|
if task in MOCK_OUTPUTS:
|
|
# Return a copy so callers cannot mutate the canned data.
|
|
return json.loads(json.dumps(MOCK_OUTPUTS[task]))
|
|
result = json.loads(json.dumps(DEFAULT_MOCK_OUTPUT))
|
|
result["task"] = task
|
|
return result
|
|
|
|
|
|
def mock_telemetry_row(task: str, model: str) -> dict:
|
|
"""Build a mock telemetry row dict for offline mode."""
|
|
return {
|
|
"id": str(uuid.uuid4()),
|
|
"task": task,
|
|
"model": model,
|
|
"provider": "mock",
|
|
"input_tokens": 0,
|
|
"output_tokens": 0,
|
|
"cost_usd": 0.0,
|
|
"duration_ms": 0,
|
|
"mock": True,
|
|
} |