Merge pull request #104 from streetycat/MVP
Adapt to the function of llama.cpp
This commit is contained in:
@@ -116,9 +116,24 @@ class LocalLlama_ComputeNode(Queue_ComputeNode):
|
|||||||
|
|
||||||
body = {
|
body = {
|
||||||
"messages": [],
|
"messages": [],
|
||||||
|
"functions": llm_inner_functions,
|
||||||
|
"tools": [],
|
||||||
|
"tool_choices": [],
|
||||||
"max_tokens": 4000
|
"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:
|
for prompt in prompts:
|
||||||
body["messages"].append({
|
body["messages"].append({
|
||||||
"role": prompt["role"],
|
"role": prompt["role"],
|
||||||
@@ -126,6 +141,8 @@ class LocalLlama_ComputeNode(Queue_ComputeNode):
|
|||||||
})
|
})
|
||||||
|
|
||||||
try:
|
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 = requests.post(self.url + "/v1/chat/completions", json = body, verify=False, headers={"Content-Type": "application/json"})
|
||||||
response.close()
|
response.close()
|
||||||
|
|
||||||
@@ -138,8 +155,12 @@ class LocalLlama_ComputeNode(Queue_ComputeNode):
|
|||||||
token_usage = resp["usage"]
|
token_usage = resp["usage"]
|
||||||
|
|
||||||
match status_code:
|
match status_code:
|
||||||
case "function_call":
|
case "tool_calls":
|
||||||
task.state = ComputeTaskState.DONE
|
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":
|
case "stop":
|
||||||
task.state = ComputeTaskState.DONE
|
task.state = ComputeTaskState.DONE
|
||||||
case _:
|
case _:
|
||||||
|
|||||||
Reference in New Issue
Block a user