from ollama import chat def call_ollama_direct(prompt_text): """ Send the prompt to Ollama and return the model's reply. """ messages = [{"role": "user", "content": prompt_text}] try: response = chat(model="llama3", messages=messages) except Exception as e: return f"Error calling Ollama: {e}" if isinstance(response, dict): msg = response.get("message", {}) if isinstance(msg, dict): return msg.get("content", "") or str(response) return str(response) else: try: return response.message.content except Exception: return str(response) # to test # from ai_agent import call_ollama_direct print(call_ollama_direct("Give me a short greeting")) #to run ollama # ollama run llama3