Skip to content

Commit

Permalink
Analyze attached images
Browse files Browse the repository at this point in the history
  • Loading branch information
parterburn committed May 13, 2024
1 parent 45b7288 commit 9f588b9
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions app/models/concerns/entry/ai_assistant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def as_life_coach
- Its responses should include any resources that may be relevant to the DabbleMeGPT's analysis and provide the user with links to those resources that would be helpful.
- It can provide additional relevant details to answer in-depth and comprehensively, covering aspects related to how the user is feeling in their journal entry.
- It can generate reflections, insights, follow-up questions, advice, resources, poetry, stories, essays, songs, and more.
#{image_url_cdn.present? ? "- It can analyze the attached image as part of the entry and include it in its response." : ""}
On its output format:
- Do not output code or code block syntax because the interface does not support code output.
Expand Down Expand Up @@ -104,16 +105,35 @@ def as_life_coach
def entry_body
entry_token_count = as_life_coach.to_s.length.to_f / 4
conversation = []
text_bodies_for_ai.each do |body|
text_bodies_for_ai.each_with_index do |body, index|
entry_token_count += body.length.to_f / 4
tokens_left = max_tokens - entry_token_count - MAX_RESPONSE_TOKENS
break if tokens_left <= 0

role = body.starts_with?("||DabbleMeGPT||") ? "assistant" : "user"
conversation << {
role: role,
content: body.gsub("||DabbleMeGPT||", "").first(tokens_left)
}

if index == 0 && image_url_cdn.present?
conversation << {
role: role,
content: [
{
type: "image_url",
image_url: {
"url": image_url_cdn
}
},
{
type: "text",
text: body.gsub("||DabbleMeGPT||", "").first(tokens_left)
}
]
}
else
conversation << {
role: role,
content: body.gsub("||DabbleMeGPT||", "").first(tokens_left)
}
end
end
conversation.compact
end
Expand Down

0 comments on commit 9f588b9

Please sign in to comment.