girish00 commited on
Commit
36ff300
·
verified ·
1 Parent(s): 4c195e0

add structured endpoint handler

Browse files
Files changed (1) hide show
  1. README.md +32 -0
README.md CHANGED
@@ -12,6 +12,7 @@ This project fine-tunes `Qwen/Qwen2.5-Coder-0.5B-Instruct` using LoRA for:
12
  - `finetune_coding_llm_colab.py`: local training script (LoRA) + optional upload
13
  - `infer_local.py`: test local trained model with structured JSON output
14
  - `infer_cloud.py`: run Hugging Face API inference and force the same structured JSON output
 
15
  - `evaluate_model.py`: run multi-prompt quality checks and report accuracy
16
  - `upload_to_hf.py`: upload local model folder to HF
17
  - `run_pipeline.py`: one command for generate + train (+ optional upload)
@@ -171,6 +172,37 @@ python infer_cloud.py --prompt "Fix this code: def add(a,b) return a+b" --no-loc
171
  `infer_cloud.py` applies the same JSON parsing, Python syntax check, relevancy score, hallucination flag, and auto-repair fallback as `infer_local.py`. If Hugging Face cannot serve your custom model repo through an inference provider, the script automatically falls back to the local `model/` folder so the command still returns the local-style JSON. Use `--no-local-fallback` if you want cloud-only failure behavior.
172
 
173
  Hosted Hugging Face API calls usually do not return token logits, so `important_tokens` may be empty and `confidence` may be `0.0` unless your endpoint returns token-level details. When the local fallback runs, those fields are computed the same way as `infer_local.py`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
 
175
  Explicit base model for LoRA adapter loading:
176
 
 
12
  - `finetune_coding_llm_colab.py`: local training script (LoRA) + optional upload
13
  - `infer_local.py`: test local trained model with structured JSON output
14
  - `infer_cloud.py`: run Hugging Face API inference and force the same structured JSON output
15
+ - `handler.py`: custom Hugging Face Inference Endpoint handler that returns the same JSON contract from the hosted endpoint
16
  - `evaluate_model.py`: run multi-prompt quality checks and report accuracy
17
  - `upload_to_hf.py`: upload local model folder to HF
18
  - `run_pipeline.py`: one command for generate + train (+ optional upload)
 
172
  `infer_cloud.py` applies the same JSON parsing, Python syntax check, relevancy score, hallucination flag, and auto-repair fallback as `infer_local.py`. If Hugging Face cannot serve your custom model repo through an inference provider, the script automatically falls back to the local `model/` folder so the command still returns the local-style JSON. Use `--no-local-fallback` if you want cloud-only failure behavior.
173
 
174
  Hosted Hugging Face API calls usually do not return token logits, so `important_tokens` may be empty and `confidence` may be `0.0` unless your endpoint returns token-level details. When the local fallback runs, those fields are computed the same way as `infer_local.py`.
175
+
176
+ ### Cloud Output Guarantee
177
+
178
+ To make other users receive this JSON pattern with their own token, deploy this repository as a Hugging Face Dedicated Inference Endpoint. The included `handler.py` is loaded by the endpoint and returns:
179
+
180
+ ```json
181
+ {
182
+ "code": "string",
183
+ "explanation": "string",
184
+ "confidence": 0.0,
185
+ "important_tokens": [],
186
+ "relevancy_score": 0.0,
187
+ "hallucination": false,
188
+ "hallucination_check_reason": "string",
189
+ "latency_ms": 0
190
+ }
191
+ ```
192
+
193
+ Endpoint request example:
194
+
195
+ ```powershell
196
+ $env:HF_TOKEN="their_huggingface_token"
197
+ Invoke-RestMethod `
198
+ -Uri "https://your-endpoint-url.endpoints.huggingface.cloud" `
199
+ -Method Post `
200
+ -Headers @{ Authorization = "Bearer $env:HF_TOKEN" } `
201
+ -ContentType "application/json" `
202
+ -Body '{"inputs":"Fix this code: def add(a,b) return a+b","parameters":{"max_new_tokens":320}}'
203
+ ```
204
+
205
+ Calling the model repository directly through Hugging Face serverless inference is not enough if Hugging Face has no provider serving the custom repo. Use a Dedicated Inference Endpoint or your own cloud VM for true cloud execution.
206
 
207
  Explicit base model for LoRA adapter loading:
208