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
Copy file name to clipboardExpand all lines: docs/guides/rails.md
+19-1Lines changed: 19 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -122,6 +122,24 @@ chat.messages.order(:created_at).each do |message|
122
122
end
123
123
```
124
124
125
+
## Using System Messages
126
+
127
+
If you wish to use systems messages, you can create a Message with the role `:system` directly in the chat:
128
+
129
+
```ruby
130
+
# Create a new chat
131
+
chat =Chat.create!(model_id:'gpt-4o-mini')
132
+
133
+
# Create a message with the system role
134
+
chat.messages.create!(role::system, content:"You are a helpful Ruby programming assistant. Always include code examples in your responses and explain them line by line.")
135
+
136
+
# Now the AI will follow these instructions in all responses
137
+
chat.ask "How do I handle file operations in Ruby?"
138
+
139
+
# The response is automatically persisted
140
+
puts chat.messages.last.content
141
+
```
142
+
125
143
## Streaming Responses
126
144
127
145
You can stream responses while still persisting the final result:
@@ -394,4 +412,4 @@ Now that you've integrated RubyLLM with Rails, you might want to explore:
394
412
395
413
-[Using Tools]({% link guides/tools.md %}) to add capabilities to your chats
396
414
-[Streaming Responses]({% link guides/streaming.md %}) for a better user experience
397
-
-[Error Handling]({% link guides/error-handling.md %}) to handle AI service issues gracefully
415
+
-[Error Handling]({% link guides/error-handling.md %}) to handle AI service issues gracefully
0 commit comments