• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

scope3data / scope3ai-py / 12933127151

23 Jan 2025 04:01PM UTC coverage: 96.237% (+15.7%) from 80.557%
12933127151

Pull #73

github

aa22d7
kevdevg
fix: fixing pr
Pull Request #73: feat(litellm): Use default tracer and Image generation - TTS - STT

185 of 187 new or added lines in 12 files covered. (98.93%)

49 existing lines in 10 files now uncovered.

2327 of 2418 relevant lines covered (96.24%)

3.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/scope3ai/api/tracer.py
1
from typing import List, Optional
4✔
2

3
from .typesgen import ImpactResponse, ModeledRow
4✔
4

5

6
class Tracer:
4✔
7
    def __init__(
4✔
8
        self,
9
        name: str = None,
10
        keep_traces: bool = False,
11
    ) -> None:
12
        from scope3ai.lib import Scope3AI
4✔
13

14
        self.scope3ai = Scope3AI.get_instance()
4✔
15
        self.name = name
4✔
16
        self.keep_traces = keep_traces
4✔
17
        self.children: List[Tracer] = []
4✔
18
        self.rows: List[ModeledRow] = []
4✔
19
        self.traces = []  # type: List[Scope3AIContext]
4✔
20

21
    def impact(self, timeout: Optional[int] = None) -> ImpactResponse:
4✔
22
        """
23
        Return an aggregated impact response for the current tracer and its children.
24

25
        As the impact is computed asynchronously, this method will wait for the
26
        impact response to be available before returning it.
27
        """
28
        for trace in self.traces:
4✔
29
            trace.wait_impact(timeout)
4✔
30
        return self._impact()
4✔
31

32
    async def aimpact(self, timeout: Optional[int] = None) -> ImpactResponse:
4✔
33
        """
34
        Async version of Tracer::impact.
35
        """
UNCOV
36
        for trace in self.traces:
×
UNCOV
37
            await trace.await_impact(timeout)
×
UNCOV
38
        return self._impact()
×
39

40
    def _impact(self) -> ImpactResponse:
4✔
41
        """
42
        Return an aggregated impact response for the current tracer and its children.
43
        """
44
        all_rows = self.get_all_rows()
4✔
45
        return ImpactResponse(
4✔
46
            rows=all_rows,
47
            total_energy_wh=sum([row.total_impact.usage_energy_wh for row in all_rows]),
48
            total_gco2e=sum(
49
                [row.total_impact.usage_emissions_gco2e for row in all_rows]
50
            ),
51
            total_mlh2o=sum([row.total_impact.usage_water_ml for row in all_rows]),
52
            has_errors=any([row.error is not None for row in all_rows]),
53
        )
54

55
    def add_impact(self, impact: ModeledRow) -> None:
4✔
56
        self.rows.append(impact)
4✔
57

58
    def get_all_rows(self) -> List[ModeledRow]:
4✔
59
        all_rows = self.rows[:]
4✔
60
        for child in self.children:
4✔
61
            all_rows.extend(child.get_all_rows())
4✔
62
        return all_rows
4✔
63

64
    def _link_parent(self, parent: Optional["Tracer"]) -> None:
4✔
65
        if parent and (self not in parent.children):
4✔
66
            parent.children.append(self)
4✔
67

68
    def _unlink_parent(self, parent: Optional["Tracer"]) -> None:
4✔
69
        pass
4✔
70

71
    def _link_trace(self, trace) -> None:
4✔
72
        if trace not in self.traces:
4✔
73
            self.traces.append(trace)
4✔
74

75
    def _unlink_trace(self, trace) -> None:
4✔
76
        if self.keep_traces:
4✔
77
            return
4✔
78
        if trace in self.traces:
4✔
79
            self.traces.remove(trace)
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc