この記事は機械翻訳のミラー記事です。元の記事にジャンプするにはこちらをクリックしてください。

眺める: 1326|答える: 3

[出典] [AI] (16) セマンティックカーネルはQwenに基づいて関数呼び出しをテストしています

[リンクをコピー]
2025年3月26日 17:46:52 に投稿 | | | |
要件:大規模モデルを使ってリアルタイム情報(現在の時刻、今日の天気、チェック・エクスプレス・デリバリーなど)を取得したり、大規模モデルでビジネスデータを分析したりする場合は、関数呼び出し機能を使う必要があります。 インターネット上の多くの記事は関数呼び出しについて非常に曖昧で明確に説明していませんが、私はリクエスト情報に基づいてこの関数を理解しています。

まずレンダリングを見て、大きなモデルを使おう現在の時刻、上海の天気、そしてパソコンの起動を助けてくれた電卓を手に入れました、下図に示されているように:



OpenAIインターフェースドキュメント:ハイパーリンクのログインが見えます。、下図に示されているように:



関数呼び出し

大規模モデルはリアルタイムの問題や数学的計算、その他の問題に直面する際には効果的でない場合があります。 関数呼び出し機能を使って、外部ツールを導入することで大型モデルが外部とやり取りできるようにできます。

ファンクションコールは、大規模モデルを外部ツールやAPIとつなげ、大規模なモデルが実際の産業実装へと移行するのを支援する新しい機能です。 ファンクションコールにより、開発者は複雑なプロンプトを入力することなく、モデルからより信頼性の高い構造化データを取得できます。

この方法を使うと、関数群の定義を自然言語でモデルに記述できます。 会話中、大規模モデルが関数の使用が必要だと判断した場合、賢くその機能を選択し、ユーザーの特定のニーズを満たすためのパラメータを呼び戻します。 他の場合、大規模モデルは関数を返さず、会話を続けます。 大規模モデルは関数を直接呼び出すのではなく、対応する入力パラメータを返すため、関数やAPIインターフェースを自分で呼び出すことができます。

簡単に言えば、ファンクションコールは自然言語と情報インターフェースの間の「翻訳者」です

自然言語を必要な関数やパラメータに変換し、それを大規模なモデル呼び出し元に返します
大規模モデル呼び出し者が関数を実行すると、その結果は大規模モデルに戻され、大規模モデルは自然言語に要約されたり、サブタスクの計画を継続したりできます

ワークフロー図は以下の通りです:



セマンティックカーネル

セマンティックカーネルは軽量でオープンソースの開発キットで、AIエージェントを簡単に生成し、最新のAIモデルをC#、Python、またはJavaのコードベースに統合できます。 効率的なミドルウェアとして機能し、エンタープライズレベルのソリューションを迅速に提供します。

ドキュメンテーション:ハイパーリンクのログインが見えます。
源:ハイパーリンクのログインが見えます。

C#はAlibaba Cloud Tongyi Qianwenを呼び出して関数呼び出しを実行します

以下の参照で新しい.NET 8コンソールプロジェクトを作成しましょう:

コードは以下の通りです:

最初にレンダリングしているプログラムを実行し、現在の時刻と上海の天気を確認してから計算機を開きます。

実行ログ:

=============================================================================
Request:
Method: POST
Uri: ハイパーリンクのログインが見えます。
リクエストコンテンツ: {"tools":[{"function":{"description":"時間を知るのに非常に役立ちます。" ,"name":"itsvse-get_current_time","strict":false,"parameters":{"type":"object","required":[],"properties":{}}},"type":"function"},{"function":{"description":" これは、今日ある都市の天気を確認したいときに便利です。 ","name":"itsvse-get_current_weather","strict":false,"parameters":{"type":"object","required":["location"],"properties":{"location":{"description":":北京、上海など、 杭州市、玉航区など。 ","type":"string"}}}},"type":"function"},{"function":{"description":"これは指定されたExpress物流情報をクエリしたいときに非常に役立ちます。" ","name":"itsvse-get_current_test","strict":false,"parameters":{"type":"object","required":["no"],"properties":{"no":{"description":"宅配便の追跡番号(例:SF、ZTO、郵便宅配便の追跡番号)は許容可能です。" ","type":"string"}}}},"type":"function"},{"function":{"description":"計算機を開けたいときにとても便利です。" ,"name":"itsvse-open_calculator","strict":false,"parameters":{"type":"object","required":[],"properties":{}}},"type":function"}],"messages":[{"role":"user","content" 「こんにちは、上海の現在の時刻と今日の天気を確認するのを手伝ってください。」 じゃあ、打刻計算機を手伝ってくれ。今日の収入を計算したいんだ。 "}],"model":"qwen-max","tool_choice":"auto","parallel_tool_calls":true}
Response:
ステータスコード:OK
Body: {"choices":[{"message":{"content":"","role":"assistant","tool_calls":[{"function":{"name":"itsvse-get_current_time","arguments":"{}"},"index":0,"id":"call_6e6cade782f54c9ca87186","type":"function"},{"function":{"name":"itsvse-get_current_weather","arguments":"{\"location\": \"上海市\"}"},"index":1,"id":"call_cc957be34f5741f4b2a969","type":"function"},{"function":{"name":"itsvse-open_calculator","arguments":"{}"},"index":2,"id":"call_6023df74d7bd48c789e876","type":"function"}]},"finish_reason":"tool_calls","index":0,"logprobs":null}],"object":"chat.completion","usage":{"prompt_tokens":500,"completion_tokens":53,"total_tokens":553,"prompt_tokens_details":{"cached_tokens":256}},"created":1742980780,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-1761acb9-717a-997c-9f17-7284e82fd121"}
=============================================================================
-----------------------時間を得る方法と呼びます-----------------------
----------------------------------------------------------------
-----------------------天気を知る方法と呼ぶのです-----------------------
パラメータ:上海
----------------------------------------------------------------
----------------------- コンピューターの電卓を開けて-----------------------
=============================================================================
Request:
Method: POST
Uri: ハイパーリンクのログインが見えます。
リクエストコンテンツ: {"tools":[{"function":{"description":"時間を知るのに非常に役立ちます。" ,"name":"itsvse-get_current_time","strict":false,"parameters":{"type":"object","required":[],"properties":{}}},"type":"function"},{"function":{"description":" これは、今日ある都市の天気を確認したいときに便利です。 ","name":"itsvse-get_current_weather","strict":false,"parameters":{"type":"object","required":["location"],"properties":{"location":{"description":":北京、上海など、 杭州市、玉航区など。 ","type":"string"}}}},"type":"function"},{"function":{"description":"これは指定されたExpress物流情報をクエリしたいときに非常に役立ちます。" ","name":"itsvse-get_current_test","strict":false,"parameters":{"type":"object","required":["no"],"properties":{"no":{"description":"宅配便の追跡番号(例:SF、ZTO、郵便宅配便の追跡番号)は許容可能です。" ","type":"string"}}}},"type":"function"},{"function":{"description":"計算機を開けたいときにとても便利です。" ,"name":"itsvse-open_calculator","strict":false,"parameters":{"type":"object","required":[],"properties":{}}},"type":function"}],"messages":[{"role":"user","content" 「こんにちは、上海の現在の時刻と今日の天気を確認するのを手伝ってください。」 じゃあ、打刻計算機を手伝ってくれ。今日の収入を計算したいんだ。 "},{"role":"assistant","content":"","tool_calls":[{"id":"call_6e6cade782f54c9ca87186","function":{"name":"itsvse-get_current_time","arguments":"{}"},"type":"function" ","index":0},{"id":"call_cc957be34f5741f4b2a969","function":{"name":"itsvse-get_current_weather","arguments":"{\"location\": \"Shanghai\"}"},"type":"function","index":1},{" id":"call_6023df74d7bd48c789e876","function":{"name":"itsvse-open_calculator","arguments":"{}"},"type":"function","index":2}]},{"role":"tool","tool_call_id":"call_ 6e6cade782f54c9ca87186","content":"2025/3/26 17:19:40"},{"role":tool","tool_call_id":"call_cc957be34f5741f4b2a969","content":"上海の気象条件は以下の通りです:曇りと雷雨、気温は10°Cから20°Cの間で",{" role":tool","tool_call_id":"call_6023df74d7bd48c789e876","content":計算機が開かれた。 }],"model":"qwen-max","tool_choice":"auto","parallel_tool_calls":true}
Response:
ステータスコード:OK
Body: {"choices":[{"message":{"content":"现在的时间是2025年3月26日17点19分40秒。\n\n今天上海市的天气情况如下:多云转雷阵雨,气温介于10°C到20°C之间,请记得带伞哦。\n\n我已经 帮你打开了计算器,你可以开始计算今天的收入了。","role":"assistant"},"finish_reason":"stop","index":0,"logprobs":null}],"object":"chat.completion","usage":{"prompt_tokens":621,"completion_tokens":70,"total_tokens":691,"prompt_tokens_details":{"cached_tokens":0}},"created":1742980783,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-b0bd149e-3f5b-9a53-91d7-7bb26487d822"}
=============================================================================
アシスタント>は現在2025年3月26日17時19分40秒です。

本日の上海の天候状況は以下の通りです:曇りから雷雨、気温は10°Cから20°Cの間で、傘を持参することを忘れないでください。

計算機を開いておいたので、今日から収入の計算を始めてください。

参考:

ハイパーリンクのログインが見えます。
ハイパーリンクのログインが見えます。
ハイパーリンクのログインが見えます。
ハイパーリンクのログインが見えます。
ハイパーリンクのログインが見えます。

スコア

参加者数1MB+1 倒れる 理由
グッドタイム + 1 オーナーが良い投稿をするのを応援してください。私も良い投稿をします!

すべての評価を見る





先の:toPlainString, toEngineeringString, toString for BigDecimal in Java
次に:.NET/C#の親子プロセスは標準的な入出力ストリームを使って通信します
 地主| 2025年3月27日 08:59:23に投稿 |
マルチターン会話コード:


開始されたリクエストの情報は以下の通りです:



 地主| 2025年3月27日 08:58:04に投稿 |
ストリーミング作品について

ストリームモードでもこのルールtool_calls適用されますが、以下に挙げるような追加のポイントがあります。

ストリーミング出力中は、最終チャンクに現れるfinish_reasonため、delta.tool_callsフィールドの有無を用いて現在の返信にツールコールが含まれているかどうかを判断することが推奨されます。
ストリーミング出力中はまずdelta.contentが出力され、その後delta.tool_callsが出されるため、delta.contentの出力が完了するまで判断・識別tool_callsなければなりません。
ストリーミング出力の過程で、最初のデータブロックで現在の呼び出しtool_callsのtool_call.idとtool_call.function.nameを指定し、その後のデータブロックで出力されるのはtool_call.function.argumentsのみです。
ストリーミング出力プロセス中に、Kimiモデルが同時に複数のtool_callsを返す場合、indexという追加フィールドを使って現在のtool_callインデックスを特定し、tool_call.function.argumentsパラメータを正しくスティッチできるようにします。

ハイパーリンクのログインが見えます。

ストリーミング応答の例は以下の通りです:

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"name":"itsvse-get_current_time","arguments":""},"index":0,"id":"call_deb0063d315441b18b50d8","type":"function"}],"role":"assistant"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"arguments":"{}"},"index":0,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":0,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":0,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":0,"id":"","type":"function"},{"function":{"name":"itsvse-get_current_weather","arguments":""},"index":1,"id":"call_9790fb45e2b7419097d578","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"arguments":"{\"location\": \""},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{"arguments":"上海市\"}"},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"content":null,"tool_calls":[{"function":{},"index":1,"id":"","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"delta":{"tool_calls":[{"function":{"arguments":null},"index":1,"id":"","type":"function"},{"function":{"arguments":"{}","name":"itsvse-open_calculator"},"index":2,"id":"call_3ad6478075f04021ab9ea1","type":"function"}]},"index":0}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[{"finish_reason":"tool_calls","delta":{},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":500,"completion_tokens":53,"total_tokens":553,"prompt_tokens_details":{"cached_tokens":0}},"created":1743037194,"system_fingerprint":null,"model":"qwen-max","id":"chatcmpl-c4e2a989-10a3-9604-bdae-0b58b4f876a7"}

data: [DONE]


 地主| 2025年10月22日 11:30:02に投稿 |
MCP(1) モデルコンテキストプロトコル入門チュートリアル
https://www.itsvse.com/thread-11104-1-1.html
免責事項:
Code Farmer Networkが発行するすべてのソフトウェア、プログラミング資料、記事は学習および研究目的のみを目的としています。 上記の内容は商業的または違法な目的で使用されてはならず、そうでなければ利用者はすべての結果を負うことになります。 このサイトの情報はインターネットからのものであり、著作権紛争はこのサイトとは関係ありません。 ダウンロード後24時間以内に上記の内容を完全にパソコンから削除してください。 もしこのプログラムを気に入ったら、正規のソフトウェアを支持し、登録を購入し、より良い本物のサービスを受けてください。 もし侵害があれば、メールでご連絡ください。

Mail To:help@itsvse.com