- Issue created by @marcus_johansson
- 🇩🇪Germany marcus_johansson
So the current version of this is good if you just need "user" and "assistant" interaction, but there are two I think important things missing for us to be able to replicate what exists on platform.openai.com (or used to).
That is:
1. Is that when you get a tool usage response back, that information is in a separate place in the response, so that should be possible to replicate with tool call id, function name and function input. Even if that is for now just an array of those three things as strings. See https://platform.openai.com/docs/guides/function-calling#handling-functi... (in this case called id, name, arguments)
2. The next step is also that you can set a tool response. So that is the response that you give back after you have run the execute on your Drupal machine. This is unique because it has to add the tool call id referenced from the decision. The role is already added, but adding the tool call id should be based on if the tool role is "tool".
3. A test would be nice on top of that.
4. Developer documentation as well.
- 🇮🇳India abhisekmazumdar India
I got the gist of it and will give it a try
My understanding is this chat_history FormElement will need the following changes next:- A existing / new section of assistant is created it should have the following as string as of now
- tool_call_id
- function_name
- function_input
- And for tool add a field tool_call_id_reference.
- 🇩🇪Germany marcus_johansson
That is almost correct, the minor thing is that it should be an array of
- tool_call_id
- function_name
- funtion_input
So it needs a way to add more, add less for a complex object. I think that makes sense to set to #tree=true then as well, but you could test that.
- 🇮🇳India abhisekmazumdar India
I made the update to the Draft changes: https://git.drupalcode.org/project/ai/-/merge_requests/719/diffs?commit_...
This includes added Tool call section for the Role Assistant which has the above said fields.
And Role Tool has a tool called Reference IDExample use of the element:
$form['conversation'] = [ '#type' => 'chat_history', '#title' => $this->t('Conversation'), '#default_value' => [ [ 'role' => 'user', 'content' => 'What is the weather like?' ], [ 'role' => 'assistant', 'content' => 'I can check that for you.', 'tool_calls' => [ [ 'tool_call_id' => 'call_1', 'function_name' => 'get_weather', 'function_input' => '{"location":"Oslo","unit":"celsius"}', ], ], ], [ 'role' => 'tool', 'content' => '{"temp":25,"condition":"sunny"}', 'tool_call_id_reference' => 'call_1' ], [ 'role' => 'user', 'content' => 'Can you also check the time?' ], ], '#chat_history_add_more' => TRUE, '#rows' => 2, ];
preview:
Sharing my work in progress here to ensure I'm heading in the right direction.
- 🇮🇳India abhisekmazumdar India
I have made the final changes, added the document and test. I also made some changes to the CSS and cleaned up the other parts of the code. This is now up for review.
Example usage:
$form['conversation'] = [ '#type' => 'chat_history', '#title' => $this->t('Conversation'), '#default_value' => [ [ 'role' => 'user', 'content' => 'What is the weather like?' ], [ 'role' => 'assistant', 'content' => 'I can check that for you.', 'tool_calls' => [ [ 'tool_call_id' => 'call_1', 'function_name' => 'get_weather', 'function_input' => '{"location":"Oslo","unit":"celsius"}', ], ], ], [ 'role' => 'tool', 'content' => '{"temp":25,"condition":"sunny"}', 'tool_call_id_reference' => 'call_1' ], ], ];
- 🇩🇪Germany marcus_johansson
Thanks, tested, code reviewed - looks great. I added one linkage to the mkdocs file, so the documentation shows up on https://project.pages.drupalcode.org/ai/1.2.x/
Now that this issue is closed, please review the contribution record.
As a contributor, attribute any organization helped you, or if you volunteered your own time.
Maintainers, please credit people who helped resolve this issue.
-
marcus_johansson →
committed 3aa06c21 on 1.2.x
Resolve #3528948 "Add chathistory form"
-
marcus_johansson →
committed 3aa06c21 on 1.2.x