goose-py 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {goose_py-0.2.0 → goose_py-0.2.2}/PKG-INFO +1 -1
- {goose_py-0.2.0 → goose_py-0.2.2}/goose/agent.py +19 -9
- {goose_py-0.2.0 → goose_py-0.2.2}/pyproject.toml +1 -1
- {goose_py-0.2.0 → goose_py-0.2.2}/README.md +0 -0
- {goose_py-0.2.0 → goose_py-0.2.2}/goose/__init__.py +0 -0
- {goose_py-0.2.0 → goose_py-0.2.2}/goose/errors.py +0 -0
- {goose_py-0.2.0 → goose_py-0.2.2}/goose/flow.py +0 -0
- {goose_py-0.2.0 → goose_py-0.2.2}/goose/py.typed +0 -0
@@ -2,7 +2,7 @@ import base64
|
|
2
2
|
import logging
|
3
3
|
from datetime import datetime
|
4
4
|
from enum import StrEnum
|
5
|
-
from typing import Any, Callable, ClassVar, Literal, NotRequired, TypedDict
|
5
|
+
from typing import Any, Awaitable, Callable, ClassVar, Literal, NotRequired, TypedDict
|
6
6
|
|
7
7
|
from litellm import acompletion
|
8
8
|
from pydantic import BaseModel, computed_field
|
@@ -125,14 +125,20 @@ class AgentResponse[R: BaseModel](BaseModel):
|
|
125
125
|
def duration_ms(self) -> int:
|
126
126
|
return int((self.end_time - self.start_time).total_seconds() * 1000)
|
127
127
|
|
128
|
+
@computed_field
|
129
|
+
@property
|
130
|
+
def input_cost(self) -> float:
|
131
|
+
return self.INPUT_CENTS_PER_MILLION_TOKENS[self.model] * self.input_tokens
|
132
|
+
|
133
|
+
@computed_field
|
134
|
+
@property
|
135
|
+
def output_cost(self) -> float:
|
136
|
+
return self.OUTPUT_CENTS_PER_MILLION_TOKENS[self.model] * self.output_tokens
|
137
|
+
|
128
138
|
@computed_field
|
129
139
|
@property
|
130
140
|
def total_cost(self) -> float:
|
131
|
-
|
132
|
-
output_cost = (
|
133
|
-
self.OUTPUT_CENTS_PER_MILLION_TOKENS[self.model] * self.output_tokens
|
134
|
-
)
|
135
|
-
return input_cost + output_cost
|
141
|
+
return self.input_cost + self.output_cost
|
136
142
|
|
137
143
|
|
138
144
|
class Agent:
|
@@ -141,11 +147,11 @@ class Agent:
|
|
141
147
|
*,
|
142
148
|
flow_name: str,
|
143
149
|
run_id: str,
|
144
|
-
logger: Callable[[AgentResponse[Any]], None] | None = None,
|
150
|
+
logger: Callable[[AgentResponse[Any]], Awaitable[None]] | None = None,
|
145
151
|
) -> None:
|
146
152
|
self.flow_name = flow_name
|
147
153
|
self.run_id = run_id
|
148
|
-
self.logger = logger
|
154
|
+
self.logger = logger
|
149
155
|
|
150
156
|
async def __call__[R: BaseModel](
|
151
157
|
self,
|
@@ -192,5 +198,9 @@ class Agent:
|
|
192
198
|
end_time=end_time,
|
193
199
|
)
|
194
200
|
|
195
|
-
self.logger
|
201
|
+
if self.logger is not None:
|
202
|
+
await self.logger(agent_response)
|
203
|
+
else:
|
204
|
+
logging.info(agent_response.model_dump())
|
205
|
+
|
196
206
|
return agent_response.response
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|