Skip to content

Commit 66a2a0d

Browse files
committed
updated readme, fix function call postprocess
1 parent bf13242 commit 66a2a0d

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
1-
# llama.cpp
1+
# tools.cpp
22

3-
![llama](https://user-images.githubusercontent.com/1991296/230134379-7181e485-c521-4d23-a0d6-f7b3b61ba524.png)
3+
### tools.cpp quickstart
4+
1. build from source:
5+
Mac user
6+
```
7+
make
8+
```
49

5-
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6-
[![Server](https://github.com/ggerganov/llama.cpp/actions/workflows/server.yml/badge.svg?branch=master&event=schedule)](https://github.com/ggerganov/llama.cpp/actions/workflows/server.yml)
7-
[![Conan Center](https://shields.io/conan/v/llama-cpp)](https://conan.io/center/llama-cpp)
10+
Nvidia-Cuda user:
11+
```
12+
make LLAMA_CUDA=1
13+
```
814

9-
[Roadmap](https://github.com/users/ggerganov/projects/7) / [Project status](https://github.com/ggerganov/llama.cpp/discussions/3471) / [Manifesto](https://github.com/ggerganov/llama.cpp/discussions/205) / [ggml](https://github.com/ggerganov/ggml)
15+
2. Install helper package:
16+
```
17+
npm install jsonrepair
18+
```
1019

11-
Inference of Meta's [LLaMA](https://arxiv.org/abs/2302.13971) model (and others) in pure C/C++
20+
3. Download a compatible gguf model:
21+
For example:
22+
```
23+
wget https://huggingface.co/sanjay920/Llama-3-8b-function-calling-alpha-v1.gguf/resolve/main/Llama-3-8b-function-calling-alpha-v1.gguf
24+
```
1225

13-
> [!IMPORTANT]
14-
[2024 Jun 12] Binaries have been renamed w/ a `llama-` prefix. `main` is now `llama-cli`, `server` is `llama-server`, etc (https://github.com/ggerganov/llama.cpp/pull/7809)
26+
4. start server:
27+
```
28+
./llama-server -ngl 35 -m Llama-3-8b-function-calling-alpha-v1.gguf --port 1234 --host 0.0.0.0 -c 16000 --chat-template llama3
29+
```
1530

1631
### Recent API changes
1732

examples/server/function-call-parser.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ json clean_json_strings(const std::string& input_str) {
6868
// json repair here
6969
std::string fixed_str = jsonrepair(input_str);
7070
json data = json::parse(fixed_str);
71-
7271
for (auto& [key, value] : data.items()) {
7372
if (value.is_string()) {
7473
std::string val = value.get<std::string>();
@@ -82,6 +81,7 @@ json clean_json_strings(const std::string& input_str) {
8281
if (v.is_string()) {
8382
v = clean_command_string(v.get<std::string>());
8483
}
84+
8585
}
8686
}
8787
}
@@ -97,7 +97,7 @@ json clean_json_strings(const std::string& input_str) {
9797

9898
std::vector<json> rubra_fc_json_tool_extractor(const std::string& output_str) {
9999
std::vector<json> result;
100-
printf("OUTPUT STR TO BE PARSED : %s", output_str.c_str());
100+
printf("OUTPUT STR TO BE PARSED : %s\n", output_str.c_str());
101101
if (output_str.find("endtoolcall") == std::string::npos) {
102102
return result;
103103
}
@@ -111,7 +111,8 @@ std::vector<json> rubra_fc_json_tool_extractor(const std::string& output_str) {
111111
size_t pos = segment.find("starttoolcall");
112112
if (pos != std::string::npos) {
113113
// Extract substring after "toolcall"
114-
listOfStrToParse.push_back(segment.substr(pos + std::string("starttoolcall").length()));
114+
std::string ss = segment.substr(pos + std::string("starttoolcall").length());
115+
listOfStrToParse.push_back(ss);
115116
}
116117
start = end + std::string("endtoolcall").length(); // Move past the "endtoolcall"
117118
}
@@ -121,9 +122,10 @@ std::vector<json> rubra_fc_json_tool_extractor(const std::string& output_str) {
121122
try {
122123
for (const auto & line : listOfStrToParse) {
123124
// json fc = json::parse(line);
125+
124126
json fc = clean_json_strings(line);
125-
if (fc["arguments"].is_string()) {
126-
fc["arguments"] = json::parse(fc["arguments"].get<std::string>());
127+
if (!fc["arguments"].is_string()) {
128+
fc["arguments"] = fc["arguments"].dump();
127129
}
128130
if (!fc.is_null()) {
129131
function_call_json.push_back(fc);

examples/server/utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static json format_final_response_oaicompat(const json & request, json result, c
474474

475475
tool_call["function"] = json{
476476
{"name" , pc["name"]},
477-
{"arguments" , pc["kwargs"].dump()},
477+
{"arguments" , pc["kwargs"]},
478478
};
479479
oai_format_tool_calls.push_back(tool_call);
480480
}

0 commit comments

Comments
 (0)