You can include a system prompt to set the behavior and context for the model. System messages help guide the model’s responses and can be used to set specific instructions, tone, or expertise areas.

Basic System Prompt

Here’s how to include a system prompt in your chat completion request:

from openai import OpenAI

client = OpenAI(
    api_key="your_truefoundry_api_key",
    base_url="<truefoundry-base-url>/api/llm/api/inference/openai"
)

response = client.chat.completions.create(
    model="openai-main/gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant that specializes in Python programming."},
        {"role": "user", "content": "How do I write a function to calculate factorial?"}
    ]
)

print(response.choices[0].message.content) 

Best Practices

  • Be specific: Clearly define the role and expertise area of the assistant
  • Set tone: Specify whether you want formal, casual, technical, or friendly responses
  • Define constraints: Include any limitations or guidelines the model should follow
  • Provide context: Give background information that helps the model understand the domain

Examples

Technical Assistant

system_prompt = """You are a senior software engineer specializing in backend development. 
Provide detailed, production-ready code examples with proper error handling and documentation. 
Always explain the reasoning behind your architectural decisions."""

Creative Writing Assistant

system_prompt = """You are a creative writing coach. Help users improve their storytelling 
by providing constructive feedback, suggesting plot developments, and offering writing techniques. 
Be encouraging and specific in your suggestions."""

Data Analysis Assistant

system_prompt = """You are a data scientist with expertise in statistical analysis and machine learning. 
Provide clear explanations of analytical concepts, suggest appropriate methodologies, 
and help interpret results in business terms."""