Originally created by @denlogv on GitHub (Jan 4, 2024).
Is your feature request related to a problem? Please describe.
I am trying to use Ollama-WebUI for a custom Langchain pipeline, but am having problems conforming with what the JS backend expects as a response, as it appears very strict about it. I implemented a "proxy" server (FastAPI) that has a generic router for all paths and methods and adds some custom logic to /api_tags and /api/generate endpoints. To simulate responses from Ollama, I use EventSourceResponses of the following form:
It works well when just routing responses from Ollama, but when using a pipeline, this server sometimes sends other events such as ping messages, which Ollama WebUI backend doesn't handle, as it tries to parse them as if they were "normal" responses from Ollama, which causes the backend to break from the IO loop:
try {
let S = ce.split(`
`);
for (const P of S)
if (P !== "") {
console.log(P);
let R = JSON.parse(P);
if (R.done == !1) {
if (h.content == "" && R.response == `
`)
continue;
h.content += R.response,
s(7, l),
s(1, n)
} else {
if ("detail"in R)
throw R;
h.done = !0,
h.context = R.context,
s(7, l),
s(1, n)
}
}
} catch (S) {
console.log(S),
"detail"in S && fe.error(S.detail);
break
}
Describe the solution you'd like
Could you maybe just ignore such responses instead of breaking from the loop? I am not sure how to add some sort of middleware for events that would filter out everything that doesn't look like Ollama responses. Or maybe you have an idea of how to do that?
PS
Also, what it is the recommended way to debug this application?
Originally created by @denlogv on GitHub (Jan 4, 2024).
**Is your feature request related to a problem? Please describe.**
I am trying to use Ollama-WebUI for a custom Langchain pipeline, but am having problems conforming with what the JS backend expects as a response, as it appears very strict about it. I implemented a "proxy" server (FastAPI) that has a generic router for all paths and methods and adds some custom logic to `/api_tags` and `/api/generate` endpoints. To simulate responses from Ollama, I use EventSourceResponses of the following form:
```
async def api_generate_code_qa(payload):
chat_answer_generator = await chat_qa(question=payload['prompt'], first_line_keywords=True)
return EventSourceResponse(
esr_chat_answer_generator(chat_answer_generator, payload=payload),
ping_message_factory=lambda: ServerSentEvent(),
ping=60
)
```
It works well when just routing responses from Ollama, but when using a pipeline, this server sometimes sends other events such as ping messages, which Ollama WebUI backend doesn't handle, as it tries to parse them as if they were "normal" responses from Ollama, which causes the backend to break from the IO loop:
```
try {
let S = ce.split(`
`);
for (const P of S)
if (P !== "") {
console.log(P);
let R = JSON.parse(P);
if (R.done == !1) {
if (h.content == "" && R.response == `
`)
continue;
h.content += R.response,
s(7, l),
s(1, n)
} else {
if ("detail"in R)
throw R;
h.done = !0,
h.context = R.context,
s(7, l),
s(1, n)
}
}
} catch (S) {
console.log(S),
"detail"in S && fe.error(S.detail);
break
}
```
**Describe the solution you'd like**
Could you maybe just ignore such responses instead of breaking from the loop? I am not sure how to add some sort of middleware for events that would filter out everything that doesn't look like Ollama responses. Or maybe you have an idea of how to do that?
**PS**
Also, what it is the recommended way to debug this application?
Hi, Thanks for the suggestion! We won't be modifying the frontend code as we can't be 100% sure if there would not be any side effects, but maybe the community can help you out with your backend code. I'll move this post to discussion, Thanks!
@tjbck commented on GitHub (Jan 5, 2024):
Hi, Thanks for the suggestion! We won't be modifying the frontend code as we can't be 100% sure if there would not be any side effects, but maybe the community can help you out with your backend code. I'll move this post to discussion, Thanks!
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @denlogv on GitHub (Jan 4, 2024).
Is your feature request related to a problem? Please describe.
I am trying to use Ollama-WebUI for a custom Langchain pipeline, but am having problems conforming with what the JS backend expects as a response, as it appears very strict about it. I implemented a "proxy" server (FastAPI) that has a generic router for all paths and methods and adds some custom logic to
/api_tagsand/api/generateendpoints. To simulate responses from Ollama, I use EventSourceResponses of the following form:It works well when just routing responses from Ollama, but when using a pipeline, this server sometimes sends other events such as ping messages, which Ollama WebUI backend doesn't handle, as it tries to parse them as if they were "normal" responses from Ollama, which causes the backend to break from the IO loop:
Describe the solution you'd like
Could you maybe just ignore such responses instead of breaking from the loop? I am not sure how to add some sort of middleware for events that would filter out everything that doesn't look like Ollama responses. Or maybe you have an idea of how to do that?
PS
Also, what it is the recommended way to debug this application?
@tjbck commented on GitHub (Jan 5, 2024):
Hi, Thanks for the suggestion! We won't be modifying the frontend code as we can't be 100% sure if there would not be any side effects, but maybe the community can help you out with your backend code. I'll move this post to discussion, Thanks!