Skip to content

Commit 43bf80f

Browse files
committed
chore: function calling cleanup
1 parent b901e01 commit 43bf80f

File tree

8 files changed

+213
-330
lines changed

8 files changed

+213
-330
lines changed

docs/docs/guides/function-calling.md

+24-6
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ tools = [
6363

6464
completion_payload = {
6565
"messages": [
66-
{"role": "system", "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user."},
67-
{"role": "user", "content": "Hi, can you tell me the delivery date for my order?"},
66+
{
67+
"role": "system",
68+
"content": 'You have access to the following CUSTOM functions:\n\n<CUSTOM_FUNCTIONS>\n\nIf a you choose to call a function ONLY reply in the following format:\n<{start_tag}={function_name}>{parameters}{end_tag}\nwhere\n\nstart_tag => `<function`\nparameters => a JSON dict with the function argument name as key and function argument value as value.\nend_tag => `</function>`\n\nHere is an example,\n<function=example_function_name>{"example_name": "example_value"}</function>\n\nReminder:\n- Function calls MUST follow the specified format\n- Required parameters MUST be specified\n- You can call one or more functions at a time, but remember only chose correct function\n- Put the entire function call reply on one line\n- Always add your sources when using search results to answer the user query\n- If you can not find correct parameters or arguments corresponding to function in the user\'s message, ask user again to provide, do not make assumptions.\n- No explanation are needed when calling a function.\n\nYou are a helpful assistant.',
69+
},
70+
{
71+
"role": "user",
72+
"content": "Hi, can you tell me the delivery date for my order?"
73+
},
6874
]
6975
}
7076

@@ -126,10 +132,22 @@ Once the user provides their order ID:
126132
```python
127133
completion_payload = {
128134
"messages": [
129-
{"role": "system", "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user."},
130-
{"role": "user", "content": "Hi, can you tell me the delivery date for my order?"},
131-
{"role": "assistant", "content": "Of course! Please provide your order ID so I can look it up."},
132-
{"role": "user", "content": "i think it is order_70705"},
135+
{
136+
"role": "system",
137+
"content": 'You have access to the following CUSTOM functions:\n\n<CUSTOM_FUNCTIONS>\n\nIf a you choose to call a function ONLY reply in the following format:\n<{start_tag}={function_name}>{parameters}{end_tag}\nwhere\n\nstart_tag => `<function`\nparameters => a JSON dict with the function argument name as key and function argument value as value.\nend_tag => `</function>`\n\nHere is an example,\n<function=example_function_name>{"example_name": "example_value"}</function>\n\nReminder:\n- Function calls MUST follow the specified format\n- Required parameters MUST be specified\n- You can call one or more functions at a time, but remember only chose correct function\n- Put the entire function call reply on one line\n- Always add your sources when using search results to answer the user query\n- If you can not find correct parameters or arguments corresponding to function in the user\'s message, ask user again to provide, do not make assumptions.\n- No explanation are needed when calling a function.\n\nYou are a helpful assistant.',
138+
},
139+
{
140+
"role": "user",
141+
"content": "Hi, can you tell me the delivery date for my order?"
142+
},
143+
{
144+
"role": "assistant",
145+
"content": "Of course! Please provide your order ID so I can look it up."
146+
},
147+
{
148+
"role": "user",
149+
"content": "i think it is order_70705"
150+
},
133151
]
134152
}
135153

engine/controllers/server.cc

-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ void server::ProcessStreamRes(std::function<void(const HttpResponsePtr&)> cb,
179179
void server::ProcessNonStreamRes(std::function<void(const HttpResponsePtr&)> cb,
180180
SyncQueue& q) {
181181
auto [status, res] = q.wait_and_pop();
182-
function_calling_utils::PostProcessResponse(res);
183182
LOG_DEBUG << "response: " << res.toStyledString();
184183
auto resp = cortex_utils::CreateCortexHttpJsonResponse(res);
185184
resp->setStatusCode(

engine/extensions/local-engine/local_engine.cc

+1
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ void LocalEngine::LoadModel(std::shared_ptr<Json::Value> json_body,
531531

532532
params.push_back("--pooling");
533533
params.push_back("mean");
534+
params.push_back("--jinja");
534535

535536
std::vector<std::string> v;
536537
v.reserve(params.size() + 1);

engine/services/inference_service.cc

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ cpp::result<void, InferResult> InferenceService::HandleChatCompletion(
1313
engine_type = (*(json_body)).get("engine", kLlamaRepo).asString();
1414
}
1515
CTL_DBG("engine_type: " << engine_type);
16-
function_calling_utils::PreprocessRequest(json_body);
17-
CTL_DBG("engine_type: " << engine_type);
1816
auto tool_choice = json_body->get("tool_choice", Json::Value::null);
1917
auto model_id = json_body->get("model", "").asString();
2018
if (saved_models_.find(model_id) != saved_models_.end()) {

engine/test/components/test_function_calling.cc

-157
This file was deleted.

engine/utils/cli_selection_utils.h

+15-11
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ inline void PrintMenu(
2727

2828
inline std::optional<int> GetNumericValue(const std::string& sval) {
2929
try {
30-
return std::stoi(sval);
30+
return std::stoi(sval);
3131
} catch (const std::invalid_argument&) {
32-
// Not a valid number
33-
return std::nullopt;
32+
// Not a valid number
33+
return std::nullopt;
3434
} catch (const std::out_of_range&) {
35-
// Number out of range
36-
return std::nullopt;
35+
// Number out of range
36+
return std::nullopt;
3737
}
3838
}
3939

@@ -73,14 +73,16 @@ inline std::optional<std::string> PrintModelSelection(
7373
}
7474

7575
// Validate if the selection consists solely of numeric characters
76-
if(!std::all_of(selection.begin(), selection.end(), ::isdigit)){
76+
if (!std::all_of(selection.begin(), selection.end(), ::isdigit)) {
7777
return std::nullopt;
7878
}
7979

8080
// deal with out of range numeric values
8181
std::optional<int> numeric_value = GetNumericValue(selection);
82-
83-
if (!numeric_value.has_value() || (unsigned) numeric_value.value() > availables.size() || numeric_value.value() < 1) {
82+
83+
if (!numeric_value.has_value() ||
84+
(unsigned)numeric_value.value() > availables.size() ||
85+
numeric_value.value() < 1) {
8486
return std::nullopt;
8587
}
8688

@@ -101,13 +103,15 @@ inline std::optional<std::string> PrintSelection(
101103
}
102104

103105
// Validate if the selection consists solely of numeric characters
104-
if(!std::all_of(selection.begin(), selection.end(), ::isdigit)){
106+
if (!std::all_of(selection.begin(), selection.end(), ::isdigit)) {
105107
return std::nullopt;
106108
}
107-
109+
108110
// deal with out of range numeric values
109111
std::optional<int> numeric_value = GetNumericValue(selection);
110-
if (!numeric_value.has_value() ||(unsigned) numeric_value.value() > options.size() || numeric_value.value() < 1) {
112+
if (!numeric_value.has_value() ||
113+
(unsigned)numeric_value.value() > options.size() ||
114+
numeric_value.value() < 1) {
111115
return std::nullopt;
112116
}
113117

0 commit comments

Comments
 (0)