@@ -11,15 +11,14 @@ import { AppSchema } from '/srv/db/schema'
11
11
* Handler for arbitrary generation -- not for messages
12
12
*/
13
13
14
- export const plainGenerate = wrap ( async ( { socketId, userId, body, log } , res ) => {
14
+ export const inference = wrap ( async ( { socketId, userId, body, log } , res ) => {
15
15
assertValid ( { requestId : 'string' , prompt : 'string' , settings : 'any' , user : 'any' } , body )
16
16
17
17
let settings = body . settings as Partial < AppSchema . GenSettings > | null
18
- let user = body . user as AppSchema . User | null
19
18
if ( userId ) {
20
19
const id = body . settings . _id as string
21
20
settings = isDefaultPreset ( id ) ? defaultPresets [ id ] : await store . presets . getUserPreset ( id )
22
- user = await store . users . getUser ( userId )
21
+ body . user = await store . users . getUser ( userId )
23
22
}
24
23
25
24
if ( ! settings ) {
@@ -29,18 +28,18 @@ export const plainGenerate = wrap(async ({ socketId, userId, body, log }, res) =
29
28
)
30
29
}
31
30
32
- if ( ! user ) {
31
+ if ( ! body . user ) {
33
32
throw errors . Unauthorized
34
33
}
35
34
36
35
res . json ( { success : true , generating : true , message : 'Generating response' } )
37
36
38
37
const { stream } = await createPlainStream ( {
39
- user,
38
+ user : body . user ,
40
39
settings,
41
40
log,
42
41
prompt : body . prompt ,
43
- guest : socketId ,
42
+ guest : userId ? undefined : socketId ,
44
43
} )
45
44
46
45
let generated = ''
@@ -58,7 +57,11 @@ export const plainGenerate = wrap(async ({ socketId, userId, body, log }, res) =
58
57
59
58
if ( gen . error ) {
60
59
error = true
61
- const payload = { type : 'plain-generate-error' , requestId : body . requestId , error : gen . error }
60
+ const payload = {
61
+ type : 'plain-generate-complete' ,
62
+ requestId : body . requestId ,
63
+ error : gen . error ,
64
+ }
62
65
if ( userId ) sendOne ( userId , payload )
63
66
else sendGuest ( socketId , payload )
64
67
continue
0 commit comments