mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat: file attachment input
This commit is contained in:
+3
-2
@@ -37,14 +37,15 @@ export const createAgent = ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const generateUserPrompt = (input: AgentInput) => {
|
const generateUserPrompt = (input: AgentInput) => {
|
||||||
|
const images = input.attachments.filter(attachment => attachment.type === 'image')
|
||||||
|
const files = input.attachments.filter(attachment => attachment.type === 'file')
|
||||||
const text = user(input.query, {
|
const text = user(input.query, {
|
||||||
contactId: identity.contactId,
|
contactId: identity.contactId,
|
||||||
contactName: identity.contactName,
|
contactName: identity.contactName,
|
||||||
platform: currentPlatform,
|
platform: currentPlatform,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
|
attachments: files,
|
||||||
})
|
})
|
||||||
const images = input.attachments.filter(attachment => attachment.type === 'image')
|
|
||||||
// const files = input.attachments.filter(attachment => attachment.type === 'file')
|
|
||||||
const userMessage: UserModelMessage = {
|
const userMessage: UserModelMessage = {
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: [
|
content: [
|
||||||
|
|||||||
+15
-1
@@ -40,4 +40,18 @@ export const ScheduleModel = z.object({
|
|||||||
pattern: z.string().min(1, 'Schedule pattern is required'),
|
pattern: z.string().min(1, 'Schedule pattern is required'),
|
||||||
maxCalls: z.number().nullable().optional(),
|
maxCalls: z.number().nullable().optional(),
|
||||||
command: z.string().min(1, 'Schedule command is required'),
|
command: z.string().min(1, 'Schedule command is required'),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const ImageAttachmentModel = z.object({
|
||||||
|
type: z.literal('image'),
|
||||||
|
base64: z.string().min(1, 'Image base64 is required'),
|
||||||
|
metadata: z.record(z.string(), z.any()).optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const FileAttachmentModel = z.object({
|
||||||
|
type: z.literal('file'),
|
||||||
|
path: z.string().min(1, 'File path is required'),
|
||||||
|
metadata: z.record(z.string(), z.any()).optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const AttachmentModel = z.union([ImageAttachmentModel, FileAttachmentModel])
|
||||||
@@ -4,7 +4,7 @@ import { createAgent } from '../agent'
|
|||||||
import { createAuthFetcher } from '../index'
|
import { createAuthFetcher } from '../index'
|
||||||
import { ModelConfig } from '../types'
|
import { ModelConfig } from '../types'
|
||||||
import { bearerMiddleware } from '../middlewares/bearer'
|
import { bearerMiddleware } from '../middlewares/bearer'
|
||||||
import { AllowedActionModel, IdentityContextModel, ModelConfigModel } from '../models'
|
import { AllowedActionModel, AttachmentModel, IdentityContextModel, ModelConfigModel } from '../models'
|
||||||
import { allActions } from '../types'
|
import { allActions } from '../types'
|
||||||
|
|
||||||
const AgentModel = z.object({
|
const AgentModel = z.object({
|
||||||
@@ -17,6 +17,7 @@ const AgentModel = z.object({
|
|||||||
skills: z.array(z.string()),
|
skills: z.array(z.string()),
|
||||||
query: z.string(),
|
query: z.string(),
|
||||||
identity: IdentityContextModel,
|
identity: IdentityContextModel,
|
||||||
|
attachments: z.array(AttachmentModel),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const chatModule = new Elysia({ prefix: '/chat' })
|
export const chatModule = new Elysia({ prefix: '/chat' })
|
||||||
@@ -35,7 +36,7 @@ export const chatModule = new Elysia({ prefix: '/chat' })
|
|||||||
query: body.query,
|
query: body.query,
|
||||||
messages: body.messages,
|
messages: body.messages,
|
||||||
skills: body.skills,
|
skills: body.skills,
|
||||||
attachments: [],
|
attachments: body.attachments,
|
||||||
})
|
})
|
||||||
}, {
|
}, {
|
||||||
body: AgentModel,
|
body: AgentModel,
|
||||||
@@ -54,7 +55,7 @@ export const chatModule = new Elysia({ prefix: '/chat' })
|
|||||||
query: body.query,
|
query: body.query,
|
||||||
messages: body.messages,
|
messages: body.messages,
|
||||||
skills: body.skills,
|
skills: body.skills,
|
||||||
attachments: [],
|
attachments: body.attachments,
|
||||||
})) {
|
})) {
|
||||||
yield sse(JSON.stringify(action))
|
yield sse(JSON.stringify(action))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
|
import { ContainerFileAttachment } from '../types'
|
||||||
|
|
||||||
export interface UserParams {
|
export interface UserParams {
|
||||||
contactId: string
|
contactId: string
|
||||||
contactName: string
|
contactName: string
|
||||||
platform: string
|
platform: string
|
||||||
date: Date
|
date: Date
|
||||||
|
attachments: ContainerFileAttachment[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const user = (
|
export const user = (
|
||||||
query: string,
|
query: string,
|
||||||
{ contactId, contactName, platform, date }: UserParams
|
{ contactId, contactName, platform, date, attachments }: UserParams
|
||||||
) => {
|
) => {
|
||||||
const headers = {
|
const headers = {
|
||||||
'contact-id': contactId,
|
'contact-id': contactId,
|
||||||
'contact-name': contactName,
|
'contact-name': contactName,
|
||||||
'platform': platform,
|
'platform': platform,
|
||||||
'time': date.toISOString(),
|
'time': date.toISOString(),
|
||||||
|
'attachments': attachments.map(attachment => attachment.path),
|
||||||
}
|
}
|
||||||
return `
|
return `
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export interface BaseAgentAttachment {
|
export interface BaseAgentAttachment {
|
||||||
type: string
|
type: string
|
||||||
metadata: Record<string, unknown>
|
metadata?: Record<string, unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ImageAttachment extends BaseAgentAttachment {
|
export interface ImageAttachment extends BaseAgentAttachment {
|
||||||
|
|||||||
Reference in New Issue
Block a user