Skip to content

Commit

Permalink
chore: remove Assistant prefix from models, types, foreign keys, va…
Browse files Browse the repository at this point in the history
…riables (#1285)

* AssistantConversation -> Conversation

* AssistantUserMessage -> UserMessage

* assistantConversation -> conversation

* assistantUserMessage -> userMessage

* AssistantAgentMessage -> AgentMessage

* remaining types

* fix tables and fkeys
  • Loading branch information
fontanierh authored Sep 6, 2023
1 parent 894cee6 commit d849aba
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 149 deletions.
16 changes: 8 additions & 8 deletions front/admin/db.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
AgentMessage,
App,
AssistantAgentMessage,
AssistantConversation,
AssistantMessage,
AssistantUserMessage,
ChatMessage,
ChatRetrievedDocument,
ChatSession,
Clone,
Conversation,
Dataset,
DataSource,
DocumentTrackerChangeSuggestion,
Expand All @@ -17,10 +15,12 @@ import {
Key,
Membership,
MembershipInvitation,
Message,
Provider,
Run,
TrackedDocument,
User,
UserMessage,
UserMetadata,
Workspace,
XP1Run,
Expand Down Expand Up @@ -49,10 +49,10 @@ async function main() {
await ExtractedEvent.sync({ alter: true });
await DocumentTrackerChangeSuggestion.sync({ alter: true });

await AssistantConversation.sync({ alter: true });
await AssistantUserMessage.sync({ alter: true });
await AssistantAgentMessage.sync({ alter: true });
await AssistantMessage.sync({ alter: true });
await Conversation.sync({ alter: true });
await UserMessage.sync({ alter: true });
await AgentMessage.sync({ alter: true });
await Message.sync({ alter: true });

await XP1User.sync({ alter: true });
await XP1Run.sync({ alter: true });
Expand Down
18 changes: 9 additions & 9 deletions front/lib/api/assistant/actions/retrieval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {
AgentConfigurationType,
} from "@app/types/assistant/agent";
import {
AssistantAgentMessageType,
AssistantConversationType,
AssistantUserMessageType,
AgentMessageType,
ConversationType,
UserMessageType,
} from "@app/types/assistant/conversation";

/**
Expand Down Expand Up @@ -174,8 +174,8 @@ export async function retrievalActionSpecification(
export async function generateRetrievalParams(
auth: Authenticator,
configuration: RetrievalConfigurationType,
conversation: AssistantConversationType,
userMessage: AssistantUserMessageType
conversation: ConversationType,
userMessage: UserMessageType
): Promise<
Result<
{ query: string | null; relativeTimeFrame: TimeFrame | null; topK: number },
Expand Down Expand Up @@ -299,15 +299,15 @@ export type RetrievalSuccessEvent = {
action: RetrievalActionType;
};

// This method is in charge of running the retrieval and creating an AssistantAgentRetrieval DB
// This method is in charge of running the retrieval and creating an AgentRetrieval DB
// object in the database (along with the RetrievedDocument objects). It does not create any generic
// model related to the conversation.
export async function* runRetrieval(
auth: Authenticator,
configuration: AgentConfigurationType,
conversation: AssistantConversationType,
userMessage: AssistantUserMessageType,
agentMessage: AssistantAgentMessageType
conversation: ConversationType,
userMessage: UserMessageType,
agentMessage: AgentMessageType
): AsyncGenerator<
| RetrievalParamsEvent
| RetrievalDocumentsEvent
Expand Down
18 changes: 9 additions & 9 deletions front/lib/api/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
AgentMessageConfigurationType,
} from "@app/types/assistant/agent";
import {
AssistantAgentActionType,
AssistantAgentMessageType,
AssistantConversationType,
AgentActionType,
AgentMessageType,
ConversationType,
} from "@app/types/assistant/conversation";

import {
Expand Down Expand Up @@ -88,7 +88,7 @@ export async function updateAgentConfiguration(
export async function generateActionInputs(
auth: Authenticator,
specification: AgentActionSpecification,
conversation: AssistantConversationType
conversation: ConversationType
): Promise<Result<Record<string, string | boolean | number>, Error>> {
const model = {
providerId: "openai",
Expand Down Expand Up @@ -160,7 +160,7 @@ export type AgentMessageNewEvent = {
type: "agent_message_new";
created: number;
configurationId: string;
message: AssistantAgentMessageType;
message: AgentMessageType;
};

// Generic event sent when an error occured (whether it's during the action or the message generation).
Expand All @@ -184,7 +184,7 @@ export type AgentActionSuccessEvent = {
created: number;
configurationId: string;
messageId: string;
action: AssistantAgentActionType;
action: AgentActionType;
};

// Event sent when tokens are streamed as the the agent is generating a message.
Expand All @@ -202,16 +202,16 @@ export type AgentMessageSuccessEvent = {
created: number;
configurationId: string;
messageId: string;
message: AssistantAgentMessageType;
message: AgentMessageType;
};

// This interface is used to execute an agent. It is in charge of creating the AssistantAgentMessage
// This interface is used to execute an agent. It is in charge of creating the AgentMessage
// object in database (fully completed or with error set if an error occured). It is called to run
// an agent or when retrying a previous agent interaction.
export async function* runAgent(
auth: Authenticator,
configuration: AgentConfigurationType,
conversation: AssistantConversationType
conversation: ConversationType
): AsyncGenerator<
| AgentMessageNewEvent
| AgentErrorEvent
Expand Down
64 changes: 30 additions & 34 deletions front/lib/api/assistant/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@ import {
import { Authenticator } from "@app/lib/auth";
import { CoreAPI } from "@app/lib/core_api";
import { front_sequelize } from "@app/lib/databases";
import {
AssistantAgentMessage,
AssistantMessage,
AssistantUserMessage,
} from "@app/lib/models";
import { AgentMessage, Message, UserMessage } from "@app/lib/models";
import { Err, Ok, Result } from "@app/lib/result";
import { generateModelSId } from "@app/lib/utils";
import logger from "@app/logger/logger";
import { isRetrievalActionType } from "@app/types/assistant/actions/retrieval";
import {
AssistantAgentMessageType,
AssistantConversationType,
AssistantMention,
AssistantUserMessageContext,
AssistantUserMessageType,
AgentMessageType,
ConversationType,
isAgentMention,
isAgentMessageType,
isAssistantAgentMention,
isUserMessageType,
Mention,
UserMessageContext,
UserMessageType,
} from "@app/types/assistant/conversation";

import { renderRetrievalActionForModel } from "./actions/retrieval";
Expand All @@ -52,7 +48,7 @@ export async function renderConversationForModel({
model,
allowedTokenCount,
}: {
conversation: AssistantConversationType;
conversation: ConversationType;
model: { providerId: string; modelId: string };
allowedTokenCount: number;
}): Promise<Result<ModelConversationType, Error>> {
Expand Down Expand Up @@ -156,7 +152,7 @@ export async function renderConversationForModel({
// Event sent when the user message is created.
export type UserMessageNewEvent = {
type: "user_message_new";
message: AssistantUserMessageType;
message: UserMessageType;
};

// This method is in charge of creating a new user message in database, running the necessary agents
Expand All @@ -169,10 +165,10 @@ export async function* postUserMessage(
mentions,
context,
}: {
conversation: AssistantConversationType;
conversation: ConversationType;
message: string;
mentions: AssistantMention[];
context: AssistantUserMessageContext;
mentions: Mention[];
context: UserMessageContext;
}
): AsyncGenerator<
| UserMessageNewEvent
Expand All @@ -185,26 +181,26 @@ export async function* postUserMessage(
> {
const user = auth.user();

let userMessage: AssistantUserMessageType | null = null;
const agentMessages: AssistantAgentMessageType[] = [];
let userMessage: UserMessageType | null = null;
const agentMessages: AgentMessageType[] = [];

await front_sequelize.transaction(async (t) => {
let nextMessageRank =
((await AssistantMessage.max<number | null, AssistantMessage>("rank", {
((await Message.max<number | null, Message>("rank", {
where: {
assistantConversationId: conversation.id,
conversationId: conversation.id,
},
transaction: t,
})) ?? -1) + 1;

const userMessageRow = await AssistantMessage.create(
const userMessageRow = await Message.create(
{
sId: generateModelSId(),
rank: nextMessageRank++,
assistantConversationId: conversation.id,
conversationId: conversation.id,
parentId: null,
assistantUserMessageId: (
await AssistantUserMessage.create(
userMessageId: (
await UserMessage.create(
{
message: message,
userContextUsername: context.username,
Expand Down Expand Up @@ -237,15 +233,15 @@ export async function* postUserMessage(

// for each assistant mention, create an "empty" agent message
for (const m of mentions) {
if (isAssistantAgentMention(m)) {
const agentMessageRow = await AssistantMessage.create(
if (isAgentMention(m)) {
const agentMessageRow = await Message.create(
{
sId: generateModelSId(),
rank: nextMessageRank++,
assistantConversationId: conversation.id,
conversationId: conversation.id,
parentId: userMessage.id,
assistantAgentMessageId: (
await AssistantAgentMessage.create({}, { transaction: t })
agentMessageId: (
await AgentMessage.create({}, { transaction: t })
).id,
},
{
Expand Down Expand Up @@ -309,15 +305,15 @@ export async function* postUserMessage(
}

// This method is in charge of re-running an agent interaction (generating a new
// AssistantAgentMessage as a result)
// AgentMessage as a result)
export async function* retryAgentMessage(
auth: Authenticator,
{
conversation,
message,
}: {
conversation: AssistantConversationType;
message: AssistantAgentMessageType;
conversation: ConversationType;
message: AgentMessageType;
}
): AsyncGenerator<
| AgentMessageNewEvent
Expand Down Expand Up @@ -348,8 +344,8 @@ export async function* editUserMessage(
message,
content,
}: {
conversation: AssistantConversationType;
message: AssistantUserMessageType;
conversation: ConversationType;
message: UserMessageType;
content: string;
}
): AsyncGenerator<
Expand Down
Loading

0 comments on commit d849aba

Please sign in to comment.