code: def get_ollama_response(
      api_base="http://localhost:11434",
      model="llama2",
      messages=None,
      optional_params=None,
      logging_obj=None,
      acompletion: bool = False,
      model_response=None,
      encoding=None,
  ):
      if api_base.endswith("/api/chat"):
          url = api_base
      else:
          url = f"{api_base}/api/chat"
  
      ## Load Config
      config = litellm.OllamaConfig.get_config()
      for k, v in config.items():
          if (
              k not in optional_params
          ):  # completion(top_k=3) > cohere_config(top_k=3) <- allows for dynamic variables to be passed in
              optional_params[k] = v
  
      optional_params["stream"] = optional_params.get("stream", False)
      data = {"model": model, "messages": messages, **optional_params}
      ## LOGGING
      logging_obj.pre_call(
          input=None,
          api_key=None,
          additional_args={
              "api_base": url,
              "complete_input_dict": data,
              "headers": {},
              "acompletion": acompletion,
          },
      )
      if acompletion is True:
          if optional_params.get("stream", False) == True:
              response = ollama_async_streaming(
                  url=url,
                  data=data,
                  model_response=model_response,
                  encoding=encoding,
                  logging_obj=logging_obj,
              )
          else:
              response = ollama_acompletion(
                  url=url,
                  data=data,
                  model_response=model_response,
                  encoding=encoding,
                  logging_obj=logging_obj,
              )
          return response
      elif optional_params.get("stream", False) == True:
          return ollama_completion_stream(
              url=url, data=data, logging_obj=logging_obj
          )
  
      response = requests.post(
          url=f"{url}",
          json=data,
      )
      if response.status_code != 200:
          raise OllamaError(
              status_code=response.status_code, message=response.text
          )
  
      ## LOGGING
      logging_obj.post_call(
          input=messages,
          api_key="",
          original_response=response.text,
          additional_args={
              "headers": None,
              "api_base": api_base,
          },
      )
  
      response_json = response.json()
  
      ## RESPONSE OBJECT
      model_response["choices"][0]["finish_reason"] = "stop"
      if data.get("format", "") == "json":
          message = litellm.Message(
              content=None,
              tool_calls=[
                  {
                      "id": f"call_{str(uuid.uuid4())}",
                      "function": {
                          "arguments": response_json["message"][
                              "content"
                          ],
                          "name": "",
                      },
                      "type": "function",
                  }
              ],
          )
          model_response["choices"][0]["message"] = message
      else:
          model_response["choices"][0]["message"] = response_json[
              "message"
          ]
      model_response["created"] = int(time.time())
      model_response["model"] = "ollama/" + model
      prompt_tokens = response_json["prompt_eval_count"]  # type: ignore
      completion_tokens = response_json["eval_count"]
      model_response["usage"] = litellm.Usage(
          prompt_tokens=prompt_tokens,
          completion_tokens=completion_tokens,
          total_tokens=prompt_tokens + completion_tokens,
      )
      return model_response
  
file_path: litellm/litellm/llms/ollama_chat.py
imports: import requests, types, time
  import json, uuid
  import traceback
  from typing import Optional
  import litellm
  import httpx, aiohttp, asyncio
  from .prompt_templates.factory import prompt_factory, custom_prompt
label_desc: Use image node_id 1 for calling a global function with example usage: get_ollama_response(api_base, model, messages, optional_params, logging_obj, acompletion, model_response, encoding) and returns: model_response, response, ollama_completion_stream