Views
No views yet
1from peft import AutoPeftModelForCausalLM
2from transformers import AutoTokenizer
3model_id='parlance-labs/hc-mistral-alpaca'
4model = AutoPeftModelForCausalLM.from_pretrained(model_id).cuda()
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6tokenizer.pad_token = tokenizer.eos_token1def prompt(nlq, cols):
2 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.
3
4### Instruction:
5
6NLQ: "{nlq}"
7
8Columns: {cols}
9
10### Response:
11"""
12
13def prompt_tok(nlq, cols):
14 _p = prompt(nlq, cols)
15 input_ids = tokenizer(_p, return_tensors="pt", truncation=True).input_ids.cuda()
16 out_ids = model.generate(input_ids=input_ids, max_new_tokens=5000,
17 do_sample=False)
18 return tokenizer.batch_decode(out_ids.detach().cpu().numpy(),
19 skip_special_tokens=True)[0][len(_p):]1# model inputs
2nlq = "Exception count by exception and caller"
3cols = ['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']
4
5# print prediction
6out = prompt_tok(nlq, cols)
7print(nlq, '\n', out)"{'breakdowns': ['exception.message', 'exception.type'], 'calculations': [{'op': 'COUNT'}], 'filters': [{'column': 'exception.message', 'op': 'exists'}, {'column': 'exception.type', 'op': 'exists'}], 'orders': [{'op': 'COUNT', 'order': 'descending'}], 'time_range': 7200}"