Skip to content

Commit

Permalink
Changed protobuf version and fixed /api/generations route
Browse files Browse the repository at this point in the history
  • Loading branch information
like-a-freedom committed Feb 2, 2025
1 parent 4b9fb73 commit a81191b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ ENV ULIMIT_STACK=1048576
ENV CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON"

#29.3
#5.29.3
ARG PROTOBUF_VERSION=22.3
#22.3
ARG PROTOBUF_VERSION=5.29.3
RUN git clone --branch v${PROTOBUF_VERSION} --recurse-submodules https://github.com/protocolbuffers/protobuf && \
cd protobuf && \
cmake -Dprotobuf_BUILD_TESTS=OFF \
Expand Down
40 changes: 19 additions & 21 deletions src/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,32 +159,30 @@ async def generate(request: OllamaGenerateRequest):
start_time = time.time_ns()
load_start = time.time_ns()

# Process the prompt
if "<image>" in request.prompt:
# Extract base64 image if present
import re

image_match = re.search(r"<image>(.*?)</image>", request.prompt)
if image_match:
image_data = image_match.group(1)
# Remove image data from prompt
prompt = re.sub(r"<image>.*?</image>", "", request.prompt).strip()

# Process image
image_bytes = base64.b64decode(image_data)
image = Image.open(io.BytesIO(image_bytes))
else:
raise HTTPException(status_code=400, detail="Invalid image format")
else:
raise HTTPException(status_code=400, detail="No image provided")
# Process the prompt and images
prompt = request.prompt
processed_images = []

if request.images:
for image_data in request.images:
try:
image_bytes = base64.b64decode(image_data)
image = Image.open(io.BytesIO(image_bytes))
processed_images.append(image)
except Exception as e:
raise HTTPException(
status_code=400, detail=f"Invalid image format: {str(e)}"
)

load_duration = time.time_ns() - load_start

# Process image and generate response
prompt_eval_start = time.time_ns()
answer = vision_service.analyze_image(image, prompt)
prompt_eval_duration = time.time_ns() - prompt_eval_start
answers = []
for img in processed_images:
answer = vision_service.analyze_image(img, prompt)
answers.append(answer)

prompt_eval_duration = time.time_ns() - prompt_eval_start
total_duration = time.time_ns() - start_time

return OllamaGenerateResponse(
Expand Down
1 change: 1 addition & 0 deletions src/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class OllamaGenerateRequest(BaseModel):
prompt: str
stream: Optional[bool] = False
options: Optional[OllamaGenerateOptions] = OllamaGenerateOptions()
images: Optional[List[str]]


class OllamaGenerateResponse(BaseModel):
Expand Down

0 comments on commit a81191b

Please sign in to comment.