Kendamarron/jimba-instruction-all
Viewer • Updated • 42.4k • 101
How to use SousiOmine/sarashina2.2-3b-instruct-v0.1-Pythonic-FunctionCall with Unsloth Studio:
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for SousiOmine/sarashina2.2-3b-instruct-v0.1-Pythonic-FunctionCall to start chatting
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for SousiOmine/sarashina2.2-3b-instruct-v0.1-Pythonic-FunctionCall to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for SousiOmine/sarashina2.2-3b-instruct-v0.1-Pythonic-FunctionCall to start chatting
pip install unsloth
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="SousiOmine/sarashina2.2-3b-instruct-v0.1-Pythonic-FunctionCall",
max_seq_length=2048,
)https://qiita.com/SousiOmine/items/23313089c7c3f498996b
sbintuitions/sarashina2.2-3b-instruct-v0.1に、 Kendamarron/jimba-instruction-allとSousiOmine/Japanese-Pythonic-FunctionCallを用いたQLoRAファインチューニングを行い、 python関数の呼び出しに対応させたモデルです。
system_tool_format = """{}
#ツール
ユーザーの要望達成を支援するために、1つ以上のpython関数を呼び出すことができます。
呼び出せるpythonの関数を<tools></tools>タグ内に記します。
<tools>
{}
</tools>
関数を呼び出すには、以下のように関数名と引数を<tool_call></tool_call>タグ内に記述してください。
<tool_call>
function_name(param1=value1, param2=value2)
</tool_call>
"""
# お好きなシステムプロンプトをどうぞ
system = "あなたは役に立つアシスタントです。"
# ツールはdocstring付きで文字で書いてね
tools = """def perform_web_search(query: str) -> list:
\"\"\"
ウェブ検索を実行します。
Args:
query (str): 検索クエリ。例: "東京の天気"
Returns:
list: 検索結果のリスト。各要素はウェブページのタイトルとURLです。
\"\"\"
pass
def get_weather(city: str) -> dict:
\"\"\"
指定した都市の現在の天気情報を取得します。
Args:
city (str): 天気を確認したい都市の名前。例: "東京"
Returns:
dict: 天気情報の辞書。{'temperature': 20.5, 'condition': 'Cloudy', 'humidity': 72}
\"\"\"
pass
def execute_script(script: str) -> str:
\"\"\"
ユーザから受け取ったスクリプトまたはコマンドを実行します。
Args:
script (str): 実行したいコマンドまたはスクリプト。例: "ls -la"
Returns:
str: 実行結果の出力またはエラーメッセージ。
\"\"\"
pass
"""
prompt = "今日のAIニュースと埼玉の天気を教えて"
chat = [
{"role": "system", "content": system_tool_format.format(system, tools)},
{"role": "user", "content": prompt},
]
# Unslothのサンプルから持ってきました チャットテンプレート適用してやればほかのでいけるはず
input = tokenizer.apply_chat_template(chat, tokenize = False, add_generation_prompt = True)
#print(input)
FastLanguageModel.for_inference(model)
inputs = tokenizer(
[
input
], return_tensors = "pt").to("cuda")
from transformers import TextStreamer
text_streamer = TextStreamer(tokenizer)
_ = model.generate(**inputs, streamer = text_streamer, temperature=0.7, max_new_tokens = 1024)
# 応答の例
# <|assistant|><tool_call>perform_web_search(query="AI ニュース"), get_weather(city="埼玉")</tool_call></s>
# 戻り値はこんな感じで渡してあげてください
# chat.append({"role": "user", "content": "<tool_response>戻り値はまとめてここに</tool_response>"})
Base model
sbintuitions/sarashina2.2-3b