Skip to content

Commit e2ebe68

Browse files
authored
Merge pull request #135 from codelion/fix-backslash-python3.10
Fix backslash python3.10
2 parents 811b8c1 + 58840a1 commit e2ebe68

File tree

9 files changed

+123
-18
lines changed

9 files changed

+123
-18
lines changed

.github/workflows/publish.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,32 @@ jobs:
5050
registry: ghcr.io
5151
username: ${{ github.actor }}
5252
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
# Extract metadata for proxy_only image
55+
- name: Extract metadata for proxy_only Docker
56+
id: meta-proxy
57+
uses: docker/metadata-action@v5
58+
with:
59+
images: ghcr.io/${{ github.repository }}
60+
flavor: |
61+
suffix=-slim
62+
tags: |
63+
type=semver,pattern={{version}}
64+
type=semver,pattern={{major}}.{{minor}}
65+
latest
66+
67+
# Build and push proxy image
68+
- name: Build and push proxy_only Docker image
69+
uses: docker/build-push-action@v5
70+
with:
71+
context: .
72+
file: Dockerfile.proxy_only
73+
push: true
74+
platforms: linux/amd64,linux/arm64
75+
tags: ${{ steps.meta-proxy.outputs.tags }}
76+
labels: ${{ steps.meta-proxy.outputs.labels }}
77+
cache-from: type=gha,scope=proxy
78+
cache-to: type=gha,scope=proxy,mode=max
5379

5480
- name: Extract metadata for Docker
5581
id: meta

Dockerfile.proxy_only

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Build stage
2+
FROM python:3.12-slim AS builder
3+
4+
# Define build argument with default value
5+
ARG PORT=8000
6+
# Make it available as env variable at runtime
7+
ENV OPTILLM_PORT=$PORT
8+
9+
# Set working directory
10+
WORKDIR /app
11+
12+
# Install system dependencies
13+
RUN apt-get update && apt-get install -y --no-install-recommends \
14+
build-essential \
15+
python3-dev \
16+
gcc \
17+
g++ \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# Copy only the requirements file first to leverage Docker cache
21+
COPY requirements_proxy_only.txt .
22+
23+
# Install Python dependencies
24+
RUN pip install --no-cache-dir -r requirements_proxy_only.txt
25+
26+
# Final stage
27+
FROM python:3.12-slim
28+
29+
# Install curl for the healthcheck
30+
RUN apt-get update && apt-get install -y --no-install-recommends \
31+
curl && \
32+
apt-get clean && rm -rf /var/lib/apt/lists/*
33+
34+
# Set working directory
35+
WORKDIR /app
36+
37+
# Copy installed dependencies from builder stage
38+
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
39+
COPY --from=builder /usr/local/bin /usr/local/bin
40+
41+
# Copy application code
42+
COPY . .
43+
44+
# Create a non-root user and switch to it
45+
RUN useradd -m appuser
46+
USER appuser
47+
48+
# Set environment variables
49+
ENV PYTHONUNBUFFERED=1
50+
51+
# Use the ARG in EXPOSE
52+
EXPOSE ${PORT}
53+
54+
# Run the application
55+
ENTRYPOINT ["python", "optillm.py"]

optillm.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def load_plugins():
158158
package_plugin_dir = os.path.join(os.path.dirname(optillm.__file__), 'plugins')
159159

160160
# Get local project plugins directory
161-
current_dir = os.getcwd()
161+
current_dir = os.getcwd() if server_config.get("plugins_dir", "") == "" else server_config["plugins_dir"]
162162
local_plugin_dir = os.path.join(current_dir, 'optillm', 'plugins')
163163

164164
plugin_dirs = []
@@ -664,7 +664,8 @@ def parse_args():
664664
("--return-full-response", "OPTILLM_RETURN_FULL_RESPONSE", bool, False, "Return the full response including the CoT with <thinking> tags"),
665665
("--port", "OPTILLM_PORT", int, 8000, "Specify the port to run the proxy"),
666666
("--log", "OPTILLM_LOG", str, "info", "Specify the logging level", list(logging_levels.keys())),
667-
("--launch-gui", "OPTILLM_LAUNCH_GUI", bool, False, "Launch a Gradio chat interface")
667+
("--launch-gui", "OPTILLM_LAUNCH_GUI", bool, False, "Launch a Gradio chat interface"),
668+
("--plugins-dir", "OPTILLM_PLUGINS_DIR", str, "", "Path to the plugins directory"),
668669
]
669670

670671
for arg, env, type_, default, help_text, *extra in args_env:
@@ -704,11 +705,11 @@ def main():
704705
global server_config
705706
# Call this function at the start of main()
706707
args = parse_args()
707-
load_plugins()
708-
709708
# Update server_config with all argument values
710709
server_config.update(vars(args))
711710

711+
load_plugins()
712+
712713
port = server_config['port']
713714

714715
# Set logging level from user request

optillm/plugins/coc_plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,15 @@ def sanitize_code(code: str) -> str:
104104
safe_lines.append(line)
105105

106106
safe_code = '\n'.join(safe_lines)
107+
safe_code = safe_code.replace('\n', '\n ')
107108

108109
# Add safety wrapper
109110
wrapper = f"""
110111
{imports}
111112
112113
def safe_execute():
113114
import numpy as np # Always allow numpy
114-
{safe_code.replace('\n', '\n ')}
115+
{safe_code}
115116
return answer if 'answer' in locals() else None
116117
117118
result = safe_execute()

requirements_proxy_only.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
numpy
2+
networkx
3+
openai
4+
z3-solver
5+
aiohttp
6+
flask
7+
azure.identity
8+
scikit-learn
9+
litellm
10+
requests
11+
beautifulsoup4
12+
lxml
13+
presidio_analyzer
14+
presidio_anonymizer
15+
nbformat
16+
nbconvert
17+
ipython
18+
ipykernel
19+
gradio

scripts/eval_aime_benchmark.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
logger = logging.getLogger(__name__)
1616

1717
# Initialize OpenAI client
18-
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"), base_url="http://localhost:8000/v1")
18+
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"), base_url="https://ot7nh9nqf4l7b43s.us-east-1.aws.endpoints.huggingface.cloud/v1/")
1919

2020
SYSTEM_PROMPT = '''You are solving AIME (American Invitational Mathematics Examination) problems.
2121
@@ -241,18 +241,21 @@ def analyze_results(results: List[Dict], n: int):
241241
print("---")
242242

243243
def main(model: str, n_attempts: int):
244-
"""Main evaluation function."""
244+
"""Main evaluation function that handles gaps in processed indexes."""
245245
os.makedirs("results", exist_ok=True)
246246

247-
# Include n_attempts in filename to keep separate results for different n values
248247
results_file = f"evaluation_results_{model.replace('/', '_')}_pass_at_{n_attempts}.json"
249248

250249
dataset = load_2024_dataset()
251250
existing_results = load_existing_results(results_file)
252-
last_processed_index = get_last_processed_index(existing_results)
253251

254-
for idx, item in enumerate(tqdm(dataset, desc="Evaluating problems")):
255-
if idx <= last_processed_index:
252+
# Create a set of already processed indexes for efficient lookup
253+
processed_indexes = {result['index'] for result in existing_results}
254+
255+
for _, item in enumerate(tqdm(dataset, desc="Evaluating problems")):
256+
id = int(item['id'])
257+
# Skip if this index has already been processed
258+
if id in processed_indexes:
256259
continue
257260

258261
problem_text = item['problem']
@@ -263,7 +266,7 @@ def main(model: str, n_attempts: int):
263266
is_correct, first_correct = evaluate_pass_at_n(attempts, correct_answer)
264267

265268
result = {
266-
"index": idx,
269+
"index": id,
267270
"problem": problem_text,
268271
"attempts": attempts,
269272
"correct_answer": correct_answer,
@@ -275,6 +278,7 @@ def main(model: str, n_attempts: int):
275278
final_results = load_existing_results(results_file)
276279
analyze_results(final_results, n_attempts)
277280

281+
278282
if __name__ == "__main__":
279283
parser = argparse.ArgumentParser(description="Evaluate LLM performance on AIME 2024 problems")
280284
parser.add_argument("--model", type=str, required=True, help="OpenAI model to use (e.g., gpt-4, gpt-3.5-turbo)")

scripts/eval_arena_hard_auto_rtc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
logger = logging.getLogger(__name__)
1818

1919
# Initialize OpenAI client (only used for chat completions now)
20-
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
20+
client = OpenAI(base_url="http://localhost:8000/v1", api_key=os.environ.get("OPENAI_API_KEY"))
21+
# client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
2122

2223
@dataclass
2324
class RTCConfig:
@@ -58,8 +59,7 @@ def get_llm_response(messages: List[Dict], model: str) -> Optional[str]:
5859
response = client.chat.completions.create(
5960
model=model,
6061
messages=messages,
61-
temperature=0.7,
62-
max_tokens=1000
62+
max_tokens=4096
6363
)
6464
return response.choices[0].message.content.strip()
6565
except Exception as e:

scripts/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
datasets
22
accelerate
33
huggingface_hub
4-
git+https://github.com/huggingface/transformers.git

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="optillm",
5-
version="0.0.24",
5+
version="0.0.25",
66
packages=find_packages(),
77
py_modules=['optillm'],
88
package_data={
@@ -33,7 +33,7 @@
3333
"ipykernel",
3434
"peft",
3535
"bitsandbytes",
36-
"gradio",
36+
"gradio"
3737
],
3838
entry_points={
3939
'console_scripts': [

0 commit comments

Comments
 (0)