FEATURE: try including views/username/likes in search results (#349)

This is somewhat experimental, but the context of likes/view/username
can help the llm find out what content is more important or even
common users that produce great content

This inflates the amount of tokens somewhat, but given it is all numbers
and search columns titles are only included once this is not severe
This commit is contained in:
Sam 2023-12-12 12:22:28 +11:00 committed by GitHub
parent 2798e4c86d
commit 605445831f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -208,9 +208,14 @@ module DiscourseAi::AiBot::Commands
row = { row = {
title: post.topic.title, title: post.topic.title,
url: Discourse.base_path + post.url, url: Discourse.base_path + post.url,
username: post.user&.username,
excerpt: post.excerpt, excerpt: post.excerpt,
created: post.created_at, created: post.created_at,
category: category_names, category: category_names,
likes: post.like_count,
topic_views: post.topic.views,
topic_likes: post.topic.like_count,
topic_replies: post.topic.posts_count - 1,
} }
if SiteSetting.tagging_enabled if SiteSetting.tagging_enabled

View File

@ -127,9 +127,11 @@ RSpec.describe DiscourseAi::AiBot::Commands::SearchCommand do
expect(results[:rows].to_s).to include("/subfolder" + post1.url) expect(results[:rows].to_s).to include("/subfolder" + post1.url)
end end
it "returns category and tags" do it "returns rich topic information" do
post1 = Fabricate(:post, topic: topic_with_tags) post1 = Fabricate(:post, like_count: 1, topic: topic_with_tags)
search = described_class.new(bot: nil, post: post1, args: nil) search = described_class.new(bot: nil, post: post1, args: nil)
post1.topic.update!(views: 100, posts_count: 2, like_count: 10)
results = search.process(user: post1.user.username) results = search.process(user: post1.user.username)
row = results[:rows].first row = results[:rows].first
@ -139,6 +141,21 @@ RSpec.describe DiscourseAi::AiBot::Commands::SearchCommand do
tags = row[results[:column_names].index("tags")] tags = row[results[:column_names].index("tags")]
expect(tags).to eq("funny, sad") expect(tags).to eq("funny, sad")
likes = row[results[:column_names].index("likes")]
expect(likes).to eq(1)
username = row[results[:column_names].index("username")]
expect(username).to eq(post1.user.username)
likes = row[results[:column_names].index("topic_likes")]
expect(likes).to eq(10)
views = row[results[:column_names].index("topic_views")]
expect(views).to eq(100)
replies = row[results[:column_names].index("topic_replies")]
expect(replies).to eq(1)
end end
it "scales results to number of tokens" do it "scales results to number of tokens" do