From 9317df7f16e04f9227fc71c8432bcfc330784afb Mon Sep 17 00:00:00 2001 From: "P. Taylor Goetz" Date: Fri, 12 Apr 2024 13:32:53 -0400 Subject: [PATCH] community[patch]: Add "model" attribute to the payload sent to Ollama in `ChatOllama` (#20354) Example Ollama API calls: Request without "model": ``` curl --location 'http://localhost:11434/api/chat' \ --header 'Content-Type: application/json' \ --data '{ "messages": [ { "role": "user", "content": "What is the capitol of PA?" } ], "stream": false }' ``` Response: ``` {"error":"model is required"} ``` Request with "model": ``` curl --location 'http://localhost:11434/api/chat' \ --header 'Content-Type: application/json' \ --data '{ "model": "openchat", "messages": [ { "role": "user", "content": "What is the capitol of PA?" } ], "stream": false }' ``` Response: ``` { "eval_duration" : 733248000, "created_at" : "2024-04-11T23:04:08.735766843Z", "model" : "openchat", "message" : { "content" : " The capital city of Pennsylvania is Harrisburg.", "role" : "assistant" }, "total_duration" : 3138731168, "prompt_eval_count" : 25, "load_duration" : 466562959, "done" : true, "prompt_eval_duration" : 1938495000, "eval_count" : 10 } ``` --- libs/community/langchain_community/chat_models/ollama.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/community/langchain_community/chat_models/ollama.py b/libs/community/langchain_community/chat_models/ollama.py index 1562a698451..5e5a98f8ae0 100644 --- a/libs/community/langchain_community/chat_models/ollama.py +++ b/libs/community/langchain_community/chat_models/ollama.py @@ -156,6 +156,7 @@ class ChatOllama(BaseChatModel, _OllamaCommon): **kwargs: Any, ) -> Iterator[str]: payload = { + "model": self.model, "messages": self._convert_messages_to_ollama_messages(messages), } yield from self._create_stream( @@ -169,6 +170,7 @@ class ChatOllama(BaseChatModel, _OllamaCommon): **kwargs: Any, ) -> AsyncIterator[str]: payload = { + "model": self.model, "messages": self._convert_messages_to_ollama_messages(messages), } async for stream_resp in self._acreate_stream(