Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: request contextualisation - core functionality #65

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
21506e6
context logic subpackage; type-hint context extraction
Jun 21, 2024
a87e8e2
reworked type hint info extraction; extended functionality to also re…
ds-jakub-cierocki Jun 24, 2024
3ad4ecd
hidden args handling enabled
ds-jakub-cierocki Jun 24, 2024
b0cc0ae
improved type hints parsing and compatibility using package
ds-jakub-cierocki Jun 28, 2024
4ff5f62
dedicated exceptions for contex-related operations
ds-jakub-cierocki Jun 28, 2024
c479c50
useful classmethods for context-related operations
ds-jakub-cierocki Jun 28, 2024
e3bb127
make whole context utils module protected; added IQL parsing helper; …
ds-jakub-cierocki Jun 28, 2024
de72c7c
parsing type hints _extract_params_and_context() no longer excludes B…
ds-jakub-cierocki Jun 28, 2024
d3958c0
adjusted the existing code to be aware of contexts (promts yet untouc…
ds-jakub-cierocki Jun 28, 2024
be338bf
adjusted _type_validators.validate_arg_type() to handle typing.Union[]
ds-jakub-cierocki Jul 2, 2024
78f1535
context._utils._does_arg_allow_context() fix
ds-jakub-cierocki Jul 2, 2024
308e2e1
context record is now based on pydantic.BaseModel rather than datacla…
ds-jakub-cierocki Jul 2, 2024
73741d9
type hint lifting
ds-jakub-cierocki Jul 2, 2024
902f5ff
IQL generating LLM prompt passes BaseCallerContext() as filter argume…
ds-jakub-cierocki Jul 2, 2024
6309070
comments cleanup
ds-jakub-cierocki Jul 2, 2024
d523bf7
type hint fixes
ds-jakub-cierocki Jul 3, 2024
efe212f
Merge branch 'main' (which includes a large refactor by Michal) into …
ds-jakub-cierocki Jul 3, 2024
9ba89e5
post-merge fixes + minor refactor
ds-jakub-cierocki Jul 3, 2024
5fd802f
added missing docstrings; fixed type hints; fixed issues detected by …
ds-jakub-cierocki Jul 4, 2024
09bac55
reworked parse_param_type() function to increase performance, general…
ds-jakub-cierocki Jul 4, 2024
d42a369
fix: removed duplicated line from the prompt template
ds-jakub-cierocki Jul 4, 2024
c0b0522
adjusted existing unit tests to work with new contextualization logic
ds-jakub-cierocki Jul 4, 2024
9b2e131
linter-recommended fixes
ds-jakub-cierocki Jul 4, 2024
2d0ef4b
contextualization mechanism - dedicated unit tests
ds-jakub-cierocki Jul 5, 2024
6466f61
cleaned up overengineered code remanining from the previous iteration…
ds-jakub-cierocki Jul 5, 2024
637f7fa
replaced pydantic.BaseModel by dataclasses.dataclass, pydantic no lon…
ds-jakub-cierocki Jul 8, 2024
f867e25
BaseCallerContext: dataclass w.o. fields -> interface (abstract class…
ds-jakub-cierocki Jul 8, 2024
3423033
LLM now pastes Context() instead of BaseCallerContext() to indicate t…
ds-jakub-cierocki Jul 8, 2024
0d8cd1e
docstring typo fixes; more precise return type hint
ds-jakub-cierocki Jul 9, 2024
c97ba15
renamed Context() -> AskerContext(); added more detailed detailed exa…
ds-jakub-cierocki Jul 9, 2024
1294a9c
type hint parsing changes: SomeCustomContext -> AskerContext; Union[a…
ds-jakub-cierocki Jul 9, 2024
999759b
refactor: collection.results.[ViewExecutionResult, ExecutionResult]."…
ds-jakub-cierocki Jul 12, 2024
2e1005a
param type parsing: correctly handling builtins types with args (e.g.…
ds-jakub-cierocki Jul 12, 2024
820066d
type hint fix: explcitly marked BaseCallerContext.alias as typing.Cla…
ds-jakub-cierocki Jul 12, 2024
25fbfa6
docs + benchmarks adjusted to meet new naming [ExecutionResult, ViewE…
ds-jakub-cierocki Jul 15, 2024
a154577
redesigned context-not-available error to follow the same principles …
ds-jakub-cierocki Jul 15, 2024
623effd
EXPERIMENTAL: reworked context injection such it is handled immediate…
ds-jakub-cierocki Jul 15, 2024
afacf5b
additional unit tests for the new contextualization mechanism
ds-jakub-cierocki Jul 19, 2024
dd8b339
context benchmark script and data
ds-jakub-cierocki Jul 22, 2024
6bb0816
refactored main prompt (too long lines), missing end-of-line characters
ds-jakub-cierocki Jul 22, 2024
f388f92
better error handling
ds-jakub-cierocki Jul 22, 2024
fbecc51
context benchmark dataset fix
ds-jakub-cierocki Jul 23, 2024
5d4ff64
added polars-based accuracy summary to the benchmark
ds-jakub-cierocki Jul 23, 2024
e7e8826
adjusted prompt to reduce halucinations: nested filter/context calls …
ds-jakub-cierocki Jul 23, 2024
f8bf64e
merged main (inc. new benchmarks + large refactor) -> jc/issue-54-req…
ds-jakub-cierocki Aug 7, 2024
c1c871b
merge main
micpst Sep 23, 2024
8eefd9b
fix linters
micpst Sep 23, 2024
c28091f
fix tests
micpst Sep 23, 2024
69a8d58
fix tests
micpst Sep 23, 2024
d6c8fc6
fix tests
micpst Sep 23, 2024
d7026d4
rm old benchmarks
micpst Sep 23, 2024
e8271ac
some renames and stuff
micpst Sep 23, 2024
bdcc7b3
fix benchmarks
micpst Sep 23, 2024
71f53be
merge main
micpst Sep 25, 2024
c82e579
rm chroma file
micpst Sep 25, 2024
f5a40cb
add contexts to benchmarks + fix types
micpst Sep 30, 2024
fab9d3f
small refactor
micpst Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reworked parse_param_type() function to increase performance, general…
…ity and properly handle types: Union[Type1, Type2, ...], __main__.SomeCustomClass
  • Loading branch information
ds-jakub-cierocki committed Jul 4, 2024
commit 09bac55b1b25bedc6e86176c1b1cb3e65844d794
34 changes: 27 additions & 7 deletions src/dbally/views/exposed_functions.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
import re
from dataclasses import dataclass
from inspect import isclass
from typing import _GenericAlias # type: ignore
from typing import Optional, Sequence, Type, Union

import typing_extensions as type_ext

from dbally.context.context import BaseCallerContext
from dbally.similarity import AbstractSimilarityIndex


def parse_param_type(param_type: Union[type, _GenericAlias]) -> str:
def parse_param_type(param_type: Union[type, _GenericAlias, str]) -> str:
"""
Parses the type of a method parameter and returns a string representation of it.

Args:
param_type: type of the parameter
param_type: Type of the parameter.

Returns:
str: string representation of the type
A string representation of the type.
"""
if param_type in {int, float, str, bool, list, dict, set, tuple}:

# TODO consider using hasattr() to ensure correctness of the IF's below
if isclass(param_type):
return param_type.__name__
if param_type.__module__ == "typing":
return re.sub(r"\btyping\.", "", str(param_type))

# typing.Literal['aaa', 'bbb'] edge case handler
# the args are strings not types thus isclass('aaa') is False
# at the same type string has no __module__ property which causes an error
if isinstance(param_type, str):
return f"'{param_type}'"

if param_type.__module__ == "typing" or param_type.__module__ == "typing_extensions":
type_args = type_ext.get_args(param_type)
if type_args:
param_name = param_type._name # pylint: disable=protected-access
if param_name is None:
# workaround for typing.Literal, because: `typing.Literal['aaa', 'bbb']._name is None`
# but at the same time: `type_ext.get_origin(typing.Literal['aaa', 'bbb'])._name == "Literal"`
param_name = type_ext.get_origin(param_type)._name # pylint: disable=protected-access

args_str_repr = ", ".join(parse_param_type(arg) for arg in type_args)
return f"{param_name}[{args_str_repr}]"

return str(param_type)

Expand Down