AI Ollama LlamaIndex

parmarjatin4911@gmail.com - Jan 28 - - Dev Community

AI Ollama LlamaIndex

Basic

from llama_index.llms import Ollama

Initialize the model

llm = Ollama(model="mistral")

response = llm.complete("Write a cover letter.")

print(response)

Basic Streaming

from llama_index.llms import Ollama

Initialize the model

llm = Ollama(model="mistral")

response = llm.stream_complete("Write a cover letter.")

for r in response:
print(r.delta, end="")

Chat

from llama_index.llms import Ollama
from llama_index.llms import ChatMessage

Initialize the model

llm = Ollama(model="mistral")

messages = [
ChatMessage(
role="system", content="You are helpful assistant to create programs"
),
ChatMessage(role="user", content="Write a python program to calculate the sum of two numbers"),
]

response = llm.chat(messages)
print(response)

Chat Streaming

from llama_index.llms import Ollama
from llama_index.llms import ChatMessage

Initialize the model

llm = Ollama(model="mistral")

messages = [
ChatMessage(
role="system", content="You are helpful assistant to create programs"
),
ChatMessage(role="user", content="Write a python program to calculate the sum of two numbers"),
]

response = llm.stream_chat(messages)
for r in response:
print(r.delta, end="")

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player