File size: 2,305 Bytes
0bb114a 8cea724 6edbc9f 0bb114a 6edbc9f 0bb114a 6edbc9f 0bb114a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
This model is a merged version of [parlance-labs/hc-mistral-alpaca](https://huggingface.co/parlance-labs/hc-mistral-alpaca)
## Usage
You can use this model with the following code:
First, download the model
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id='parlance-labs/hc-mistral-alpaca-merged'
model = AutoModelForCausalLM.from_pretrained(model_id).cuda()
tokenizer = AutoTokenizer.from_pretrained(model_id)
tokenizer.pad_token = tokenizer.eos_token
```
Define helper functions
```python
def prompt(nlq, cols):
return f"""Honeycomb is an observability platform that allows you to write queries to inspect trace data. You are an assistant that takes a natural language query (NLQ) and a list of valid columns and produce a Honeycomb query.
### Instruction:
NLQ: "{nlq}"
Columns: {cols}
### Response:
"""
def prompt_tok(nlq, cols):
_p = prompt(nlq, cols)
input_ids = tokenizer(_p, return_tensors="pt", truncation=True).input_ids.cuda()
out_ids = model.generate(input_ids=input_ids, max_new_tokens=5000,
do_sample=False)
return tokenizer.batch_decode(out_ids.detach().cpu().numpy(),
skip_special_tokens=True)[0][len(_p):]
```
Get predictions
```python
nlq = "Exception count by exception and caller"
cols = ['error', 'exception.message', 'exception.type', 'exception.stacktrace', 'SampleRate', 'name', 'db.user', 'type', 'duration_ms', 'db.name', 'service.name', 'http.method', 'db.system', 'status_code', 'db.operation', 'library.name', 'process.pid', 'net.transport', 'messaging.system', 'rpc.system', 'http.target', 'db.statement', 'library.version', 'status_message', 'parent_name', 'aws.region', 'process.command', 'rpc.method', 'span.kind', 'serializer.name', 'net.peer.name', 'rpc.service', 'http.scheme', 'process.runtime.name', 'serializer.format', 'serializer.renderer', 'net.peer.port', 'process.runtime.version', 'http.status_code', 'telemetry.sdk.language', 'trace.parent_id', 'process.runtime.description', 'span.num_events', 'messaging.destination', 'net.peer.ip', 'trace.trace_id', 'telemetry.instrumentation_library', 'trace.span_id', 'span.num_links', 'meta.signal_type', 'http.route']
# print prediction
out = prompt_tok(nlq, cols)
print(nlq, '\n', out)
```
|