Skip to content

Commit 0f3eb66

Browse files
committed
Add system prompts section to chat guide
Closes #22
1 parent f832cb2 commit 0f3eb66

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/guides/chat.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ claude_chat = RubyLLM.chat(model: 'claude-3-5-sonnet-20241022')
4343
chat.with_model('gemini-2.0-flash')
4444
```
4545

46+
## System Prompts
47+
48+
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+
4670
## Multi-turn Conversations
4771

4872
Chats maintain conversation history automatically:

0 commit comments

Comments
 (0)