File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 28
28
2 . Alternative: Use ONLY ` @trace_async() ` decorator (but lose OpenAI-specific metrics)
29
29
3 . ** NEVER** : Mix decorators with client tracing - this always causes duplicates
30
30
31
- ** Confirmed Working Solution** :
31
+ ** Confirmed Working Solutions** :
32
+
33
+ ** Option 1 - No Function Tracing** (simplest):
32
34
``` python
33
35
class say_hi :
34
36
def __init__ (self ):
@@ -41,6 +43,21 @@ class say_hi:
41
43
# ... rest of streaming logic
42
44
```
43
45
46
+ ** Option 2 - With Function Tracing** (recommended):
47
+ ``` python
48
+ class say_hi :
49
+ def __init__ (self ):
50
+ self .openai_client = trace_async_openai(AsyncOpenAI())
51
+
52
+ @trace_async () # ✅ Works when function returns string
53
+ async def hi (self , cur_str : str ) -> str : # Return complete response
54
+ response = await self .openai_client.chat.completions.create(... )
55
+ complete_answer = " "
56
+ async for chunk in response:
57
+ complete_answer += chunk.choices[0 ].delta.content or " "
58
+ return complete_answer # ✅ Return instead of yield
59
+ ```
60
+
44
61
## Project Structure Insights
45
62
46
63
### Tracing Architecture
You can’t perform that action at this time.
0 commit comments