@@ -6,6 +6,10 @@ import { getTestUserHeaders } from '../../shared/testData'
6
6
import logger from '../util/logger'
7
7
import { TEST_COURSES } from '../../shared/testData'
8
8
import { headersToUser } from '../middleware/user'
9
+ import { ResponsesClient } from '../util/azure/ResponsesAPI'
10
+ import { RequestWithUser } from '../types'
11
+ import getEncoding from '../util/tiktoken'
12
+ import { getCompletionEvents } from '../util/azure/client'
9
13
10
14
const router = Router ( )
11
15
@@ -83,4 +87,58 @@ router.post('/reset-test-data', async (req, res) => {
83
87
res . status ( 200 ) . json ( { message : 'Test data reset successfully' } )
84
88
} )
85
89
90
+ router . post ( '/responses-api' , async ( req , res ) => {
91
+ const { user } = req as RequestWithUser
92
+
93
+ const encoding = getEncoding ( 'gpt-4o-mini' )
94
+
95
+ const responsesClient = new ResponsesClient ( {
96
+ model : 'gpt-4o-mini' ,
97
+ ragIndex : undefined ,
98
+ instructions : '' ,
99
+ temperature : 0.9 ,
100
+ user,
101
+ } )
102
+
103
+ console . log ( 'Starting Responses API stream' )
104
+
105
+ const stream = await responsesClient . createResponse ( {
106
+ input : {
107
+ role : 'user' ,
108
+ content : 'Hello!, please explain the concept of artificial intelligence.' ,
109
+ } ,
110
+ } )
111
+
112
+ console . log ( 'Stream Responses API started' )
113
+
114
+ const result = await responsesClient . handleResponse ( { stream, encoding, res } )
115
+
116
+ console . log ( 'Stream Responses API ended' , result )
117
+ } )
118
+
119
+ router . post ( '/completions-api' , async ( req , res ) => {
120
+ console . log ( 'Starting Completions API' )
121
+
122
+ const result = await getCompletionEvents ( {
123
+ messages : [
124
+ {
125
+ role : 'user' ,
126
+ // @ts -expect-error whatever
127
+ content : 'Hello!, please explain the concept of artificial intelligence.' ,
128
+ } ,
129
+ ] ,
130
+ model : 'gpt-4o-mini' ,
131
+ options : {
132
+ temperature : 0.9 ,
133
+ } ,
134
+ } )
135
+
136
+ // @ts -expect-error whatever
137
+ for await ( const chunk of result ) {
138
+ console . log ( 'Completions API chunk:' , chunk )
139
+ }
140
+
141
+ console . log ( 'Completions API result:' , result )
142
+ } )
143
+
86
144
export default router
0 commit comments