llama_index: [Bug]: Not able to make call to Ollama multimodal model in the cookbook

Bug Description

When I trying to follow the steps int the cookbook, I was getting an error saying that there’s a ResponseError: calling Ollama. However, I have installed Ollama successfully and was able to make model call via curl command. I suspect that this has something to do with http://localhost:11434.

Version

llama-index 0.9.44

Steps to Reproduce

Following the steps in the cookbook

from pydantic import BaseModel

class Restaurant(BaseModel):
    """Data model for an restaurant."""

    restaurant: str
    food: str
    discount: str
    price: str
    rating: str
    review: str

from llama_index.program import MultiModalLLMCompletionProgram
from llama_index.output_parsers import PydanticOutputParser

prompt_template_str = """\
{query_str}

Return the answer as a Pydantic object. The Pydantic schema is given below:

"""
mm_program = MultiModalLLMCompletionProgram.from_defaults(
    output_parser=PydanticOutputParser(Restaurant),
    image_documents=image_documents,
    prompt_template_str=prompt_template_str,
    multi_modal_llm=mm_model,
    verbose=True,
)

response = mm_program(query_str="Can you summarize what is in the image?")
for res in response:
    print(res)

Relevant Logs/Tracbacks

{ “name”: “ResponseError”, “message”: “”, “stack”: "--------------------------------------------------------------------------- ResponseError Traceback (most recent call last) Cell In[13], line 1 ----> 1 response = mm_program(query_str="Can you summarize what is in the image?") 2 for res in response: 3 print(res)

File /usr/local/lib/python3.11/site-packages/llama_index/program/multi_modal_llm_program.py:85, in MultiModalLLMCompletionProgram.call(self, llm_kwargs, *args, **kwargs) 82 llm_kwargs = llm_kwargs or {} 83 formatted_prompt = self._prompt.format(llm=self._multi_modal_llm, **kwargs) —> 85 response = self._multi_modal_llm.complete( 86 formatted_prompt, 87 image_documents=self._image_documents, 88 **llm_kwargs, 89 ) 91 raw_output = response.text 92 if self._verbose:

File /usr/local/lib/python3.11/site-packages/llama_index/multi_modal_llms/ollama.py:158, in OllamaMultiModal.complete(self, prompt, image_documents, formatted, **kwargs) 155 """Complete.""" 156 import ollama –> 158 response = ollama.generate( 159 model=self.model, 160 prompt=prompt, 161 images=image_documents_to_base64(image_documents), 162 stream=False, 163 options=self._model_kwargs, 164 ) 165 return CompletionResponse( 166 text=response["response"], 167 raw=response, 168 additional_kwargs=get_additional_kwargs(response, ("response",)), 169 )

File /usr/local/lib/python3.11/site-packages/ollama/_client.py:111, in Client.generate(self, model, prompt, system, template, context, stream, raw, format, images, options, keep_alive) 108 if not model: 109 raise RequestError(‘must provide a model’) –> 111 return self._request_stream( 112 ‘POST’, 113 ‘/api/generate’, 114 json={ 115 ‘model’: model, 116 ‘prompt’: prompt, 117 ‘system’: system, 118 ‘template’: template, 119 ‘context’: context or [], 120 ‘stream’: stream, 121 ‘raw’: raw, 122 ‘images’: [_encode_image(image) for image in images or []], 123 ‘format’: format, 124 ‘options’: options or {}, 125 ‘keep_alive’: keep_alive, 126 }, 127 stream=stream, 128 )

File /usr/local/lib/python3.11/site-packages/ollama/_client.py:82, in Client._request_stream(self, stream, *args, **kwargs) 76 def _request_stream( 77 self, 78 *args, 79 stream: bool = False, 80 **kwargs, 81 ) -> Union[Mapping[str, Any], Iterator[Mapping[str, Any]]]: —> 82 return self._stream(*args, **kwargs) if stream else self._request(*args, **kwargs).json()

File /usr/local/lib/python3.11/site-packages/ollama/_client.py:58, in Client._request(self, method, url, **kwargs) 56 response.raise_for_status() 57 except httpx.HTTPStatusError as e: —> 58 raise ResponseError(e.response.text, e.response.status_code) from None 60 return response

ResponseError: " }

About this issue

  • Original URL
  • State: open
  • Created 5 months ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

🤖

Thank you for providing detailed information about the issue you’re facing. The error you’re encountering is a ResponseError when calling the OllamaMultiModal.complete method. This error can occur due to several reasons, and I’ll try to guide you through some steps to identify and possibly resolve the issue.

  1. Ollama Installation: Please ensure that the Ollama package is correctly installed in your environment. You can verify this by running pip show ollama in your terminal. If it’s not installed, you can install it using pip install ollama.

  2. Model Validation: The OllamaMultiModal.complete method uses the model attribute of the OllamaMultiModal instance to generate a response. Please ensure that the model you’re using is valid and correctly configured.

  3. Prompt and Image Documents: The complete method also takes a prompt and image_documents as arguments. Make sure these are valid and correctly formatted. In your case, the prompt is “Can you summarize what is in the image?” and you should ensure that image_documents contains valid image data.

  4. Additional Model Parameters: The complete method uses additional model parameters (self._model_kwargs) in the ollama.generate call. If these parameters are not valid or not properly configured, it could lead to a ResponseError.

If you’ve checked all of these and the issue persists, it would be helpful to have more information about your setup. Specifically, the model you’re using, the format of your image documents, and any additional parameters you’re passing to the model. This will help in further diagnosing the issue.

For more information, you can refer to the source code of the OllamaMultiModal class in the LlamaIndex repository.

I hope this helps! Please let me know if you have any other questions or if there’s anything else I can assist you with.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@logan-markewich I can add it back