Skip to content

Commit

Permalink
Apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph committed Sep 6, 2023
1 parent 39efe09 commit 3dc2bf8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 50 deletions.
4 changes: 2 additions & 2 deletions front/admin/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
XP1User,
} from "@app/lib/models";
import {
AgentDatasourceConfiguration,
AgentDataSourceConfiguration,
AgentRetrievalConfiguration,
} from "@app/lib/models/assistant/actions/retrieval";
import {
Expand Down Expand Up @@ -65,7 +65,7 @@ async function main() {
await AgentConfiguration.sync({ alter: true });
await AgentGenerationConfiguration.sync({ alter: true });
await AgentRetrievalConfiguration.sync({ alter: true });
await AgentDatasourceConfiguration.sync({ alter: true });
await AgentDataSourceConfiguration.sync({ alter: true });

await XP1User.sync({ alter: true });
await XP1Run.sync({ alter: true });
Expand Down
69 changes: 29 additions & 40 deletions front/lib/models/assistant/actions/retrieval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,18 @@ AgentRetrievalConfiguration.init(
beforeValidate: (retrieval: AgentRetrievalConfiguration) => {
// Validation for templated Query
if (retrieval.query == "templated") {
if (retrieval.queryTemplate === null) {
if (!retrieval.queryTemplate) {
throw new Error("Must set a template for templated query");
}
} else {
if (retrieval.queryTemplate) {
throw new Error("Can't set a template without templated query");
}
} else if (retrieval.queryTemplate) {
throw new Error("Can't set a template without templated query");
}

// Validation for Timeframe
if (retrieval.relativeTimeFrame == "custom") {
if (
retrieval.relativeTimeFrameDuration === null ||
retrieval.relativeTimeFrameUnit === null
!retrieval.relativeTimeFrameDuration ||
!retrieval.relativeTimeFrameUnit
) {
throw new Error(
"Custom relative time frame must have a duration and unit set"
Expand All @@ -99,9 +97,9 @@ AgentRetrievalConfiguration.init(
/**
* Configuration of Datasources used for Retrieval Action.
*/
export class AgentDatasourceConfiguration extends Model<
InferAttributes<AgentDatasourceConfiguration>,
InferCreationAttributes<AgentDatasourceConfiguration>
export class AgentDataSourceConfiguration extends Model<
InferAttributes<AgentDataSourceConfiguration>,
InferCreationAttributes<AgentDataSourceConfiguration>
> {
declare id: number;

Expand All @@ -110,17 +108,17 @@ export class AgentDatasourceConfiguration extends Model<
declare timeframeDuration: number | null;
declare timeframeUnit: TimeframeUnit | null;

declare tagsIn: string[];
declare tagsOut: string[];
declare parentsIn: string[];
declare parentsOut: string[];
declare tagsIn: string[] | null;
declare tagsNotIn: string[] | null;
declare parentsIn: string[] | null;
declare parentsNotIn: string[] | null;

declare datasourceId: ForeignKey<DataSource["id"]>;
declare dataSourceId: ForeignKey<DataSource["id"]>;
declare retrievalConfigurationId: ForeignKey<
AgentRetrievalConfiguration["id"]
>;
}
AgentDatasourceConfiguration.init(
AgentDataSourceConfiguration.init(
{
id: {
type: DataTypes.INTEGER,
Expand All @@ -145,49 +143,40 @@ AgentDatasourceConfiguration.init(
},
tagsIn: {
type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: false,
defaultValue: [],
allowNull: true,
},
tagsOut: {
tagsNotIn: {
type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: false,
defaultValue: [],
allowNull: true,
},
parentsIn: {
type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: false,
defaultValue: [],
allowNull: true,
},
parentsOut: {
parentsNotIn: {
type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: false,
defaultValue: [],
allowNull: true,
},
},
{
modelName: "agent_datasource_configuration",
modelName: "agent_data_source_configuration",
sequelize: front_sequelize,
hooks: {
beforeValidate: (datasourceConfig: AgentDatasourceConfiguration) => {
if (
(datasourceConfig.minTimestamp === null) !==
(datasourceConfig.maxTimestamp === null)
) {
beforeValidate: (dataSourceConfig: AgentDataSourceConfiguration) => {
if (!dataSourceConfig.minTimestamp !== !dataSourceConfig.maxTimestamp) {
throw new Error("Timestamps must be both set or both null");
}
if (
(datasourceConfig.timeframeDuration === null) !==
(datasourceConfig.timeframeUnit === null)
!dataSourceConfig.timeframeDuration !==
!dataSourceConfig.timeframeUnit
) {
throw new Error(
"Timeframe duration/unit must be both set or both null"
);
}
if (
(datasourceConfig.minTimestamp !== null ||
datasourceConfig.maxTimestamp !== null) &&
(datasourceConfig.timeframeDuration !== null ||
datasourceConfig.timeframeUnit !== null)
(dataSourceConfig.minTimestamp || dataSourceConfig.maxTimestamp) &&
(dataSourceConfig.timeframeDuration || dataSourceConfig.timeframeUnit)
) {
throw new Error("Cannot use both timestamps and timeframe");
}
Expand All @@ -196,8 +185,8 @@ AgentDatasourceConfiguration.init(
}
);

// Retrieval config <> datasource config
AgentRetrievalConfiguration.hasMany(AgentDatasourceConfiguration, {
// Retrieval config <> data source config
AgentRetrievalConfiguration.hasMany(AgentDataSourceConfiguration, {
foreignKey: { name: "retrievalId", allowNull: false },
onDelete: "CASCADE",
});
Expand Down
18 changes: 10 additions & 8 deletions front/lib/models/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
import { front_sequelize } from "@app/lib/databases";
import { AgentRetrievalConfiguration } from "@app/lib/models/assistant/actions/retrieval";
import { Workspace } from "@app/lib/models/workspace";
import { AgentConfigurationStatus } from "@app/types/assistant/agent";
import {
AgentConfigurationScope,
AgentConfigurationStatus,
} from "@app/types/assistant/agent";

/**
* Agent configuration
Expand All @@ -25,7 +28,7 @@ export class AgentConfiguration extends Model<
declare name: string;
declare pictureUrl: string | null;

declare isGlobal: boolean;
declare scope: AgentConfigurationScope;
declare workspaceId: ForeignKey<Workspace["id"]> | null; // null = it's a global agent

declare model: ForeignKey<AgentRetrievalConfiguration["id"]> | null;
Expand Down Expand Up @@ -55,10 +58,10 @@ AgentConfiguration.init(
type: DataTypes.TEXT,
allowNull: true,
},
isGlobal: {
type: DataTypes.BOOLEAN,
scope: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: false,
defaultValue: "workspace",
},
},
{
Expand All @@ -75,10 +78,9 @@ AgentConfiguration.init(
],
hooks: {
beforeValidate: (agent: AgentConfiguration) => {
if (agent.isGlobal && agent.workspaceId) {
if (agent.scope !== "workspace" && agent.workspaceId) {
throw new Error("Workspace id must be null for global agent");
}
if (!agent.isGlobal && !agent.workspaceId) {
} else if (agent.scope === "workspace" && !agent.workspaceId) {
throw new Error("Workspace id must be set for non-global agent");
}
},
Expand Down
1 change: 1 addition & 0 deletions front/types/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type AgentGenerationConfigurationType = {
*/

export type AgentConfigurationStatus = "active" | "archived";
export type AgentConfigurationScope = "global" | "workspace";

export type AgentConfigurationType = {
sId: string;
Expand Down

0 comments on commit 3dc2bf8

Please sign in to comment.