Skip to content

Commit

Permalink
Fix autotitle for conversations (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceicke authored Sep 23, 2024
1 parent 080245f commit caf0552
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions app/jobs/autotitle_conversation_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@ def perform(conversation_id)
private

def generate_title_for(text)

ai_backend = @conversation.assistant.api_service.ai_backend.new(@conversation.user, @conversation.assistant)
response = ai_backend.get_oneoff_message(
system_message,
[text],
# response_format: { type: "json_object" }) this causes problems for Groq even though it's supported: https://console.groq.com/docs/api-reference#chat-create
)
response.scan(/(?<=:)"(.+?)"/)&.flatten&.first&.strip

if ai_backend.class == AIBackend::OpenAI || ai_backend.class == AIBackend::Anthropic
response = ai_backend.get_oneoff_message(
system_message,
[text],
response_format: { type: "json_object" } # this causes problems for Groq even though it's supported: https://console.groq.com/docs/api-reference#chat-create
)
return JSON.parse(response)["topic"]
else
response = ai_backend.get_oneoff_message(
system_message,
[text]
)
return response.scan(/(?<=:)"(.+?)"/)&.flatten&.first&.strip
end
end

def system_message
Expand Down

0 comments on commit caf0552

Please sign in to comment.