Run LLM check and confirmation on the retrieved xlm-RoBERTa-base model
(bert_output)
| 128 | return prompt |
| 129 | |
| 130 | def get_secrets_LLM(bert_output): |
| 131 | """Run LLM check and confirmation on the retrieved xlm-RoBERTa-base model""" |
| 132 | secrets_list = [] |
| 133 | litellm_model = os.environ["AUGMENT_MODEL"] |
| 134 | |
| 135 | start = time.time() |
| 136 | |
| 137 | for secrets in bert_output: |
| 138 | passw = secrets["secret"] |
| 139 | text = secrets["chunk"] |
| 140 | prompt = get_prompt(text, passw) |
| 141 | |
| 142 | ## Change the code here to accomodate non-litellm infra |
| 143 | response = litellm_client.chat.completions.create( |
| 144 | model=litellm_model, |
| 145 | messages = [ |
| 146 | { |
| 147 | "role": "system", |
| 148 | "content": "You are a helpful assistant. Your expertise is to identify the presence of APIs, database links, or leaked passwords. Do not explain." |
| 149 | }, |
| 150 | { |
| 151 | "role": "user", |
| 152 | "content": prompt |
| 153 | } |
| 154 | ], |
| 155 | ) |
| 156 | execution_time = (time.time()-start) |
| 157 | message = response.choices[0].message.content |
| 158 | |
| 159 | credential_pattern = r"<credential>(.*?)</credential>" |
| 160 | credential_matches = list(re.finditer(credential_pattern, message)) |
| 161 | |
| 162 | |
| 163 | credentials = [match.group(1) for match in credential_matches] |
| 164 | |
| 165 | secrets_list.append({'Extracted_Credentials':credentials, 'LLM_response':message,'chunk':text, 'generation_time': execution_time}) |
| 166 | |
| 167 | return secrets_list |
| 168 | |
| 169 | |
| 170 | def get_secrets_BERT(chunks, model=model, tokenizer=tokenizer): |
no test coverage detected