Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-action renderConversationForModel with cli #4963

Merged
merged 8 commits into from
May 6, 2024

Conversation

PopDaph
Copy link
Contributor

@PopDaph PopDaph commented May 3, 2024

Description

Implements a renderConversationForModelMultiActions. Not called yet from getNextAction.
For convenience it's implemented with a simple cli command.

./admin/cli.sh conversation render-for-model --wId=7ea8c3d99c --cId=b0050ddc00

Result:

{
 "modelConversation": {
      "messages": [
        {
          "role": "user",
          "name": "Daphné Popin",
          "content": "\n@dust is Soupinou cute?"
        },
        {
          "role": "assistant",
          "content": null,
          "function_call": {
            "id": "81",
            "type": "function",
            "function": {
              "name": "search_data_sources",
              "arguments": "{\"query\":\"Soupinou cute\",\"relativeTimeFrame\":\"all\",\"topK\":32}"
            }
          }
        },
        {
          "role": "function",
          "function_call_id": "81",
          "content": "TITLE: team_office-thread-2024-04-12_07h56 (data source: slack)\nREFERENCE: j1\nEXTRACTS:\n$title: Thread in #team_office: I have to leave at 5pm today (and I just arrived at the office), Soupinou is sic..."
        },
        {
          "role": "assistant",
          "name": "dust",
          "content": "Yes, Soupinou is considered cute. In a Slack thread, you referred to Soupinou as \"the cutest cat in the world\" :cite[b5]."
        }
      ]
    }
    "tokensUsed": 13124
}

Risk

Not called from the product yet so not risky and rollbackable.

Deploy Plan

Deploy front.

Copy link
Contributor

@spolu spolu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why tool everywhere? 😬

front/lib/api/assistant/actions/dust_app_run.ts Outdated Show resolved Hide resolved
front/lib/api/assistant/actions/dust_app_run.ts Outdated Show resolved Hide resolved
types/src/front/lib/api/assistant/generation.ts Outdated Show resolved Hide resolved
@@ -12,6 +12,53 @@ export type ModelConversationType = {
messages: ModelMessageType[];
};

export type ContentFragmentMessageTypeModel = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We likely want to get rid of this type entirely and either render that as a fake agent message with function call + response function message or a user message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide to have function call + reponse it could look like that:

{
  "role": "assistant",
  "content": null,
  "functionCalls": [
    {
      "id": "81",
      "type": "function",
      "function": {
        "name": "retrieve_content",
        "arguments": "{\"content_type\":\"slack_thread_content\"}" // or file_attachment
      }
    }
  ]
},
{
  "role": "tool",
  "toolCallId": "81",
  "content": "Content from the fragment"
}

Or if we decide it's a user message:

{
  "role": "user",
  "name": "get_slack_thread_content", // or get_file_attachment
  "content": "Content from the fragment"
},

=> Since some provider are erroring when a convo starts with an agent message cf https://github.com/dust-tt/tasks/issues/699, I will add a commit to set it as a user message. Let me know if you think otherwise!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other providers won’t allow having two user messages in a row I believe 🙃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure there’s a great solution here 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task created to handle it from Core: #4967

@PopDaph
Copy link
Contributor Author

PopDaph commented May 3, 2024

Why tool everywhere? 😬

Because I understood we wanted to align on the new name and specs from #4931 but I'll add a commit to change 👍🏻

@spolu
Copy link
Contributor

spolu commented May 3, 2024

Yes but through core :-)

@PopDaph PopDaph marked this pull request as ready for review May 3, 2024 11:24
@PopDaph PopDaph force-pushed the render-convo-multi-actions-1 branch 3 times, most recently from 5d19dec to d9337af Compare May 3, 2024 11:55
@PopDaph PopDaph requested review from fontanierh and spolu May 3, 2024 12:23
content: m.content,
});
}
if (m.action) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need m.actions but will create a separate task for that.

@lasryaric does your current work on inverting relationship include refactoring from message.action into message.actions ?

Copy link
Contributor

@fontanierh fontanierh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM deferring to @spolu for final review !

front/lib/api/assistant/generation.ts Outdated Show resolved Hide resolved
let text = `${m.role} ${"name" in m ? m.name : ""} ${m.content ?? ""}`;
if ("function_calls" in m) {
text += m.function_calls
.map((f) => `${f.function.name} ${f.function.arguments}`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be : search_data_sources {"query":"Soupinou cute","relativeTimeFrame":"all","topK":32}

export type AssistantFunctionCallMessageTypeModel = {
role: "assistant";
content: string | null;
function_calls: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function_calls is an array

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad it is!

@PopDaph PopDaph force-pushed the render-convo-multi-actions-1 branch from c5f6217 to d1708e0 Compare May 3, 2024 14:19
@PopDaph PopDaph requested a review from spolu May 3, 2024 14:37
@PopDaph PopDaph force-pushed the render-convo-multi-actions-1 branch from d1708e0 to b4b0ce7 Compare May 3, 2024 14:43
Copy link
Contributor

@spolu spolu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just rename for all actions:
renderFunctionMessageForForProcessAction => renderProcessActionFunctionCall

renderAssistantFunctionCallForProcessAction => renderProcessActionForMultiActionModel

front/lib/api/assistant/actions/process.ts Outdated Show resolved Hide resolved
front/lib/api/assistant/actions/dust_app_run.ts Outdated Show resolved Hide resolved
@PopDaph PopDaph force-pushed the render-convo-multi-actions-1 branch from ac80d35 to 00d40f5 Compare May 6, 2024 07:11
@PopDaph PopDaph merged commit 8940f0a into main May 6, 2024
6 checks passed
@PopDaph PopDaph deleted the render-convo-multi-actions-1 branch May 6, 2024 07:15
flvndvd pushed a commit that referenced this pull request May 26, 2024
* Multi-action renderConversationForModel with cli

* Replace tool by function

* Snake case as expected by the model

* I can't be git blamed on the fuck it comment :D

* Back to function_calls & improve token count estimation

* Get change from #4973

* Fix we want a single assistant message for all function calls of a given AgentMessageType

* Better naming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants