Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8c1df6

Browse files
fix: engine Issues & API Issues (janhq#1811)
* chore: convention* fix: correct get remote model list* feat: auto generate remote model config* feat: support update remote engine* fix: do not generate remote model* chore: change engine_name to engine* fix: api key template on engine level* fix: add type for local engine* chore: cleanup* fix: add remote engine to /v1/engines GET* fix: build* fix: load engine when start model* chore: add log* fix: ignore chat_completions in model* fix: delete remote model* fix: replace api_key_template by header_template* fix: use engine from model yaml* fix: better error handling in stream mode* chore: cleanup* chore: unit test for anthropic response---------Co-authored-by: vansangpfiev <sang@jan.ai>
1 parentc508e68 commitf8c1df6

File tree

20 files changed

+663
-322
lines changed

20 files changed

+663
-322
lines changed

‎docs/static/openapi/cortex.json‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5388,18 +5388,18 @@
53885388
"engine",
53895389
"version",
53905390
"inference_params",
5391-
"TransformReq",
5392-
"TransformResp",
5391+
"transform_req",
5392+
"transform_resp",
53935393
"metadata"
53945394
],
53955395
"properties": {
53965396
"model": {
53975397
"type":"string",
53985398
"description":"The identifier of the model."
53995399
},
5400-
"api_key_template": {
5400+
"header_template": {
54015401
"type":"string",
5402-
"description":"Template for theAPI keyheader."
5402+
"description":"Template for the header."
54035403
},
54045404
"engine": {
54055405
"type":"string",
@@ -5432,7 +5432,7 @@
54325432
}
54335433
}
54345434
},
5435-
"TransformReq": {
5435+
"transform_req": {
54365436
"type":"object",
54375437
"properties": {
54385438
"get_models": {
@@ -5454,7 +5454,7 @@
54545454
}
54555455
}
54565456
},
5457-
"TransformResp": {
5457+
"transform_resp": {
54585458
"type":"object",
54595459
"properties": {
54605460
"chat_completions": {
@@ -6162,9 +6162,9 @@
61626162
"description":"Number of GPU layers.",
61636163
"example":33
61646164
},
6165-
"api_key_template": {
6165+
"header_template": {
61666166
"type":"string",
6167-
"description":"Template for theAPI keyheader."
6167+
"description":"Template for the header."
61686168
},
61696169
"version": {
61706170
"type":"string",

‎engine/common/engine_servicei.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ struct EngineVariantResponse {
2525
std::string name;
2626
std::string version;
2727
std::string engine;
28+
std::string type;
2829

2930
Json::ValueToJson()const {
3031
Json::Value root;
3132
root["name"] = name;
3233
root["version"] = version;
3334
root["engine"] = engine;
35+
root["type"] = type.empty() ?"local" : type;
3436
return root;
3537
}
3638
};
@@ -57,7 +59,7 @@ class EngineServiceI {
5759
virtual cpp::result<cortex::db::EngineEntry, std::string>
5860
GetEngineByNameAndVariant(
5961
const std::string& engine_name,
60-
const std::optional<std::string> variant = std::nullopt) =0;
61-
62-
virtualboolIsRemoteEngine(const std::string& engine_name) = 0;
62+
const std::optional<std::string> variant = std::nullopt)const=0;
63+
64+
virtualboolIsRemoteEngine(const std::string& engine_name)const= 0;
6365
};

‎engine/config/model_config.h‎

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@
1111
#include<stdexcept>
1212
#include<string>
1313
#include<vector>
14-
#include"config/remote_template.h"
1514
#include"utils/format_utils.h"
1615
#include"utils/remote_models_utils.h"
1716

1817
namespaceconfig {
1918

2019
structRemoteModelConfig {
2120
std::string model;
22-
std::stringapi_key_template;
21+
std::stringheader_template;
2322
std::string engine;
2423
std::string version;
25-
std::size_t created;
24+
size_t created;
2625
std::string object ="model";
2726
std::string owned_by ="";
2827
Json::Value inference_params;
29-
Json::ValueTransformReq;
30-
Json::ValueTransformResp;
28+
Json::Valuetransform_req;
29+
Json::Valuetransform_resp;
3130
Json::Value metadata;
3231
voidLoadFromJson(const Json::Value& json) {
3332
if (!json.isObject()) {
@@ -36,8 +35,8 @@ struct RemoteModelConfig {
3635

3736
// Load basic string fields
3837
model = json.get("model", model).asString();
39-
api_key_template =
40-
json.get("api_key_template",api_key_template).asString();
38+
header_template =
39+
json.get("header_template",header_template).asString();
4140
engine = json.get("engine", engine).asString();
4241
version = json.get("version", version).asString();
4342
created =
@@ -47,31 +46,8 @@ struct RemoteModelConfig {
4746

4847
// Load JSON object fields directly
4948
inference_params = json.get("inference_params", inference_params);
50-
TransformReq = json.get("TransformReq", TransformReq);
51-
// Use default template if it is empty, currently we only support 2 remote engines
52-
auto is_anthropic = [](const std::string& model) {
53-
return model.find("claude") != std::string::npos;
54-
};
55-
if (TransformReq["chat_completions"]["template"].isNull()) {
56-
if (is_anthropic(model)) {
57-
TransformReq["chat_completions"]["template"] =
58-
kAnthropicTransformReqTemplate;
59-
}else {
60-
TransformReq["chat_completions"]["template"] =
61-
kOpenAITransformReqTemplate;
62-
}
63-
}
64-
TransformResp = json.get("TransformResp", TransformResp);
65-
if (TransformResp["chat_completions"]["template"].isNull()) {
66-
if (is_anthropic(model)) {
67-
TransformResp["chat_completions"]["template"] =
68-
kAnthropicTransformRespTemplate;
69-
}else {
70-
TransformResp["chat_completions"]["template"] =
71-
kOpenAITransformRespTemplate;
72-
}
73-
}
74-
49+
transform_req = json.get("transform_req", transform_req);
50+
transform_resp = json.get("transform_resp", transform_resp);
7551
metadata = json.get("metadata", metadata);
7652
}
7753

@@ -80,7 +56,7 @@ struct RemoteModelConfig {
8056

8157
// Add basic string fields
8258
json["model"] = model;
83-
json["api_key_template"] =api_key_template;
59+
json["header_template"] =header_template;
8460
json["engine"] = engine;
8561
json["version"] = version;
8662
json["created"] =static_cast<Json::UInt64>(created);
@@ -89,8 +65,8 @@ struct RemoteModelConfig {
8965

9066
// Add JSON object fields directly
9167
json["inference_params"] = inference_params;
92-
json["TransformReq"] =TransformReq;
93-
json["TransformResp"] =TransformResp;
68+
json["transform_req"] =transform_req;
69+
json["transform_resp"] =transform_resp;
9470
json["metadata"] = metadata;
9571

9672
return json;
@@ -101,7 +77,7 @@ struct RemoteModelConfig {
10177

10278
// Convert basic fields
10379
root["model"] = model;
104-
root["api_key_template"] =api_key_template;
80+
root["header_template"] =header_template;
10581
root["engine"] = engine;
10682
root["version"] = version;
10783
root["object"] = object;
@@ -111,8 +87,8 @@ struct RemoteModelConfig {
11187
// Convert Json::Value to YAML::Node using utility function
11288
root["inference_params"] =
11389
remote_models_utils::jsonToYaml(inference_params);
114-
root["TransformReq"] =remote_models_utils::jsonToYaml(TransformReq);
115-
root["TransformResp"] =remote_models_utils::jsonToYaml(TransformResp);
90+
root["transform_req"] =remote_models_utils::jsonToYaml(transform_req);
91+
root["transform_resp"] =remote_models_utils::jsonToYaml(transform_resp);
11692
root["metadata"] =remote_models_utils::jsonToYaml(metadata);
11793

11894
// Save to file
@@ -134,7 +110,7 @@ struct RemoteModelConfig {
134110

135111
// Load basic fields
136112
model = root["model"].as<std::string>("");
137-
api_key_template = root["api_key_template"].as<std::string>("");
113+
header_template = root["header_template"].as<std::string>("");
138114
engine = root["engine"].as<std::string>("");
139115
version = root["version"] ? root["version"].as<std::string>() :"";
140116
created = root["created"] ? root["created"].as<std::size_t>() :0;
@@ -144,8 +120,8 @@ struct RemoteModelConfig {
144120
// Load complex fields using utility function
145121
inference_params =
146122
remote_models_utils::yamlToJson(root["inference_params"]);
147-
TransformReq =remote_models_utils::yamlToJson(root["TransformReq"]);
148-
TransformResp =remote_models_utils::yamlToJson(root["TransformResp"]);
123+
transform_req =remote_models_utils::yamlToJson(root["transform_req"]);
124+
transform_resp =remote_models_utils::yamlToJson(root["transform_resp"]);
149125
metadata =remote_models_utils::yamlToJson(root["metadata"]);
150126
}
151127
};

‎engine/config/remote_template.h‎

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp