File tree 3 files changed +48
-5
lines changed
src/backend/src/modules/puterai
3 files changed +48
-5
lines changed Original file line number Diff line number Diff line change 1
1
const { TextractClient, AnalyzeDocumentCommand, InvalidS3ObjectException } = require ( "@aws-sdk/client-textract" ) ;
2
2
3
3
const BaseService = require ( "../../services/BaseService" ) ;
4
+ const APIError = require ( "../../api/APIError" ) ;
4
5
5
6
class AWSTextractService extends BaseService {
6
7
_construct ( ) {
@@ -10,6 +11,23 @@ class AWSTextractService extends BaseService {
10
11
static IMPLEMENTS = {
11
12
[ 'puter-ocr' ] : {
12
13
async recognize ( { source, test_mode } ) {
14
+ if ( test_mode ) {
15
+ return {
16
+ blocks : [
17
+ {
18
+ type : 'text/textract:WORD' ,
19
+ confidence : 0.9999998807907104 ,
20
+ text : 'Hello' ,
21
+ } ,
22
+ {
23
+ type : 'text/puter:sample-output' ,
24
+ confidence : 1 ,
25
+ text : 'The test_mode flag is set to true. This is a sample output.' ,
26
+ } ,
27
+ ]
28
+ } ;
29
+ }
30
+
13
31
const resp = await this . analyze_document ( source ) ;
14
32
15
33
// Simplify the response for common interface
Original file line number Diff line number Diff line change @@ -20,7 +20,32 @@ class OpenAICompletionService extends BaseService {
20
20
21
21
static IMPLEMENTS = {
22
22
[ 'puter-chat-completion' ] : {
23
- async complete ( { messages, vision } ) {
23
+ async complete ( { messages, test_mode } ) {
24
+ if ( test_mode ) {
25
+ const { LoremIpsum } = require ( 'lorem-ipsum' ) ;
26
+ const li = new LoremIpsum ( {
27
+ sentencesPerParagraph : {
28
+ max : 8 ,
29
+ min : 4
30
+ } ,
31
+ wordsPerSentence : {
32
+ max : 20 ,
33
+ min : 12
34
+ } ,
35
+ } ) ;
36
+ return {
37
+ "index" : 0 ,
38
+ "message" : {
39
+ "role" : "assistant" ,
40
+ "content" : li . generateParagraphs (
41
+ Math . floor ( Math . random ( ) * 3 ) + 1
42
+ ) ,
43
+ } ,
44
+ "logprobs" : null ,
45
+ "finish_reason" : "stop"
46
+ }
47
+ }
48
+
24
49
const model = 'gpt-4o' ;
25
50
return await this . complete ( messages , {
26
51
model,
Original file line number Diff line number Diff line change @@ -19,17 +19,17 @@ class OpenAIImageGenerationService extends BaseService {
19
19
static IMPLEMENTS = {
20
20
[ 'puter-image-generation' ] : {
21
21
async generate ( { prompt, test_mode } ) {
22
- const url = await this . generate ( prompt , {
23
- ratio : this . constructor . RATIO_SQUARE ,
24
- } ) ;
25
-
26
22
if ( test_mode ) {
27
23
return new TypedValue ( {
28
24
$ : 'string:url:web' ,
29
25
content_type : 'image' ,
30
26
} , 'https://puter-sample-data.puter.site/image_example.png' ) ;
31
27
}
32
28
29
+ const url = await this . generate ( prompt , {
30
+ ratio : this . constructor . RATIO_SQUARE ,
31
+ } ) ;
32
+
33
33
const image = new TypedValue ( {
34
34
$ : 'string:url:web' ,
35
35
content_type : 'image'
You can’t perform that action at this time.
0 commit comments