mimi800 commited on
Commit
1e77452
·
verified ·
1 Parent(s): 2b19671

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +3 -3
  2. model.py +3 -6
  3. model_config.py +3 -0
  4. prompt.py +4 -2
app.py CHANGED
@@ -8,13 +8,13 @@ def process_error(error_message: str) -> str:
8
  """
9
  Main function to process the error message and return JSON response.
10
  """
11
- # Build full prompt
12
- full_prompt = SYSTEM_PROMPT + error_message.strip()
13
 
14
  # Get raw model output
15
  raw_output = generate_response(full_prompt)
16
 
17
- # Extrahiere JSON aus der Antwort (falls Modell Prompt wiederholt)
18
  json_match = re.search(r"\{.*\}", raw_output, re.DOTALL)
19
  if json_match:
20
  raw_output = json_match.group(0)
 
8
  """
9
  Main function to process the error message and return JSON response.
10
  """
11
+ # Build full prompt with proper ending
12
+ full_prompt = SYSTEM_PROMPT + error_message.strip() + "\n<|end|>\n<|assistant|>"
13
 
14
  # Get raw model output
15
  raw_output = generate_response(full_prompt)
16
 
17
+ # Extrahiere JSON aus der Antwort
18
  json_match = re.search(r"\{.*\}", raw_output, re.DOTALL)
19
  if json_match:
20
  raw_output = json_match.group(0)
model.py CHANGED
@@ -2,15 +2,12 @@ import os
2
  from dotenv import load_dotenv
3
  from transformers import pipeline
4
  import torch
 
5
 
6
  # Load environment variables from .env file
7
  load_dotenv()
8
 
9
- # Initialize the model pipeline (adjust model name as needed)
10
- # Using a small, CPU-friendly model like StarCoder-1B
11
- MODEL_NAME = "bigcode/starcoderbase-1b"
12
-
13
- # Get HuggingFace token from environment variable
14
  HF_TOKEN = os.getenv("HF_TOKEN")
15
 
16
  # Initialize text generation pipeline
@@ -20,7 +17,7 @@ generator = pipeline(
20
  model=MODEL_NAME,
21
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
22
  device_map="auto", # Automatically choose device (CPU if no GPU)
23
- token=HF_TOKEN # Pass token for gated models
24
  )
25
 
26
  def generate_response(prompt: str) -> str:
 
2
  from dotenv import load_dotenv
3
  from transformers import pipeline
4
  import torch
5
+ from model_config import MODEL_NAME
6
 
7
  # Load environment variables from .env file
8
  load_dotenv()
9
 
10
+ # Get HuggingFace token from environment variable (for gated models only)
 
 
 
 
11
  HF_TOKEN = os.getenv("HF_TOKEN")
12
 
13
  # Initialize text generation pipeline
 
17
  model=MODEL_NAME,
18
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
19
  device_map="auto", # Automatically choose device (CPU if no GPU)
20
+ token=HF_TOKEN if "bigcode" in MODEL_NAME else None # Only for gated repos
21
  )
22
 
23
  def generate_response(prompt: str) -> str:
model_config.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Modell-Konfiguration für CPU-gestützte Inferenz
2
+
3
+ MODEL_NAME = "microsoft/Phi-3-mini-4k-instruct" # Öffentliches, schnelles Modell
prompt.py CHANGED
@@ -1,15 +1,17 @@
1
  # System prompt to instruct the model to always respond in structured JSON format
2
 
3
  SYSTEM_PROMPT = """
 
4
  You are a helpful assistant for developers debugging code.
5
  The user will provide a stack trace or error message.
6
  Your task is to provide a JSON object with exactly two keys:
7
  - "explanation": A concise, understandable explanation of the error (max 2 sentences)
8
  - "fix_suggestion": A clear, actionable fix in code or concept (max 3 sentences)
9
 
10
- Respond ONLY with valid JSON. No other text. No markdown. No explanations.
11
  Example:
12
  {"explanation": "Variable is undefined.", "fix_suggestion": "Check if defined."}
 
13
 
14
- Input:
15
  """
 
1
  # System prompt to instruct the model to always respond in structured JSON format
2
 
3
  SYSTEM_PROMPT = """
4
+ <|system|>
5
  You are a helpful assistant for developers debugging code.
6
  The user will provide a stack trace or error message.
7
  Your task is to provide a JSON object with exactly two keys:
8
  - "explanation": A concise, understandable explanation of the error (max 2 sentences)
9
  - "fix_suggestion": A clear, actionable fix in code or concept (max 3 sentences)
10
 
11
+ Respond ONLY with valid JSON. No other text. No markdown.
12
  Example:
13
  {"explanation": "Variable is undefined.", "fix_suggestion": "Check if defined."}
14
+ <|end|>
15
 
16
+ <|user|>
17
  """