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({
99const openai = new OpenAI ( ) ;
1010
1111class SampleOpenAI {
12+ constructor ( private model = "gpt-3.5-turbo" ) { }
13+
1214 @traceloop . workflow ( { name : "sample_chat" } )
1315 async chat ( ) {
1416 const chatCompletion = await openai . chat . completions . create ( {
1517 messages : [
1618 { role : "user" , content : "Tell me a joke about OpenTelemetry" } ,
1719 ] ,
18- model : "gpt-3.5-turbo" ,
20+ model : this . model ,
1921 } ) ;
2022
2123 return chatCompletion . choices [ 0 ] . message . content ;
Original file line number Diff line number Diff line change @@ -187,30 +187,18 @@ function entity(
187187 propertyKey : string ,
188188 descriptor : PropertyDescriptor ,
189189 ) {
190- const originalMethod : ( ) => any = descriptor . value ;
190+ const originalMethod = descriptor . value ;
191191 const entityName = config . name ?? originalMethod . name ;
192192
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+ } ;
214202 } ;
215203}
216204
Original file line number Diff line number Diff line change @@ -134,6 +134,8 @@ describe("Test SDK Decorators", () => {
134134
135135 it ( "should create spans for workflows using decoration syntax" , async ( ) => {
136136 class TestOpenAI {
137+ constructor ( private model = "gpt-3.5-turbo" ) { }
138+
137139 @traceloop . workflow ( { name : "sample_chat" } )
138140 async chat ( things : Map < string , string > ) {
139141 const generations : Map < string , string > = new Map ( ) ;
@@ -142,7 +144,7 @@ describe("Test SDK Decorators", () => {
142144 messages : [
143145 { role : "user" , content : `Tell me a ${ key } about ${ value } ` } ,
144146 ] ,
145- model : "gpt-3.5-turbo" ,
147+ model : this . model ,
146148 } ) ;
147149
148150 if ( chatCompletion . choices [ 0 ] . message . content ) {
You can’t perform that action at this time.
0 commit comments