Add OptiMind code and document it on README#42
Conversation
|
@microsoft-github-policy-service agree company="Microsoft" |
|
|
||
| # if global variable tokenizer is not set, load the tokenizer | ||
| if 'tokenizer' not in globals(): | ||
| tokenizer = AutoTokenizer.from_pretrained( |
Check warning
Code scanning / Bandit
Unsafe Hugging Face Hub download without revision pinning in from_pretrained() Warning
| # Second attempt: strip non-numeric/operator chars | ||
| try: | ||
| cleaned = re.sub(r"[^0-9eE\.\+\-\*/\(\)]", "", value) | ||
| return round(eval(cleaned), 5) |
Check warning
Code scanning / Bandit
Use of possibly insecure function - consider using safer ast.literal_eval. Warning
|
|
||
| # First attempt: direct safe eval | ||
| try: | ||
| return round(eval(value), 5) |
Check warning
Code scanning / Bandit
Use of possibly insecure function - consider using safer ast.literal_eval. Warning
| from huggingface_hub import snapshot_download | ||
|
|
||
| try: | ||
| return snapshot_download( |
Check warning
Code scanning / Bandit
Unsafe Hugging Face Hub download without revision pinning in snapshot_download() Warning
| f.write(program) | ||
|
|
||
| try: | ||
| res = subprocess.run( |
Check notice
Code scanning / Bandit
subprocess call - check for execution of untrusted input. Note
|
|
||
| def build_prompt_optmath(question: str, instruction: str = "", solver="gurobipy") -> str: | ||
| if instruction == "": | ||
| instruction = random.choice(instruction_list).strip().format(solver=solver) |
Check notice
Code scanning / Bandit
Standard pseudo-random generators are not suitable for security/cryptographic purposes. Note
| raise ValueError("error_analysis_file must be provided if apply_error_analysis is set.") | ||
|
|
||
| if not args.apply_error_analysis and not args.apply_hint_instructions: | ||
| assert args.tool_prompt_type in ("default", "add_question"), "If not applying hint instructions or error analysis, tool_prompt_type must be 'default' or 'add_question'." |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note
| except Exception as e: | ||
| print(f"OpenAI call error: {e}, retrying...") | ||
| import pdb; pdb.set_trace() | ||
| time.sleep(random.uniform(2, 5)) |
Check notice
Code scanning / Bandit
Standard pseudo-random generators are not suitable for security/cryptographic purposes. Note
| import nest_asyncio, pdb | ||
| from datetime import datetime | ||
| from collections import Counter | ||
| import argparse, os, logging, warnings, subprocess, math, random, ast, re |
Check notice
Code scanning / Bandit
Consider possible security implications associated with the subprocess module. Note
| continue | ||
| try: | ||
| data = json.loads(stats_path.read_text()) | ||
| except Exception: |
Check notice
Code scanning / Bandit
Try, Except, Continue detected. Note
optiminddirectory, which includes the optimind repo, including the evaluation scripts, cleaned benchmarks, and the hint library described in the OptiMind paper.