Skip to content

Commit 9df04b8

Browse files
committed
Compiles and runs
1 parent c640b99 commit 9df04b8

4 files changed

Lines changed: 27 additions & 24 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ known-first-party = ["fluid_server"]
6969
requires = ["hatchling"]
7070
build-backend = "hatchling.build"
7171

72-
[tool.hatch.build.targets.wheel]
73-
packages = ["src"]
74-
7572
# Entry point for the module
7673
[project.scripts]
7774
fluid-server = "fluid_server.__main__:main"

src/fluid_server/api/v1/embeddings.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import logging
66
import time
7-
from typing import Annotated
7+
from typing import Annotated, List
88

99
from fastapi import APIRouter, Depends, HTTPException, Request
1010
from fastapi.responses import JSONResponse
@@ -39,7 +39,7 @@ async def create_embeddings(
3939
) -> EmbeddingResponse:
4040
"""
4141
Create embeddings for text inputs (OpenAI-compatible)
42-
42+
4343
This endpoint is compatible with OpenAI's embeddings API and can be used
4444
as a drop-in replacement.
4545
"""
@@ -53,15 +53,15 @@ async def create_embeddings(
5353

5454
# Ensure input is a list
5555
inputs = request.input if isinstance(request.input, list) else [request.input]
56-
56+
5757
# Generate embeddings
5858
start_time = time.time()
5959
embeddings = await embedding_manager.get_text_embeddings(
6060
texts=inputs,
6161
model_name=request.model
6262
)
6363
processing_time = time.time() - start_time
64-
64+
6565
# Create response data
6666
embedding_data = []
6767
for i, embedding in enumerate(embeddings):
@@ -71,28 +71,28 @@ async def create_embeddings(
7171
index=i
7272
)
7373
)
74-
74+
7575
# Calculate usage statistics (approximate)
7676
total_tokens = sum(len(text.split()) for text in inputs)
7777
usage = EmbeddingUsage(
7878
prompt_tokens=total_tokens,
7979
total_tokens=total_tokens
8080
)
81-
81+
8282
# Create response
8383
response = EmbeddingResponse(
8484
data=embedding_data,
8585
model=request.model,
8686
usage=usage
8787
)
88-
88+
8989
logger.info(
9090
f"Generated embeddings for {len(inputs)} inputs "
9191
f"using model '{request.model}' in {processing_time:.2f}s"
9292
)
93-
93+
9494
return response
95-
95+
9696
except Exception as e:
9797
logger.error(f"Error generating embeddings: {e}")
9898
if isinstance(e, HTTPException):
@@ -114,15 +114,15 @@ async def create_embeddings_batch(
114114
status_code=503,
115115
detail="Embeddings functionality is disabled"
116116
)
117-
117+
118118
responses = []
119119
for request in requests:
120120
# Process each request individually but return as batch
121121
response = await create_embeddings(request, embedding_manager)
122122
responses.append(response)
123-
123+
124124
return responses
125-
125+
126126
except Exception as e:
127127
logger.error(f"Error in batch embeddings: {e}")
128128
if isinstance(e, HTTPException):
@@ -140,7 +140,7 @@ async def list_embedding_models(
140140
"""
141141
try:
142142
info = embedding_manager.get_embedding_info()
143-
143+
144144
models = []
145145
for model_type, model_list in info["available_models"].items():
146146
for model_name in model_list:
@@ -151,12 +151,12 @@ async def list_embedding_models(
151151
"owned_by": "fluid-server",
152152
"model_type": f"embedding_{model_type}"
153153
})
154-
154+
155155
return JSONResponse(content={
156156
"object": "list",
157157
"data": models
158158
})
159-
159+
160160
except Exception as e:
161161
logger.error(f"Error listing embedding models: {e}")
162162
raise HTTPException(status_code=500, detail=str(e))
@@ -172,7 +172,7 @@ async def get_embedding_info(
172172
try:
173173
info = embedding_manager.get_embedding_info()
174174
return JSONResponse(content=info)
175-
175+
176176
except Exception as e:
177177
logger.error(f"Error getting embedding info: {e}")
178178
raise HTTPException(status_code=500, detail=str(e))

src/fluid_server/runtimes/base_embedding.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
class EmbeddingType(Enum):
1313
"""Supported embedding types"""
1414
TEXT = "text"
15-
IMAGE = "image"
16-
AUDIO = "audio"
1715

1816

1917
class BaseEmbeddingRuntime(ABC):
@@ -52,14 +50,14 @@ def get_info(self) -> dict[str, Any]:
5250
@abstractmethod
5351
async def embed(
5452
self,
55-
inputs: Union[str, List[str], bytes],
53+
inputs: Union[str, List[str]],
5654
embedding_type: EmbeddingType
5755
) -> List[List[float]]:
5856
"""
5957
Generate embeddings for the given inputs
6058
6159
Args:
62-
inputs: Text string(s), image bytes, or audio bytes
60+
inputs: Text string(s)
6361
embedding_type: Type of embedding to generate
6462
6563
Returns:

src/fluid_server/runtimes/llamacpp_embedding.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
logger = logging.getLogger(__name__)
1515

16+
DEFAULT_EMBEDDING_REPO_ID = "unsloth/embeddinggemma-300m-GGUF"
17+
DEFAULT_EMBEDDING_FILENAME = "embeddinggemma-300M-BF16.gguf"
1618

1719
class LlamaCppEmbeddingRuntime(BaseEmbeddingRuntime):
1820
"""llama-cpp runtime for generating text embeddings from GGUF models"""
@@ -47,6 +49,12 @@ def _load_sync(self) -> None:
4749
self._Llama = Llama
4850
repo_id, filename, model_file = self._resolve_model_sources()
4951

52+
if repo_id is None and model_file is None:
53+
repo_id = DEFAULT_EMBEDDING_REPO_ID
54+
filename = DEFAULT_EMBEDDING_FILENAME
55+
elif repo_id == DEFAULT_EMBEDDING_REPO_ID and filename is None:
56+
filename = DEFAULT_EMBEDDING_FILENAME
57+
5058
load_kwargs: dict[str, Any] = {
5159
"embedding": True,
5260
"n_ctx": 0,
@@ -191,4 +199,4 @@ def _resolve_model_sources(self) -> tuple[Optional[str], Optional[str], Optional
191199
return repo_id, filename, None
192200
return self.model_id, None, None
193201

194-
return None, None, None
202+
return DEFAULT_EMBEDDING_REPO_ID, DEFAULT_EMBEDDING_FILENAME, None

0 commit comments

Comments
 (0)