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
4918fae5
Unverified
Commit
4918fae5
authored
Jul 09, 2024
by
royjhan
Committed by
GitHub
Jul 09, 2024
Browse files
OpenAI v1/completions: allow stop token list (#5551)
* stop token parsing fix * add stop test
parent
0aff6787
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
openai/openai.go
openai/openai.go
+9
-5
openai/openai_test.go
openai/openai_test.go
+11
-0
No files found.
openai/openai.go
View file @
4918fae5
...
...
@@ -338,13 +338,17 @@ func fromCompleteRequest(r CompletionRequest) (api.GenerateRequest, error) {
switch
stop
:=
r
.
Stop
.
(
type
)
{
case
string
:
options
[
"stop"
]
=
[]
string
{
stop
}
case
[]
string
:
options
[
"stop"
]
=
stop
default
:
if
r
.
Stop
!=
nil
{
return
api
.
GenerateRequest
{},
fmt
.
Errorf
(
"invalid type for 'stop' field: %T"
,
r
.
Stop
)
case
[]
any
:
var
stops
[]
string
for
_
,
s
:=
range
stop
{
if
str
,
ok
:=
s
.
(
string
);
ok
{
stops
=
append
(
stops
,
str
)
}
else
{
return
api
.
GenerateRequest
{},
fmt
.
Errorf
(
"invalid type for 'stop' field: %T"
,
s
)
}
}
options
[
"stop"
]
=
stops
}
if
r
.
MaxTokens
!=
nil
{
options
[
"num_predict"
]
=
*
r
.
MaxTokens
...
...
openai/openai_test.go
View file @
4918fae5
...
...
@@ -79,6 +79,7 @@ func TestMiddlewareRequests(t *testing.T) {
Model
:
"test-model"
,
Prompt
:
"Hello"
,
Temperature
:
&
temp
,
Stop
:
[]
string
{
"
\n
"
,
"stop"
},
}
bodyBytes
,
_
:=
json
.
Marshal
(
body
)
...
...
@@ -99,6 +100,16 @@ func TestMiddlewareRequests(t *testing.T) {
if
genReq
.
Options
[
"temperature"
]
!=
1.6
{
t
.
Fatalf
(
"expected 1.6, got %f"
,
genReq
.
Options
[
"temperature"
])
}
stopTokens
,
ok
:=
genReq
.
Options
[
"stop"
]
.
([]
any
)
if
!
ok
{
t
.
Fatalf
(
"expected stop tokens to be a list"
)
}
if
stopTokens
[
0
]
!=
"
\n
"
||
stopTokens
[
1
]
!=
"stop"
{
t
.
Fatalf
(
"expected ['
\\
n', 'stop'], got %v"
,
stopTokens
)
}
},
},
}
...
...
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