Skip to content

Commit

Permalink
fix(agents-api): Fix e.token_count None
Browse files Browse the repository at this point in the history
Signed-off-by: Diwank Singh Tomer <[email protected]>
  • Loading branch information
creatorrr committed Apr 25, 2024
1 parent 08fca77 commit e099480
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
2 changes: 1 addition & 1 deletion agents-api/agents_api/routers/sessions/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def rm_thoughts(m):
def rm_user_assistant(m):
return m.role in ("user", "assistant")

token_count = reduce(lambda c, e: e.token_count + c, messages, 0)
token_count = reduce(lambda c, e: (e.token_count or 0) + c, messages, 0)

if token_count <= summarization_tokens_threshold:
return messages
Expand Down
2 changes: 1 addition & 1 deletion agents-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poe.tasks]
format = "black ."
lint = "ruff agents_api/**/*.py migrations/**/*.py tests/**/*.py --fix --unsafe-fixes"
typecheck = "pytype -j auto -k agents_api"
typecheck = "pytype --config pytype.toml"
check = [
"format",
"lint",
Expand Down
91 changes: 91 additions & 0 deletions agents-api/pytype.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# NOTE: All relative paths are relative to the location of this file.

[tool.pytype]

# Space-separated list of files or directories to exclude.
exclude = [
'**/*_test.py',
'**/test_*.py',
]

# Space-separated list of files or directories to process.
inputs = [
'agents_api',
]

# Keep going past errors to analyze as many files as possible.
keep_going = true

# Run N jobs in parallel. When 'auto' is used, this will be equivalent to the
# number of CPUs on the host system.
jobs = 'auto'

# All pytype output goes here.
output = '.pytype'

# Platform (e.g., "linux", "win32") that the target code runs on.
platform = 'linux'

# Paths to source code directories, separated by ':'.
pythonpath = '.'

# Python version (major.minor) of the target code.
python_version = '3.10'

# Bind 'self' in methods with non-transparent decorators. This flag is temporary
# and will be removed once this behavior is enabled by default.
bind_decorated_methods = true

# Don't allow None to match bool. This flag is temporary and will be removed
# once this behavior is enabled by default.
none_is_not_bool = false

# Enable parameter count checks for overriding methods with renamed arguments.
# This flag is temporary and will be removed once this behavior is enabled by
# default.
overriding_renamed_parameter_count_checks = true

# Variables initialized as None retain their None binding. This flag is
# temporary and will be removed once this behavior is enabled by default.
strict_none_binding = true

# Support the third-party fiddle library. This flag is temporary and will be
# removed once this behavior is enabled by default.
use_fiddle_overlay = true

# Opt-in: Do not allow Any as a return type.
no_return_any = false

# Opt-in: Require decoration with @typing.override when overriding a method or
# nested class attribute of a parent class.
require_override_decorator = false

# Experimental: Infer precise return types even for invalid function calls.
precise_return = true

# Experimental: Solve unknown types to label with structural types.
protocols = false

# Experimental: Only load submodules that are explicitly imported.
strict_import = true

# Experimental: Enable exhaustive checking of function parameter types.
strict_parameter_checks = false

# Experimental: Emit errors for comparisons between incompatible primitive
# types.
strict_primitive_comparisons = false

# Experimental: Check that variables are defined in all possible code paths.
strict_undefined_checks = false

# Experimental: FOR TESTING ONLY. Use pytype/rewrite/.
use_rewrite = false

# Space-separated list of error names to ignore.
disable = [
'pyi-error',
]

# Don't report errors.
report_errors = true

0 comments on commit e099480

Please sign in to comment.