pass context
This commit is contained in:
parent
990a17a9ab
commit
7fdd67fe78
|
@ -154,10 +154,7 @@ module DiscourseAi
|
|||
return [] if content.blank? || concept_list.blank?
|
||||
|
||||
# Prepare user message with only the content
|
||||
user_message = <<~MESSAGE
|
||||
Content to analyze:
|
||||
#{content}
|
||||
MESSAGE
|
||||
user_message = content
|
||||
|
||||
# Use the ConceptMatcher persona to match concepts
|
||||
llm = DiscourseAi::Completions::Llm.default_llm
|
||||
|
@ -166,6 +163,7 @@ module DiscourseAi
|
|||
DiscourseAi::Personas::BotContext.new(
|
||||
messages: [{ type: :user, content: user_message }],
|
||||
user: Discourse.system_user,
|
||||
inferred_concepts: DiscourseAi::InferredConcepts::Manager.list_concepts,
|
||||
)
|
||||
|
||||
prompt = persona.craft_prompt(context)
|
||||
|
|
|
@ -4,7 +4,7 @@ module DiscourseAi
|
|||
module InferredConcepts
|
||||
class Finder
|
||||
# Identifies potential concepts from provided content
|
||||
# Returns an array of concept names (strings)
|
||||
# Returns an array of concept names (strings)
|
||||
def self.identify_concepts(content)
|
||||
return [] if content.blank?
|
||||
|
||||
|
@ -13,28 +13,29 @@ module DiscourseAi
|
|||
persona = DiscourseAi::Personas::ConceptFinder.new
|
||||
context = DiscourseAi::Personas::BotContext.new(
|
||||
messages: [{ type: :user, content: content }],
|
||||
user: Discourse.system_user
|
||||
user: Discourse.system_user.
|
||||
inferred_concepts: DiscourseAi::InferredConcepts::Manager.list_concepts,
|
||||
)
|
||||
|
||||
|
||||
prompt = persona.craft_prompt(context)
|
||||
response = llm.completion(prompt, extract_json: true)
|
||||
|
||||
|
||||
return [] unless response.success?
|
||||
|
||||
|
||||
concepts = response.parsed_output["concepts"]
|
||||
concepts || []
|
||||
end
|
||||
|
||||
|
||||
# Creates or finds concepts in the database from provided names
|
||||
# Returns an array of InferredConcept instances
|
||||
def self.create_or_find_concepts(concept_names)
|
||||
return [] if concept_names.blank?
|
||||
|
||||
|
||||
concept_names.map do |name|
|
||||
InferredConcept.find_or_create_by(name: name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Finds candidate topics to use for concept generation
|
||||
#
|
||||
# @param limit [Integer] Maximum number of topics to return
|
||||
|
@ -134,4 +135,4 @@ module DiscourseAi
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue