Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
ba3cbbbb
Commit
ba3cbbbb
authored
Jun 29, 2023
by
Michael Yang
Browse files
use difflib.get_close_matches
parent
e69a08f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
13 deletions
+3
-13
ollama/prompt.py
ollama/prompt.py
+3
-13
No files found.
ollama/prompt.py
View file @
ba3cbbbb
from
os
import
path
from
difflib
import
get_close_matches
from
difflib
import
SequenceMatcher
from
jinja2
import
Environment
,
PackageLoader
from
jinja2
import
Environment
,
PackageLoader
def
template
(
name
,
prompt
):
def
template
(
name
,
prompt
):
best_ratio
=
0
best_template
=
''
environment
=
Environment
(
loader
=
PackageLoader
(
__name__
,
'templates'
))
environment
=
Environment
(
loader
=
PackageLoader
(
__name__
,
'templates'
))
for
template
in
environment
.
list_templates
():
best_templates
=
get_close_matches
(
name
,
environment
.
list_templates
(),
n
=
1
,
cutoff
=
0
)
base
,
_
=
path
.
splitext
(
template
)
template
=
environment
.
get_template
(
best_templates
.
pop
())
ratio
=
SequenceMatcher
(
None
,
path
.
basename
(
name
).
lower
(),
base
).
ratio
()
if
ratio
>
best_ratio
:
best_ratio
=
ratio
best_template
=
template
template
=
environment
.
get_template
(
best_template
)
return
template
.
render
(
prompt
=
prompt
)
return
template
.
render
(
prompt
=
prompt
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment