miurla / morphic

An AI-powered search engine with a generative UI
https://morphic.sh
Apache License 2.0
6.04k stars 1.51k forks source link

feat(utils): Add Ollama support and improve error handling for models #190

Closed peperunas closed 3 months ago

peperunas commented 4 months ago

This PR introduces support for Ollama and also refactors the existing model initialization to improve readability and maintainability.


vercel[bot] commented 4 months ago

@peperunas is attempting to deploy a commit to the morphic Team on Vercel.

A member of the Team first needs to authorize it.

peperunas commented 4 months ago

I'm still testing the PR - as of now, Tavily seems to be down so I cannot test it any further.

I'll convert it from a draft PR when I'm ready for review / merge.

miurla commented 4 months ago

@peperunas It's great that Ollama is usable!

However, there seems to be a issue with Object generation and Tool streaming. Does it seem to work well? It'd be helpful if you could tell me about the models you tested.

https://github.com/sgomez/ollama-ai-provider?tab=readme-ov-file#tested-models-and-capabilities

peperunas commented 4 months ago

I was able to test this morning - as Tavily was back online - but there is a blocking issue with Ollama.

Ollama does not support the tool role: https://github.com/ollama/ollama/issues/3165. For this reason, once the results are then passed to the Agent, we get an error back:

Error: Unsupported role: tool

image
miurla commented 4 months ago

That's good. If Ollama has managed to make the tool calls successfully, it would be good to convert the Tool's message to Assistant before generating the answer. Just yesterday, I turned it into a utility function and merged it into main.

https://github.com/miurla/morphic/blob/main/app/actions.tsx#L168

peperunas commented 4 months ago

I see, thanks @miurla.

I set USE_SPECIFIC_API to true and removed the hardcoded writer to retrieve the model via getModel(); still no luck.

Also, I am confused on the nomenclature: what is a "specific API" in the code?

Anyhow, I guess that - by making the code more robust and less reliant on OpenAI alone - Morphic should start working.

miurla commented 4 months ago

I created a draft PR with the commits to your PR. Please check it: #200

  1. Fix the error Unsupported role: tool: https://github.com/miurla/morphic/pull/200/commits/2e0edc3da1368e921a90b449188587bf4449e396

  2. For tool usage and object generation, mistral or openhermes is recommended, but the text generation was not sufficient. Only for that part, a different model was used as a sub model: https://github.com/miurla/morphic/pull/200/commits/5df77b973ea3abc123c9993d6f1dfa66837f3808

However, it does not work stably. It will be supported only as an experimental feature.

mistral mistral & phi3
image image
peperunas commented 3 months ago

Closed in favor of #214