1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

chore: update schemas related to Unleash AI chat (#8463)

https://linear.app/unleash/issue/2-2779/store-conversations-in-the-database

Updates schemas related to Unleash AI chat and renames the `chat` column
to `messages` to ensure everything aligns nicely.
This commit is contained in:
Nuno Góis 2024-10-16 14:44:37 +01:00 committed by GitHub
parent 131e608885
commit 3f8d4c3538
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 59 additions and 1 deletions

View File

@ -4,6 +4,7 @@ export const aiChatMessageSchema = {
$id: '#/components/schemas/aiChatMessageSchema',
type: 'object',
description: 'Describes an Unleash AI chat message.',
additionalProperties: false,
required: ['role', 'content'],
properties: {
role: {

View File

@ -0,0 +1,20 @@
import type { FromSchema } from 'json-schema-to-ts';
export const aiChatNewMessageSchema = {
$id: '#/components/schemas/aiChatNewMessageSchema',
type: 'object',
description: 'Describes a new Unleash AI chat message sent by the user.',
required: ['message'],
properties: {
message: {
type: 'string',
description: 'The message content.',
example: 'What is your purpose?',
},
},
components: {
schemas: {},
},
} as const;
export type AIChatNewMessageSchema = FromSchema<typeof aiChatNewMessageSchema>;

View File

@ -5,8 +5,27 @@ export const aiChatSchema = {
$id: '#/components/schemas/aiChatSchema',
type: 'object',
description: 'Describes an Unleash AI chat.',
required: ['messages'],
additionalProperties: false,
required: ['id', 'userId', 'createdAt', 'messages'],
properties: {
id: {
type: 'string',
pattern: '^[0-9]+$', // BigInt
description:
"The chat's ID. Chat IDs are incrementing integers. In other words, a more recently created chat will always have a higher ID than an older one. This ID is represented as a string since it is a BigInt.",
example: '7',
},
userId: {
type: 'integer',
description: 'The ID of the user that the chat belongs to.',
example: 7,
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date and time of when the chat was created.',
example: '2023-12-27T13:37:00+01:00',
},
messages: {
type: 'array',
description:

View File

@ -15,6 +15,7 @@ export * from './advanced-playground-feature-schema';
export * from './advanced-playground-request-schema';
export * from './advanced-playground-response-schema';
export * from './ai-chat-message-schema';
export * from './ai-chat-new-message-schema';
export * from './ai-chat-schema';
export * from './api-token-schema';
export * from './api-tokens-schema';

View File

@ -0,0 +1,17 @@
exports.up = function (db, cb) {
db.runSql(
`
ALTER TABLE ai_chats RENAME COLUMN chat TO messages;
`,
cb,
);
};
exports.down = function (db, cb) {
db.runSql(
`
ALTER TABLE ai_chats RENAME COLUMN messages TO chat;
`,
cb,
);
};