1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Groq tool api

Last updated at Posted at 2024-07-28

chatgtp tools というAPIがある。
これと同じことがGroqでも出来る。

まとめ

モデルは、Llama 3 Groq 70B Tool Use がいい。(英語だけど)
特別仕様(Causal language model fine-tuned for tool use)なだけに、マルチでtoolを呼び出すなどツール処理に優れる。

Llama 3.1 70B も悪くないけど、同時に複数のtoolは呼ばない事が多い。

tool_choice で 最初の質問時には、required と 最後のときはnoneとして、tool呼び出しを管理すると、察しが悪いLLMでもうまくtool処理が出来る。

Llama 3 Groq 8B Tool Use でも、そこそこ処理してくれる。

流れ

公式ドキュメント読んで(Handling Tool Resultsは何か違う)
https://console.groq.com/docs/tool-use

公式サンプルを見るとわかりやすい。(受け取ったtool処理をどう返すか)
https://github.com/groq/groq-api-cookbook/blob/main/parallel-tool-use/parallel-tool-use.ipynb

1 最初に質問する

System Prompt

You are a calculator assistant. Use the calculate function to perform mathematical operations and provide the results.

User Prompt 計算問題を出してみる

A= 25 * 4 + 10
B= 10 * 3 + 60
which one is bigger?

LLMからの返答

function 使って計算してくださいとmessageでお願いが来る。複数のこともある

[
{ "id": "call_6fcw", "type": "function", "function": { "name": "calculate", "arguments": "{\"expression\": \"25 * 4 + 10\"}" } }, 
{ "id": "call_3jqb", "type": "function", "function": { "name": "calculate", "arguments": "{\"expression\": \"10 * 3 + 60\"}" } }
]

ユーザーはfunctionを使った結果を返す。

もちろん普通のチャットの時と同様に、最初のsystem promptとuser prompt、返ってきたLLMからのmessageも先に含めて。複数になるので、こっちの返信は、一つづつ処理して返す

{"content":"110","role":"tool","tool_call_id":"call_6fcw"},{"content":"90","role":"tool","tool_call_id":"call_3jqb"}

LLMがこれを受け取った結果から、最初の質問に答えてくれます。

ただ、LLMによっては、一度に複数の質問がうまくできず、ここで再度質問してくることもある。

A is bigger than B
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?