Skip to content

Commit

Permalink
Instructions template support (user full name and agent list) (#2258)
Browse files Browse the repository at this point in the history
  • Loading branch information
spolu authored Oct 25, 2023
1 parent 6e61d9b commit 139b6fc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion front/lib/api/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export async function generateActionInputs(
// We inject the prompt of the model so that its input generation behavior can be modified by its
// instructions. It also injects context about the local time. If there is no generation phase we
// default to a generic prompt.
const prompt = constructPrompt(
const prompt = await constructPrompt(
auth,
userMessage,
configuration,
"You are a conversational assistant with access to function calling."
Expand Down
27 changes: 25 additions & 2 deletions front/lib/api/assistant/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from "@app/types/assistant/conversation";

import { renderDustAppRunActionForModel } from "./actions/dust_app_run";
import { getAgentConfigurations } from "./configuration";
const CANCELLATION_CHECK_INTERVAL = 500;

/**
Expand Down Expand Up @@ -249,7 +250,8 @@ export type GenerationCancelEvent = {
// - Meta data about the agent and current time.
// - Insructions from the agent configuration (in case of generation)
// - Meta data about the retrieval action (in case of retrieval)
export function constructPrompt(
export async function constructPrompt(
auth: Authenticator,
userMessage: UserMessageType,
configuration: AgentConfigurationType,
fallbackPrompt?: string
Expand All @@ -269,6 +271,27 @@ export function constructPrompt(
meta += "\n" + retrievalMetaPrompt();
}

meta.replaceAll(
"{USER_FULL_NAME}",
userMessage.context.fullName || "Unknown user"
);

// if meta includes the string "{ASSISTANTS_LIST}"
if (meta.includes("{ASSISTANTS_LIST}")) {
const agents = await getAgentConfigurations(auth);
meta.replaceAll(
"{ASSISTANTS_LIST}",
agents
.map((agent) => {
let agentDescription = "";
agentDescription += `@${agent.name}: `;
agentDescription += `${agent.description}`;
return agentDescription;
})
.join("\n")
);
}

return meta;
}

Expand Down Expand Up @@ -321,7 +344,7 @@ export async function* runGeneration(
);
}

const prompt = constructPrompt(userMessage, configuration);
const prompt = await constructPrompt(auth, userMessage, configuration);

// Turn the conversation into a digest that can be presented to the model.
const modelConversationRes = await renderConversationForModel({
Expand Down

0 comments on commit 139b6fc

Please sign in to comment.