Instructions to use sharp-pixel/opensearch-agentic-dsl with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use sharp-pixel/opensearch-agentic-dsl with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("mistralai/Ministral-3-8B-Instruct-2512-BF16") model = PeftModel.from_pretrained(base_model, "sharp-pixel/opensearch-agentic-dsl") - Transformers
How to use sharp-pixel/opensearch-agentic-dsl with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="sharp-pixel/opensearch-agentic-dsl")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("sharp-pixel/opensearch-agentic-dsl", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use sharp-pixel/opensearch-agentic-dsl with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "sharp-pixel/opensearch-agentic-dsl" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sharp-pixel/opensearch-agentic-dsl", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/sharp-pixel/opensearch-agentic-dsl
- SGLang
How to use sharp-pixel/opensearch-agentic-dsl 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 "sharp-pixel/opensearch-agentic-dsl" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sharp-pixel/opensearch-agentic-dsl", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "sharp-pixel/opensearch-agentic-dsl" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sharp-pixel/opensearch-agentic-dsl", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use sharp-pixel/opensearch-agentic-dsl with Docker Model Runner:
docker model run hf.co/sharp-pixel/opensearch-agentic-dsl
Download example.py from sharp-pixel/opensearch-agentic-dsl: direct link, hf CLI and curl.
- Browser
- Download file 3.56 kB
-
https://huggingface.co/sharp-pixel/opensearch-agentic-dsl/resolve/main/example.py
- Command line
-
hf download hf://sharp-pixel/opensearch-agentic-dsl/example.py
-
curl -L -o example.py https://huggingface.co/sharp-pixel/opensearch-agentic-dsl/resolve/main/example.py
3.56 kB
| """Generate an OpenSearch request with opensearch-agentic-dsl on a CUDA GPU.""" | |
| import json | |
| import os | |
| from pathlib import Path | |
| import torch | |
| from peft import PeftModel | |
| from transformers import AutoModelForImageTextToText, AutoTokenizer | |
| BASE_MODEL = "mistralai/Ministral-3-8B-Instruct-2512-BF16" | |
| BASE_REVISION = "06cc81bfd6e45321d8fc8f816576c5b6ac67ec22" | |
| ASSET_DIR = Path(__file__).resolve().parent | |
| ADAPTER_ID = os.environ.get("ADAPTER_ID", str(ASSET_DIR)) | |
| SYSTEM_PROMPT = (ASSET_DIR / "prompts/system.txt").read_text(encoding="utf-8").strip() | |
| USER_PROMPT_TEMPLATE = (ASSET_DIR / "prompts/user.txt").read_text(encoding="utf-8").strip() | |
| context = { | |
| "required_filters": [{"term": {"availability": "active"}}], | |
| "ui_max_price": 8000, | |
| "size": 24, | |
| "track_total_hits": 10000, | |
| "sort_mode": "recommended", | |
| "persona": {"id": "anonymous", "version": 1, "mode": "unprofiled"}, | |
| } | |
| question = ( | |
| "Shopper request: dress watch under 5000\n" | |
| "Trusted planner context: " | |
| + json.dumps(context, ensure_ascii=False, separators=(",", ":")) | |
| + "\nDerive price and gender affinity in the generated DSL. " | |
| "Apply persona only as instructed. Follow sort_mode." | |
| ) | |
| if len(question) > 1000: | |
| raise ValueError("Native planner question exceeds 1,000 characters") | |
| index_mapping = { | |
| "_doc": { | |
| "dynamic": "false", | |
| "properties": { | |
| "title": {"type": "text"}, | |
| "brand": {"type": "text"}, | |
| "canonical_text": {"type": "text"}, | |
| "description": {"type": "text"}, | |
| "availability": {"type": "keyword"}, | |
| "category": {"type": "keyword"}, | |
| "price": {"type": "integer"}, | |
| "quality_score": {"type": "rank_feature"}, | |
| "freshness_score": {"type": "rank_feature"}, | |
| "seller_score": {"type": "rank_feature"}, | |
| }, | |
| } | |
| } | |
| query_fields = list(index_mapping["_doc"]["properties"]) | |
| def native_string_parameter(value): | |
| compact = json.dumps(value, ensure_ascii=False, separators=(",", ":")) | |
| return json.dumps(compact, ensure_ascii=False) | |
| user_prompt = USER_PROMPT_TEMPLATE | |
| for placeholder, value in { | |
| "${parameters.question}": question, | |
| "${parameters.index_mapping:-}": native_string_parameter(index_mapping), | |
| "${parameters.query_fields:-}": native_string_parameter(query_fields), | |
| }.items(): | |
| user_prompt = user_prompt.replace(placeholder, value) | |
| messages = [ | |
| {"role": "system", "content": SYSTEM_PROMPT}, | |
| {"role": "user", "content": user_prompt}, | |
| ] | |
| tokenizer = AutoTokenizer.from_pretrained( | |
| BASE_MODEL, revision=BASE_REVISION, trust_remote_code=False | |
| ) | |
| tokenizer.pad_token = tokenizer.eos_token | |
| base_model = AutoModelForImageTextToText.from_pretrained( | |
| BASE_MODEL, | |
| revision=BASE_REVISION, | |
| dtype=torch.bfloat16, | |
| device_map={"": 0}, | |
| trust_remote_code=False, | |
| ) | |
| model = PeftModel.from_pretrained(base_model, ADAPTER_ID) | |
| model.eval() | |
| input_ids = tokenizer.apply_chat_template( | |
| messages, tokenize=True, add_generation_prompt=True, return_dict=False | |
| ) | |
| inputs = { | |
| "input_ids": torch.tensor([input_ids], device=model.device), | |
| "attention_mask": torch.ones((1, len(input_ids)), dtype=torch.long, device=model.device), | |
| } | |
| with torch.inference_mode(): | |
| generated = model.generate( | |
| **inputs, | |
| do_sample=False, | |
| max_new_tokens=1024, | |
| eos_token_id=tokenizer.eos_token_id, | |
| pad_token_id=tokenizer.pad_token_id, | |
| ) | |
| completion = tokenizer.decode( | |
| generated[0, len(input_ids):], skip_special_tokens=True | |
| ) | |
| print(completion) | |