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
ee94693b
Commit
ee94693b
authored
Oct 16, 2023
by
Arne Müller
Browse files
handling unescaped json marshaling
parent
06bcfbd6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
llm/llama.go
llm/llama.go
+10
-3
No files found.
llm/llama.go
View file @
ee94693b
...
@@ -544,11 +544,18 @@ func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string,
...
@@ -544,11 +544,18 @@ func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string,
Stop
:
llm
.
Stop
,
Stop
:
llm
.
Stop
,
}
}
data
,
err
:=
json
.
Marshal
(
predReq
)
// Handling JSON marshaling with special characters unescaped.
if
err
!=
nil
{
buf
:=
&
bytes
.
Buffer
{}
return
fmt
.
Errorf
(
"error marshaling data: %v"
,
err
)
enc
:=
json
.
NewEncoder
(
buf
)
enc
.
SetEscapeHTML
(
false
)
if
err
:=
enc
.
Encode
(
predReq
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to marshal data: %v"
,
err
)
}
}
// Remove trailing newline added by Encode.
data
:=
buf
.
Bytes
()[
:
buf
.
Len
()
-
1
]
req
,
err
:=
http
.
NewRequestWithContext
(
ctx
,
http
.
MethodPost
,
endpoint
,
bytes
.
NewBuffer
(
data
))
req
,
err
:=
http
.
NewRequestWithContext
(
ctx
,
http
.
MethodPost
,
endpoint
,
bytes
.
NewBuffer
(
data
))
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error creating POST request: %v"
,
err
)
return
fmt
.
Errorf
(
"error creating POST request: %v"
,
err
)
...
...
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