You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
System prompts allow you to set specific instructions or context that guide the AI's behavior throughout the conversation. These prompts are not directly visible to the user but help shape the AI's responses:
49
+
50
+
```ruby
51
+
# Create a chat instance
52
+
chat =RubyLLM.chat
53
+
54
+
# Add a system prompt to guide the AI's behavior
55
+
chat.add_message role::system, content:"You are a helpful Ruby programming assistant. Always include code examples in your responses and explain them line by line."
56
+
57
+
# Now the AI will follow these instructions in all responses
58
+
response = chat.ask "How do I handle file operations in Ruby?"
59
+
60
+
# You can add multiple system messages or update them during the conversation
61
+
chat.add_message role::system, content:"Always format your code using proper Ruby style conventions and include comments."
62
+
63
+
# System prompts are especially useful for:
64
+
# - Setting the AI's persona or tone
65
+
# - Providing domain-specific knowledge
66
+
# - Enforcing specific response formats
67
+
# - Creating specialized assistants
68
+
```
69
+
46
70
## Multi-turn Conversations
47
71
48
72
Chats maintain conversation history automatically:
0 commit comments