Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
evoprompt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Grießhaber Daniel
evoprompt
Commits
13b82620
Commit
13b82620
authored
7 months ago
by
Grießhaber Daniel
Browse files
Options
Downloads
Patches
Plain Diff
refactor _call_model_cached function implementation
parent
7420ba00
No related branches found
No related tags found
2 merge requests
!2
remove is_chat argument
,
!1
Refactor models
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
evoprompt/models.py
+9
-9
9 additions, 9 deletions
evoprompt/models.py
with
9 additions
and
9 deletions
evoprompt/models.py
+
9
−
9
View file @
13b82620
...
@@ -44,11 +44,16 @@ class LLMModel(ABC):
...
@@ -44,11 +44,16 @@ class LLMModel(ABC):
self
.
kwargs
=
kwargs
self
.
kwargs
=
kwargs
# set up caching for model calls
# set up caching for model calls
self
.
_call_model_cached
=
None
if
not
options
.
disable_cache
:
if
not
options
.
disable_cache
:
cache
=
Cache
(
Path
(
"
.cache_dir
"
,
self
.
model_cache_key
))
cache
=
Cache
(
Path
(
"
.cache_dir
"
,
self
.
model_cache_key
))
self
.
_call_model_cached
=
cache
.
memoize
(
typed
=
True
,
ignore
=
[
0
,
"
func
"
])(
self
.
_call_model_cached
@cache.memoize
(
typed
=
True
,
ignore
=
[
"
func
"
])
)
def
_call_function
(
func
,
*
args
,
**
kwargs
):
# `cache_key` is added to the cache key (e.g., to distinguish between different models), but it is not used in the function
return
func
(
*
args
,
**
kwargs
)
self
.
_call_model_cached
=
_call_function
@abstractmethod
@abstractmethod
def
build_model_input
(
def
build_model_input
(
...
@@ -114,16 +119,11 @@ class LLMModel(ABC):
...
@@ -114,16 +119,11 @@ class LLMModel(ABC):
warnings
.
warn
(
"
Caching is disabled when a grammar is provided.
"
)
warnings
.
warn
(
"
Caching is disabled when a grammar is provided.
"
)
use_cache
=
False
use_cache
=
False
if
use_cache
:
if
use_cache
and
self
.
_call_model_cached
is
not
None
:
# use cached function call
return
self
.
_call_model_cached
(
model_completion_fn
,
**
kwargs
)
return
self
.
_call_model_cached
(
model_completion_fn
,
**
kwargs
)
else
:
else
:
return
model_completion_fn
(
**
kwargs
)
return
model_completion_fn
(
**
kwargs
)
def
_call_model_cached
(
self
,
func
,
*
args
,
**
kwargs
):
# `cache_key` is added to the cache key (e.g., to distinguish between different models), but it is not used in the function
return
func
(
*
args
,
**
kwargs
)
@property
@property
def
model_cache_key
(
self
):
def
model_cache_key
(
self
):
unique_options_key
=
json
.
dumps
(
unique_options_key
=
json
.
dumps
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment