File tree Expand file tree Collapse file tree 3 files changed +16
-24
lines changed Expand file tree Collapse file tree 3 files changed +16
-24
lines changed Original file line number Diff line number Diff line change @@ -9,13 +9,15 @@ traceloop.initialize({
9
9
const openai = new OpenAI ( ) ;
10
10
11
11
class SampleOpenAI {
12
+ constructor ( private model = "gpt-3.5-turbo" ) { }
13
+
12
14
@traceloop . workflow ( { name : "sample_chat" } )
13
15
async chat ( ) {
14
16
const chatCompletion = await openai . chat . completions . create ( {
15
17
messages : [
16
18
{ role : "user" , content : "Tell me a joke about OpenTelemetry" } ,
17
19
] ,
18
- model : "gpt-3.5-turbo" ,
20
+ model : this . model ,
19
21
} ) ;
20
22
21
23
return chatCompletion . choices [ 0 ] . message . content ;
Original file line number Diff line number Diff line change @@ -187,30 +187,18 @@ function entity(
187
187
propertyKey : string ,
188
188
descriptor : PropertyDescriptor ,
189
189
) {
190
- const originalMethod : ( ) => any = descriptor . value ;
190
+ const originalMethod = descriptor . value ;
191
191
const entityName = config . name ?? originalMethod . name ;
192
192
193
- if ( originalMethod . constructor . name === "AsyncFunction" ) {
194
- descriptor . value = async function ( ...args : any [ ] ) {
195
- return await withEntity (
196
- type ,
197
- { ...config , name : entityName } ,
198
- originalMethod ,
199
- target ,
200
- ...args ,
201
- ) ;
202
- } ;
203
- } else {
204
- descriptor . value = function ( ...args : any [ ] ) {
205
- return withEntity (
206
- type ,
207
- { ...config , name : entityName } ,
208
- originalMethod ,
209
- target ,
210
- ...args ,
211
- ) ;
212
- } ;
213
- }
193
+ descriptor . value = function ( ...args : any [ ] ) {
194
+ return withEntity (
195
+ type ,
196
+ { ...config , name : entityName } ,
197
+ originalMethod ,
198
+ this ,
199
+ ...args ,
200
+ ) ;
201
+ } ;
214
202
} ;
215
203
}
216
204
Original file line number Diff line number Diff line change @@ -134,6 +134,8 @@ describe("Test SDK Decorators", () => {
134
134
135
135
it ( "should create spans for workflows using decoration syntax" , async ( ) => {
136
136
class TestOpenAI {
137
+ constructor ( private model = "gpt-3.5-turbo" ) { }
138
+
137
139
@traceloop . workflow ( { name : "sample_chat" } )
138
140
async chat ( things : Map < string , string > ) {
139
141
const generations : Map < string , string > = new Map ( ) ;
@@ -142,7 +144,7 @@ describe("Test SDK Decorators", () => {
142
144
messages : [
143
145
{ role : "user" , content : `Tell me a ${ key } about ${ value } ` } ,
144
146
] ,
145
- model : "gpt-3.5-turbo" ,
147
+ model : this . model ,
146
148
} ) ;
147
149
148
150
if ( cha
38D6
tCompletion . choices [ 0 ] . message . content ) {
You can’t perform that action at this time.
0 commit comments