1+ /* eslint-disable */
2+ // TODO: Make these more compatible with eslint
3+ window . aiTests = [
4+ testChatBasicPrompt = async function ( ) {
5+ try {
6+ // Test basic string prompt with test mode enabled
7+ const result = await puter . ai . chat ( "Hello, how are you?" ) ;
8+
9+ // Check that result is an object and not null
10+ assert ( typeof result === 'object' , "chat should return an object" ) ;
11+ assert ( result !== null , "chat should not return null" ) ;
12+
13+ // Check that the result has the expected structure
14+ assert ( typeof result . message === 'object' , "result should have a message object" ) ;
15+ assert ( typeof result . message . content === 'string' , "result.message should have content string" ) ;
16+
17+ // Check that toString() and valueOf() methods exist and work
18+ assert ( typeof result . toString === 'function' , "result should have toString method" ) ;
19+ assert ( typeof result . valueOf === 'function' , "result should have valueOf method" ) ;
20+
21+ // Check that toString() and valueOf() return the message content
22+ assert ( result . toString ( ) === result . message . content , "toString() should return message content" ) ;
23+ assert ( result . valueOf ( ) === result . message . content , "valueOf() should return message content" ) ;
24+
25+ // In test mode, the content should be a test response
26+ assert ( result . message . content . length > 0 , "message content should not be empty" ) ;
27+
28+ pass ( "testChatBasicPrompt passed" ) ;
29+ } catch ( error ) {
30+ fail ( "testChatBasicPrompt failed:" , error ) ;
31+ }
32+ } ,
33+
34+ testChatWithParameters = async function ( ) {
35+ try {
36+ // Test chat with parameters object
37+ const result = await puter . ai . chat ( "What is 2+2?" , {
38+ model : "openrouter:openai/gpt-4.1-mini" ,
39+ temperature : 0.7 ,
40+ max_tokens : 50
41+ } ) ;
42+
43+ // Check basic result structure
44+ assert ( typeof result === 'object' , "chat should return an object" ) ;
45+ assert ( result !== null , "chat should not return null" ) ;
46+ assert ( typeof result . message === 'object' , "result should have a message object" ) ;
47+ assert ( typeof result . message . content === 'string' || Array . isArray ( result . message . content ) , "result.message should have content string or an array" ) ;
48+
49+ // Check that the methods work
50+ assert ( typeof result . toString === 'function' , "result should have toString method" ) ;
51+ assert ( typeof result . valueOf === 'function' , "result should have valueOf method" ) ;
52+
53+ pass ( "testChatWithParameters passed" ) ;
54+ } catch ( error ) {
55+ fail ( "testChatWithParameters failed:" , error ) ;
56+ }
57+ } ,
58+ ] ;
0 commit comments