Skip to content

Commit 4252dca

Browse files
authored
Merge pull request #124 from codelion/fix-dockerfile-arm
Fix dockerfile arm and streaming responses
2 parents 3bad2f3 + 60527e2 commit 4252dca

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ WORKDIR /app
66

77
# Install system dependencies
88
RUN apt-get update && apt-get install -y --no-install-recommends \
9-
gcc libc6-dev \
9+
build-essential \
10+
python3-dev \
11+
gcc \
12+
g++ \
1013
&& rm -rf /var/lib/apt/lists/*
1114

1215
# Copy only the requirements file first to leverage Docker cache
@@ -44,4 +47,4 @@ ENV PYTHONUNBUFFERED=1
4447
EXPOSE 8000
4548

4649
# Run the application
47-
ENTRYPOINT ["python", "optillm.py"]
50+
CMD ["optillm"]

optillm.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,10 @@ def execute_single_approach(approach, system_prompt, initial_query, client, mode
246246
if hasattr(request, 'json'):
247247
data = request.get_json()
248248
messages = data.get('messages', [])
249-
# Copy all parameters except 'model' and 'messages'
249+
# Copy all parameters except 'stream', 'model' , 'n' and 'messages'
250250
kwargs = {k: v for k, v in data.items()
251-
if k not in ['model', 'messages', 'optillm_approach']}
251+
if k not in ['model', 'messages', 'stream', 'n', 'optillm_approach']}
252252
response = none_approach(original_messages=messages, client=client, model=model, **kwargs)
253-
254253
# For none approach, we return the response and a token count of 0
255254
# since the full token count is already in the response
256255
return response, 0
@@ -369,6 +368,21 @@ def generate_streaming_response(final_response, model):
369368
# Yield the final message to indicate the stream has ended
370369
yield "data: [DONE]\n\n"
371370

371+
def extract_contents(response_obj):
372+
contents = []
373+
# Handle both single response and list of responses
374+
responses = response_obj if isinstance(response_obj, list) else [response_obj]
375+
376+
for response in responses:
377+
# Extract content from first choice if it exists
378+
if (response.get('choices') and
379+
len(response['choices']) > 0 and
380+
response['choices'][0].get('message') and
381+
response['choices'][0]['message'].get('content')):
382+
contents.append(response['choices'][0]['message']['content'])
383+
384+
return contents
385+
372386
def parse_conversation(messages):
373387
system_prompt = ""
374388
conversation = []
@@ -523,8 +537,13 @@ def proxy():
523537
result = responses
524538
else:
525539
result, completion_tokens = execute_single_approach(approaches[0], system_prompt, initial_query, client, model)
540+
526541
logger.debug(f'Direct proxy response: {result}')
527-
return jsonify(result), 200
542+
543+
if stream:
544+
return Response(generate_streaming_response(extract_contents(result), model), content_type='text/event-stream')
545+
else :
546+
return jsonify(result), 200
528547

529548
elif operation == 'AND' or operation == 'OR':
530549
if contains_none:
@@ -545,7 +564,7 @@ def proxy():
545564
messages = tagged_conversation_to_messages(response)
546565
if messages: # Only take the last message if we have any
547566
response = messages[-1]['content']
548-
567+
549568
if stream:
550569
return Response(generate_streaming_response(response, model), content_type='text/event-stream')
551570
else:

optillm/plugins/readurls_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def extract_urls(text: str) -> List[str]:
2525
def fetch_webpage_content(url: str, max_length: int = 100000) -> str:
2626
try:
2727
headers = {
28-
'User-Agent': 'optillm/0.0.19 (https://github.com/codelion/optillm)'
28+
'User-Agent': 'optillm/0.0.20 (https://github.com/codelion/optillm)'
2929
}
3030

3131
response = requests.get(url, headers=headers, timeout=10)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="optillm",
5-
version="0.0.19",
5+
version="0.0.20",
66
packages=find_packages(),
77
py_modules=['optillm'],
88
package_data={

0 commit comments

Comments
 (0)