Adapt to the function of llama.cpp

This commit is contained in:
streetycat
2023-11-29 07:46:07 +00:00
committed by zhangzhen
parent 6b8453a2e4
commit 6a00d09701
+22 -1
View File
@@ -116,9 +116,24 @@ class LocalLlama_ComputeNode(Queue_ComputeNode):
body = {
"messages": [],
"functions": llm_inner_functions,
"tools": [],
"tool_choices": [],
"max_tokens": 4000
}
for fun in llm_inner_functions:
body["tools"].append({
"type": "function",
"function": fun,
})
body["tool_choices"].append({
"type": "function",
"function": {
"name": fun["name"]
}
})
for prompt in prompts:
body["messages"].append({
"role": prompt["role"],
@@ -126,6 +141,8 @@ class LocalLlama_ComputeNode(Queue_ComputeNode):
})
try:
logger.info(f"will post http request to {self.url}/v1/chat/completions, body: {body}")
response = requests.post(self.url + "/v1/chat/completions", json = body, verify=False, headers={"Content-Type": "application/json"})
response.close()
@@ -138,8 +155,12 @@ class LocalLlama_ComputeNode(Queue_ComputeNode):
token_usage = resp["usage"]
match status_code:
case "function_call":
case "tool_calls":
task.state = ComputeTaskState.DONE
# rebuild the function name
fun_name = resp["choices"][0]["message"]["function_call"]["name"]
if len(llm_inner_functions) == 1 and (fun_name is None or fun_name == ""):
resp["choices"][0]["message"]["function_call"]["name"] = llm_inner_functions[0]["name"]
case "stop":
task.state = ComputeTaskState.DONE
case _: