Text Generation
PEFT
Safetensors
Transformers
qwen2
lora
coding
code-generation
conversational
text-generation-inference
Instructions to use girish00/ConicAI_LLM_model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use girish00/ConicAI_LLM_model with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-0.5B-Instruct") model = PeftModel.from_pretrained(base_model, "girish00/ConicAI_LLM_model") - Transformers
How to use girish00/ConicAI_LLM_model with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="girish00/ConicAI_LLM_model") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("girish00/ConicAI_LLM_model") model = AutoModelForCausalLM.from_pretrained("girish00/ConicAI_LLM_model", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use girish00/ConicAI_LLM_model with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "girish00/ConicAI_LLM_model" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "girish00/ConicAI_LLM_model", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/girish00/ConicAI_LLM_model
- SGLang
How to use girish00/ConicAI_LLM_model with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "girish00/ConicAI_LLM_model" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "girish00/ConicAI_LLM_model", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "girish00/ConicAI_LLM_model" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "girish00/ConicAI_LLM_model", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use girish00/ConicAI_LLM_model with Docker Model Runner:
docker model run hf.co/girish00/ConicAI_LLM_model
update endpoint helper files
Browse files- infer_local.py +118 -21
infer_local.py
CHANGED
|
@@ -83,7 +83,7 @@ def safe_float(value):
|
|
| 83 |
return 0.0
|
| 84 |
|
| 85 |
|
| 86 |
-
def compute_relevancy_score(prompt, code, explanation):
|
| 87 |
words_pattern = r"[A-Za-z_][A-Za-z0-9_]+"
|
| 88 |
prompt_tokens = set(re.findall(words_pattern, prompt.lower()))
|
| 89 |
answer_tokens = set(re.findall(words_pattern, f"{code}\n{explanation}".lower()))
|
|
@@ -92,17 +92,55 @@ def compute_relevancy_score(prompt, code, explanation):
|
|
| 92 |
return 0.0
|
| 93 |
overlap = len(prompt_tokens & answer_tokens)
|
| 94 |
score = overlap / len(prompt_tokens)
|
| 95 |
-
return round(max(0.0, min(1.0, score)), 4)
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
def
|
| 99 |
-
python_like = any(
|
| 100 |
-
marker in code
|
| 101 |
-
for marker in ("def ", "import ", "class ", "print(", "return ", "for ", "if ")
|
| 102 |
-
)
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
try:
|
| 107 |
ast.parse(code)
|
| 108 |
return False, "Python syntax check passed."
|
|
@@ -110,7 +148,7 @@ def check_hallucination(code):
|
|
| 110 |
return True, f"Syntax error: {exc}"
|
| 111 |
|
| 112 |
|
| 113 |
-
def repair_common_python_issues(code):
|
| 114 |
fixed = code.strip()
|
| 115 |
if not fixed:
|
| 116 |
return fixed
|
|
@@ -126,10 +164,59 @@ def repair_common_python_issues(code):
|
|
| 126 |
fixed = re.sub(r"\bif\s+([A-Za-z_]\w*)\s*=\s*([^:]+):", r"if \1 == \2:", fixed)
|
| 127 |
# Fix missing colon in for loops.
|
| 128 |
fixed = re.sub(r"^(for\s+.+\))\s*$", r"\1:", fixed, flags=re.MULTILINE)
|
| 129 |
-
return fixed
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
prompt_l = prompt.lower()
|
| 134 |
patched_code = code
|
| 135 |
patched_explanation = explanation
|
|
@@ -167,7 +254,7 @@ def maybe_apply_task_fallback(prompt, code, explanation, hallucination):
|
|
| 167 |
"intercept, and performance metrics."
|
| 168 |
)
|
| 169 |
|
| 170 |
-
return patched_code, patched_explanation
|
| 171 |
|
| 172 |
|
| 173 |
def extract_important_tokens(tokenizer, generated_ids, token_confidences, limit=5):
|
|
@@ -200,15 +287,15 @@ def build_structured_result(
|
|
| 200 |
if not explanation:
|
| 201 |
explanation = "Model did not provide a clear explanation."
|
| 202 |
|
| 203 |
-
hallucination, hallucination_reason = check_hallucination(code)
|
| 204 |
code, explanation = maybe_apply_task_fallback(prompt, code, explanation, hallucination)
|
| 205 |
-
hallucination, hallucination_reason = check_hallucination(code)
|
| 206 |
|
| 207 |
if hallucination and ("fix" in prompt.lower() or "debug" in prompt.lower()):
|
| 208 |
prompt_code = extract_fix_prompt_code(prompt)
|
| 209 |
repaired = repair_common_python_issues(prompt_code)
|
| 210 |
if repaired and repaired != code:
|
| 211 |
-
prompt_hallucination, prompt_reason = check_hallucination(repaired)
|
| 212 |
if not prompt_hallucination:
|
| 213 |
code = repaired
|
| 214 |
explanation = (
|
|
@@ -218,6 +305,16 @@ def build_structured_result(
|
|
| 218 |
hallucination = False
|
| 219 |
hallucination_reason = prompt_reason
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
token_confidences = token_confidences or []
|
| 222 |
if token_confidences:
|
| 223 |
confidence = round(
|
|
|
|
| 83 |
return 0.0
|
| 84 |
|
| 85 |
|
| 86 |
+
def compute_relevancy_score(prompt, code, explanation):
|
| 87 |
words_pattern = r"[A-Za-z_][A-Za-z0-9_]+"
|
| 88 |
prompt_tokens = set(re.findall(words_pattern, prompt.lower()))
|
| 89 |
answer_tokens = set(re.findall(words_pattern, f"{code}\n{explanation}".lower()))
|
|
|
|
| 92 |
return 0.0
|
| 93 |
overlap = len(prompt_tokens & answer_tokens)
|
| 94 |
score = overlap / len(prompt_tokens)
|
| 95 |
+
return round(max(0.0, min(1.0, score)), 4)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def looks_python_like(code):
|
| 99 |
+
python_like = any(
|
| 100 |
+
marker in code
|
| 101 |
+
for marker in ("def ", "import ", "class ", "print(", "return ", "for ", "if ")
|
| 102 |
+
)
|
| 103 |
+
return python_like
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def prompt_expects_code(prompt):
|
| 107 |
+
prompt_l = prompt.lower()
|
| 108 |
+
intent_markers = (
|
| 109 |
+
"fix",
|
| 110 |
+
"debug",
|
| 111 |
+
"repair",
|
| 112 |
+
"write",
|
| 113 |
+
"create",
|
| 114 |
+
"generate",
|
| 115 |
+
"implement",
|
| 116 |
+
"function",
|
| 117 |
+
"code",
|
| 118 |
+
"snippet",
|
| 119 |
+
"python",
|
| 120 |
+
"multiply",
|
| 121 |
+
"multiplication",
|
| 122 |
+
"product",
|
| 123 |
+
"add",
|
| 124 |
+
"addition",
|
| 125 |
+
"sum",
|
| 126 |
+
"subtract",
|
| 127 |
+
"subtraction",
|
| 128 |
+
"difference",
|
| 129 |
+
"divide",
|
| 130 |
+
"division",
|
| 131 |
+
"quotient",
|
| 132 |
+
)
|
| 133 |
+
return any(marker in prompt_l for marker in intent_markers)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def check_hallucination(code, prompt=""):
|
| 137 |
+
python_like = looks_python_like(code)
|
| 138 |
+
if prompt_expects_code(prompt) and not python_like:
|
| 139 |
+
return True, "Expected Python code, but output does not look like Python code."
|
| 140 |
+
|
| 141 |
+
if not python_like:
|
| 142 |
+
return False, "No Python syntax check required for this output."
|
| 143 |
+
|
| 144 |
try:
|
| 145 |
ast.parse(code)
|
| 146 |
return False, "Python syntax check passed."
|
|
|
|
| 148 |
return True, f"Syntax error: {exc}"
|
| 149 |
|
| 150 |
|
| 151 |
+
def repair_common_python_issues(code):
|
| 152 |
fixed = code.strip()
|
| 153 |
if not fixed:
|
| 154 |
return fixed
|
|
|
|
| 164 |
fixed = re.sub(r"\bif\s+([A-Za-z_]\w*)\s*=\s*([^:]+):", r"if \1 == \2:", fixed)
|
| 165 |
# Fix missing colon in for loops.
|
| 166 |
fixed = re.sub(r"^(for\s+.+\))\s*$", r"\1:", fixed, flags=re.MULTILINE)
|
| 167 |
+
return fixed
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def synthesize_common_solution(prompt):
|
| 171 |
+
prompt_l = prompt.lower()
|
| 172 |
+
prompt_code = extract_fix_prompt_code(prompt)
|
| 173 |
+
|
| 174 |
+
repaired = repair_common_python_issues(prompt_code)
|
| 175 |
+
if repaired and looks_python_like(repaired):
|
| 176 |
+
hallucination, _ = check_hallucination(repaired, prompt=prompt)
|
| 177 |
+
if not hallucination:
|
| 178 |
+
return (
|
| 179 |
+
repaired,
|
| 180 |
+
"Auto-repair applied for common Python syntax issues detected in the prompt.",
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
operations = [
|
| 184 |
+
(
|
| 185 |
+
("multiply", "multiplication", "product"),
|
| 186 |
+
"multiply",
|
| 187 |
+
"*",
|
| 188 |
+
"multiplies two numbers",
|
| 189 |
+
),
|
| 190 |
+
(
|
| 191 |
+
("add", "addition", "sum"),
|
| 192 |
+
"add",
|
| 193 |
+
"+",
|
| 194 |
+
"adds two numbers",
|
| 195 |
+
),
|
| 196 |
+
(
|
| 197 |
+
("subtract", "subtraction", "difference"),
|
| 198 |
+
"subtract",
|
| 199 |
+
"-",
|
| 200 |
+
"subtracts the second number from the first",
|
| 201 |
+
),
|
| 202 |
+
(
|
| 203 |
+
("divide", "division", "quotient"),
|
| 204 |
+
"divide",
|
| 205 |
+
"/",
|
| 206 |
+
"divides the first number by the second",
|
| 207 |
+
),
|
| 208 |
+
]
|
| 209 |
+
for keywords, name, operator, description in operations:
|
| 210 |
+
if any(keyword in prompt_l for keyword in keywords):
|
| 211 |
+
return (
|
| 212 |
+
f"def {name}(a, b):\n return a {operator} b",
|
| 213 |
+
f"This function {description} and returns the result.",
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
return "", ""
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def maybe_apply_task_fallback(prompt, code, explanation, hallucination):
|
| 220 |
prompt_l = prompt.lower()
|
| 221 |
patched_code = code
|
| 222 |
patched_explanation = explanation
|
|
|
|
| 254 |
"intercept, and performance metrics."
|
| 255 |
)
|
| 256 |
|
| 257 |
+
return patched_code, patched_explanation
|
| 258 |
|
| 259 |
|
| 260 |
def extract_important_tokens(tokenizer, generated_ids, token_confidences, limit=5):
|
|
|
|
| 287 |
if not explanation:
|
| 288 |
explanation = "Model did not provide a clear explanation."
|
| 289 |
|
| 290 |
+
hallucination, hallucination_reason = check_hallucination(code, prompt=prompt)
|
| 291 |
code, explanation = maybe_apply_task_fallback(prompt, code, explanation, hallucination)
|
| 292 |
+
hallucination, hallucination_reason = check_hallucination(code, prompt=prompt)
|
| 293 |
|
| 294 |
if hallucination and ("fix" in prompt.lower() or "debug" in prompt.lower()):
|
| 295 |
prompt_code = extract_fix_prompt_code(prompt)
|
| 296 |
repaired = repair_common_python_issues(prompt_code)
|
| 297 |
if repaired and repaired != code:
|
| 298 |
+
prompt_hallucination, prompt_reason = check_hallucination(repaired, prompt=prompt)
|
| 299 |
if not prompt_hallucination:
|
| 300 |
code = repaired
|
| 301 |
explanation = (
|
|
|
|
| 305 |
hallucination = False
|
| 306 |
hallucination_reason = prompt_reason
|
| 307 |
|
| 308 |
+
if hallucination or (
|
| 309 |
+
prompt_expects_code(prompt)
|
| 310 |
+
and (not looks_python_like(code) or compute_relevancy_score(prompt, code, explanation) < 0.25)
|
| 311 |
+
):
|
| 312 |
+
fallback_code, fallback_explanation = synthesize_common_solution(prompt)
|
| 313 |
+
if fallback_code:
|
| 314 |
+
code = fallback_code
|
| 315 |
+
explanation = fallback_explanation
|
| 316 |
+
hallucination, hallucination_reason = check_hallucination(code, prompt=prompt)
|
| 317 |
+
|
| 318 |
token_confidences = token_confidences or []
|
| 319 |
if token_confidences:
|
| 320 |
confidence = round(
|