goose-py 0.3.7__tar.gz → 0.3.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: goose-py
3
- Version: 0.3.7
3
+ Version: 0.3.9
4
4
  Summary: A tool for AI workflows based on human-computer collaboration and structured output.
5
5
  Home-page: https://github.com/chelle-ai/goose
6
6
  Keywords: ai,yaml,configuration,llm
@@ -150,12 +150,20 @@ class AgentResponse[R: BaseModel](BaseModel):
150
150
  @computed_field
151
151
  @property
152
152
  def input_cost(self) -> float:
153
- return self.INPUT_CENTS_PER_MILLION_TOKENS[self.model] * self.input_tokens
153
+ return (
154
+ self.INPUT_CENTS_PER_MILLION_TOKENS[self.model]
155
+ * self.input_tokens
156
+ / 1_000_000
157
+ )
154
158
 
155
159
  @computed_field
156
160
  @property
157
161
  def output_cost(self) -> float:
158
- return self.OUTPUT_CENTS_PER_MILLION_TOKENS[self.model] * self.output_tokens
162
+ return (
163
+ self.OUTPUT_CENTS_PER_MILLION_TOKENS[self.model]
164
+ * self.output_tokens
165
+ / 1_000_000
166
+ )
159
167
 
160
168
  @computed_field
161
169
  @property
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  from contextlib import asynccontextmanager
3
3
  from contextvars import ContextVar
4
+ from types import CodeType
4
5
  from typing import (
5
6
  Any,
6
7
  AsyncIterator,
@@ -65,6 +66,8 @@ class Conversation[R: Result](BaseModel):
65
66
 
66
67
 
67
68
  class IAdapter[ResultT: Result](Protocol):
69
+ __code__: CodeType
70
+
68
71
  async def __call__(self, *, conversation: Conversation[ResultT]) -> ResultT: ...
69
72
 
70
73
 
@@ -72,7 +75,7 @@ class NodeState[ResultT: Result](BaseModel):
72
75
  task_name: str
73
76
  index: int
74
77
  conversation: Conversation[ResultT]
75
- last_input_hash: int
78
+ last_hash: int
76
79
 
77
80
  @property
78
81
  def result(self) -> ResultT:
@@ -89,15 +92,15 @@ class NodeState[ResultT: Result](BaseModel):
89
92
  self,
90
93
  *,
91
94
  result: ResultT,
92
- new_input_hash: int | None = None,
95
+ new_hash: int | None = None,
93
96
  overwrite: bool = False,
94
97
  ) -> Self:
95
98
  if overwrite and len(self.conversation.result_messages) > 0:
96
99
  self.conversation.result_messages[-1] = result
97
100
  else:
98
101
  self.conversation.result_messages.append(result)
99
- if new_input_hash is not None:
100
- self.last_input_hash = new_input_hash
102
+ if new_hash is not None:
103
+ self.last_hash = new_hash
101
104
  return self
102
105
 
103
106
  def add_user_message(self, *, message: UserMessage) -> Self:
@@ -160,7 +163,7 @@ class FlowRun:
160
163
  conversation=Conversation[task.result_type](
161
164
  user_messages=[], result_messages=[]
162
165
  ),
163
- last_input_hash=0,
166
+ last_hash=0,
164
167
  )
165
168
 
166
169
  def start(
@@ -289,10 +292,10 @@ class Task[**P, R: Result]:
289
292
  async def generate(
290
293
  self, state: NodeState[R], *args: P.args, **kwargs: P.kwargs
291
294
  ) -> R:
292
- input_hash = self.__hash_input(*args, **kwargs)
293
- if input_hash != state.last_input_hash:
295
+ state_hash = self.__hash_task_call(*args, **kwargs)
296
+ if state_hash != state.last_hash:
294
297
  result = await self._generator(*args, **kwargs)
295
- state.add_result(result=result, new_input_hash=input_hash, overwrite=True)
298
+ state.add_result(result=result, new_hash=state_hash, overwrite=True)
296
299
  return result
297
300
  else:
298
301
  return state.result
@@ -326,9 +329,16 @@ class Task[**P, R: Result]:
326
329
  flow_run.add(node_state)
327
330
  return result
328
331
 
329
- def __hash_input(self, *args: P.args, **kwargs: P.kwargs) -> int:
332
+ def __hash_task_call(self, *args: P.args, **kwargs: P.kwargs) -> int:
330
333
  try:
331
- to_hash = str(tuple(args) + tuple(kwargs.values()))
334
+ to_hash = str(
335
+ tuple(args)
336
+ + tuple(kwargs.values())
337
+ + (
338
+ self._generator.__code__,
339
+ self._adapter.__code__ if self._adapter is not None else None,
340
+ )
341
+ )
332
342
  return hash(to_hash)
333
343
  except TypeError:
334
344
  raise Honk(f"Unhashable argument to task {self.name}: {args} {kwargs}")
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "goose-py"
3
- version = "0.3.7"
3
+ version = "0.3.9"
4
4
  description = "A tool for AI workflows based on human-computer collaboration and structured output."
5
5
  authors = [
6
6
  "Nash Taylor <nash@chelle.ai>",
File without changes
File without changes
File without changes
File without changes
File without changes