summaryrefslogtreecommitdiff
path: root/examples/server/oai.hpp
diff options
context:
space:
mode:
authorWu Jian Ping <wujjpp@hotmail.com>2024-01-29 21:48:10 +0800
committerGitHub <noreply@github.com>2024-01-29 15:48:10 +0200
commitc82d18e863fcde91b4b1109b1d0c73ea4470c405 (patch)
tree20ade3c1f035baa8aa3a3c7d2c3ef8a9cac1b333 /examples/server/oai.hpp
parent14fef85e2d5361e6b4dd7a9ecf22bb817362997d (diff)
server : embeddings compatibility for OpenAI (#5190)
Diffstat (limited to 'examples/server/oai.hpp')
-rw-r--r--examples/server/oai.hpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/examples/server/oai.hpp b/examples/server/oai.hpp
index bc5db6ee..43410f80 100644
--- a/examples/server/oai.hpp
+++ b/examples/server/oai.hpp
@@ -206,3 +206,18 @@ inline static std::vector<json> format_partial_response_oaicompat(const task_res
return std::vector<json>({ret});
}
+
+inline static json format_embeddings_response_oaicompat(const json &request, const json &embeddings)
+{
+ json res =
+ json{
+ {"model", json_value(request, "model", std::string(DEFAULT_OAICOMPAT_MODEL))},
+ {"object", "list"},
+ {"usage",
+ json{{"prompt_tokens", 0},
+ {"total_tokens", 0}}},
+ {"data", embeddings}
+ };
+ return res;
+}
+