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
opencompass
Commits
3b29aaee
Unverified
Commit
3b29aaee
authored
Aug 21, 2023
by
philipwangOvO
Committed by
GitHub
Aug 21, 2023
Browse files
[Fix] bin_trim (#237)
Co-authored-by:
wangchonghua
<
wangchonghua@pjlab.org.cn
>
parent
655a807f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
opencompass/models/openai_api.py
opencompass/models/openai_api.py
+8
-6
No files found.
opencompass/models/openai_api.py
View file @
3b29aaee
...
...
@@ -281,18 +281,20 @@ class OpenAI(BaseAPIModel):
pattern
=
re
.
compile
(
r
'[\u4e00-\u9fa5]'
)
if
pattern
.
search
(
prompt
):
words
=
list
(
jieba
.
cut
(
prompt
,
cut_all
=
False
))
sep
=
''
else
:
words
=
prompt
.
split
(
' '
)
sep
=
' '
l
,
r
=
1
,
len
(
words
)
while
l
+
2
<
r
:
mid
=
(
l
+
r
)
//
2
if
self
.
mode
==
'front'
:
cur_prompt
=
' '
.
join
(
words
[
-
mid
:])
cur_prompt
=
sep
.
join
(
words
[
-
mid
:])
elif
self
.
mode
==
'mid'
:
cur_prompt
=
' '
.
join
(
words
[:
mid
])
+
' '
.
join
(
words
[
-
mid
:])
cur_prompt
=
sep
.
join
(
words
[:
mid
])
+
sep
.
join
(
words
[
-
mid
:])
elif
self
.
mode
==
'rear'
:
cur_prompt
=
' '
.
join
(
words
[:
mid
])
cur_prompt
=
sep
.
join
(
words
[:
mid
])
if
self
.
get_token_len
(
cur_prompt
)
<=
num_token
:
l
=
mid
# noqa: E741
...
...
@@ -300,9 +302,9 @@ class OpenAI(BaseAPIModel):
r
=
mid
if
self
.
mode
==
'front'
:
prompt
=
' '
.
join
(
words
[
-
l
:])
prompt
=
sep
.
join
(
words
[
-
l
:])
elif
self
.
mode
==
'mid'
:
prompt
=
' '
.
join
(
words
[:
l
])
+
' '
.
join
(
words
[
-
l
:])
prompt
=
sep
.
join
(
words
[:
l
])
+
sep
.
join
(
words
[
-
l
:])
elif
self
.
mode
==
'rear'
:
prompt
=
' '
.
join
(
words
[:
l
])
prompt
=
sep
.
join
(
words
[:
l
])
return
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