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.
Here’s how to include a system prompt in your chat completion request:
Copy
Ask AI
from openai import OpenAIclient = 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)
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."""
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."""
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."""