Skip to content

Commit 82d7c53

Browse files
committed
embeddings handle base64
1 parent 7de8880 commit 82d7c53

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

koboldcpp.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3770,7 +3770,12 @@ def do_POST(self):
37703770
outdatas = []
37713771
odidx = 0
37723772
for od in gen["data"]:
3773-
outdatas.append({"object":"embedding","index":odidx,"embedding":od})
3773+
if genparams.get("encoding_format", "")=="base64":
3774+
binary_data = struct.pack('<' + 'f' * len(od), *od)
3775+
b64_string = base64.b64encode(binary_data).decode('utf-8')
3776+
outdatas.append({"object":"embedding","index":odidx,"embedding":b64_string})
3777+
else:
3778+
outdatas.append({"object":"embedding","index":odidx,"embedding":od})
37743779
odidx += 1
37753780
genresp = (json.dumps({"object":"list","data":outdatas,"model":friendlyembeddingsmodelname,"usage":{"prompt_tokens":gen["count"],"total_tokens":gen["count"]}}).encode())
37763781
self.send_response(200)

0 commit comments

Comments
 (0)