Ollama-Specific Parameters in ClientAI¶
This guide covers the Ollama-specific parameters that can be passed to ClientAI's generate_text
and chat
methods. These parameters are passed as additional keyword arguments to customize Ollama's behavior.
generate_text Method¶
Basic Structure¶
from clientai import ClientAI
client = ClientAI('ollama')
response = client.generate_text(
prompt="Your prompt here", # Required
model="llama2", # Required
suffix="Optional suffix", # Ollama-specific
system="System message", # Ollama-specific
template="Custom template", # Ollama-specific
context=[1, 2, 3], # Ollama-specific
format="json", # Ollama-specific
options={"temperature": 0.7}, # Ollama-specific
keep_alive="5m" # Ollama-specific
)
Ollama-Specific Parameters¶
suffix: str
¶
- Text to append to the generated output
system: str
¶
- System message to guide the model's behavior
template: str
¶
- Custom prompt template
context: List[int]
¶
- Context from previous interactions
format: Literal['', 'json']
¶
- Controls response format
options: Optional[Options]
¶
- Model-specific parameters
keep_alive: Optional[Union[float, str]]
¶
- Model memory retention duration
chat Method¶
Basic Structure¶
response = client.chat(
model="llama2", # Required
messages=[...], # Required
tools=[...], # Ollama-specific
format="json", # Ollama-specific
options={"temperature": 0.7}, # Ollama-specific
keep_alive="5m" # Ollama-specific
)
Ollama-Specific Parameters¶
tools: Optional[List[Dict]]
¶
- Tools available for the model (requires stream=False)
response = client.chat( model="llama2", messages=[{"role": "user", "content": "What's 2+2?"}], tools=[{ "type": "function", "function": { "name": "calculate", "description": "Perform basic math", "parameters": { "type": "object", "properties": { "expression": {"type": "string"} } } } }], stream=False )
format: Literal['', 'json']
¶
- Controls response format
options: Optional[Options]
¶
- Model-specific parameters
keep_alive: Optional[Union[float, str]]
¶
- Model memory retention duration
Complete Examples¶
Example 1: Creative Writing with generate_text¶
response = client.generate_text(
prompt="Write a short story about AI",
model="llama2",
system="You are a creative writer specializing in science fiction",
template="Story prompt: {{.Prompt}}\n\nCreative story:",
options={
"temperature": 0.9,
"top_p": 0.95
},
suffix="\n\nThe End.",
keep_alive="10m"
)
Example 2: JSON Response with chat¶
messages = [
{"role": "system", "content": "You are a helpful assistant that provides structured data"},
{"role": "user", "content": "List 3 programming languages with their key features"}
]
response = client.chat(
model="llama2",
messages=messages,
format="json",
options={
"temperature": 0.3, # Lower temperature for more structured output
"top_p": 0.9
}
)
Example 3: Multimodal Chat with Image¶
messages = [
{
"role": "user",
"content": "What's in this image?",
"images": ["encoded_image_data_or_path"]
}
]
response = client.chat(
model="llava",
messages=messages,
format="json",
keep_alive="5m"
)
Example 4: Contextual Generation¶
# First generation
first_response = client.generate_text(
prompt="Write the beginning of a mystery story",
model="llama2",
options={"temperature": 0.8}
)
# Continue the story using context
continued_response = client.generate_text(
prompt="Continue the story with a plot twist",
model="llama2",
context=first_response.context,
options={"temperature": 0.8}
)
Parameter Validation Notes¶
- Both
model
andprompt
/messages
are required - When using
tools
,stream
must beFalse
format
only accepts''
or'json'
- Image support requires multimodal models (e.g., llava)
- Context preservation works only with
generate_text
- Keep alive duration can be string (e.g., "5m") or float (seconds)
These parameters allow you to fully customize Ollama's behavior while working with ClientAI's abstraction layer.