Function calling に対応したLlama API(llama2)
OpenAI互換のAPIでllama2モデルをホストする、LLamaAPIが公開されていたので、さっそく試してみました。
Llama API のページでユーザー登録してAPIキーを取得します。
OpenAIのFunction Callingのサンプルを入力してみます。
!pip install llamaapi -q
from llamaapi import LlamaAPI
# Replace 'Your_API_Token' with your actual API token
llama = LlamaAPI(`取得したAPI KEY')
import json
schema ={
"messages": [
{"role": "user", "content": "What is the weather like in Boston?"}
],
"functions": [
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
]
}
実行!
response = llama.run(schema)
response.json()['choices'][0]
いい感じです。
おそらく、近いうちにLangChainのAgentなども対応してくれそうです。
また、せっかくllama2なので、今後、ローカル環境でも動くFunction Calling対応のAPIの登場にも期待したいですね。
お読みいただきありがとうございました。