
사용자: “지금 성동구 날씨 어때?”
LLM:
get_current_weather(location: string, unit: ‘celsius’ | ‘fahrenheit’)LLM: 성동구 날씨는 맑음입니다!
사용자: 이 위키피디아 문서에서 ‘사람 이름’ 추출해줘
LLM: 홍길동 <|sep|> 김정은 <|sep|> 루이 암스트롱
LLM:
transform_extracted_tokens_to_data(llm_response: string, separator: ‘<|sep|>’)LLM:
추출_인물_데이터.csv제공
사용자: ‘일론 머스크’에 대해 설명해줘
LLM:
find_db(entity: string)LLM:
find_info(database: db, entity: string)LLM: 일론 머스크는 미국의 미치광이 과학자이자 정신 나간 기업가로..
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("meetkai/functionary-small-v3.2")
model = AutoModelForCausalLM.from_pretrained("meetkai/functionary-small-v3.2", device_map="auto", trust_remote_code=True)
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
},
"required": ["location"]
}
}
}
]
messages = [{"role": "user", "content": "What is the weather in Istanbul and Singapore respectively?"}]
final_prompt = tokenizer.apply_chat_template(messages, tools, add_generation_prompt=True, tokenize=False)
inputs = tokenizer(final_prompt, return_tensors="pt").to("cuda")
pred = model.generate_tool_use(**inputs, max_new_tokens=128, tokenizer=tokenizer)
print(tokenizer.decode(pred.cpu()[0]))tokenizer.apply_chat_template에 tools 템플릿을 적용한 final_prompt의 형태는 다음과 같이 구성됨<|start_header_id|>system<|end_header_id|>
You are capable of executing available function(s) if required.
Only execute function(s) when absolutely necessary.
Ask for the required input to:recipient==all
Use JSON for function arguments.
Respond in this format:
>>>${recipient}
${content}
Available functions:
// Supported function definitions that should be called when necessary.
namespace functions {
// Get the current weather
type get_current_weather = (_: {
// The city and state, e.g. San Francisco, CA
location: string,
}) => any;
} // namespace functions<|eot_id|><|start_header_id|>user<|end_header_id|>
What is the weather for Istanbul?