Skip to content

Commit

Permalink
feat: add conversation name extracted from user's first query context (
Browse files Browse the repository at this point in the history
  • Loading branch information
Davsooonowy authored Jan 27, 2025
1 parent 0986773 commit 5c22137
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
10 changes: 9 additions & 1 deletion frontend/src/components/conversations/conversations-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ export function ConversationsList() {
return await api.conversations().getConversations(dataSetId, page);
}

const truncateText = (text: string, maxLength: number): string => {
if (text.length <= maxLength) {
return text;
}
return text.substring(0, maxLength - 3) + '...';
}

return (
<PaginatedTable
loadItems={loadConversations}
itemsReloadDependencies={dataSetId}
noItemsMessage="You don't have any conversations yet"
tableHeaders={["Time"]}
tableHeaders={["Name", "Time"]}
tableRow={(item, index) => {
return (
<TableRow key={index} onClick={() => navigateToConversation(item.id)} className="cursor-pointer">
<TableCell>{truncateText(item.summary || "Unnamed Conversation", 180)}</TableCell>
<TableCell>{new Date(item.started_at).toLocaleString('en-US')}</TableCell>
</TableRow>
)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export type Conversation = {
model: string;
dimensions: number;
data_set: string;
summary?: string;
history?: Message[];
}

Expand Down
5 changes: 5 additions & 0 deletions server/agent/conversation/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def respond_to_user_message(self, conversation_id: int, data_set_id: int, user_i
role='user',
text=message)

# Set the conversation summary if it's the first message
if not conversation.summary:
conversation.summary = user_message.text
conversation.save()

response_text = self.get_answer(conversation, user_message.text)
response = Message.objects.create(conversation=conversation,
created_at=datetime.now(),
Expand Down
18 changes: 18 additions & 0 deletions server/agent/migrations/0003_conversation_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.5 on 2025-01-27 12:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("agent", "0002_remove_conversation_system_name_and_more"),
]

operations = [
migrations.AddField(
model_name="conversation",
name="summary",
field=models.CharField(null=True),
),
]
1 change: 1 addition & 0 deletions server/agent/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Conversation(models.Model):
user = models.ForeignKey(get_user_model(), on_delete=models.PROTECT)
started_at = models.DateTimeField(auto_now_add=True)
data_set = models.ForeignKey(DataSet, on_delete=models.PROTECT, null=False)
summary = models.CharField(null=True)

class Meta:
db_table_comment = ("A conversation is a collection of various messages exchanged during one session. Messages "
Expand Down
2 changes: 1 addition & 1 deletion server/agent/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ConversationCreationSerializer(serializers.Serializer):
class ConversationSerializer(serializers.ModelSerializer):
class Meta:
model = Conversation
fields = ['id', 'started_at']
fields = ['id', 'started_at', 'summary']


class MessageFeedbackSerializer(serializers.ModelSerializer):
Expand Down

0 comments on commit 5c22137

Please sign in to comment.