Skip to content

Commit

Permalink
Merge pull request #59 from salesforce/improve-quip-handling
Browse files Browse the repository at this point in the history
Convert html to md
  • Loading branch information
vswamidass-sfdc authored Sep 4, 2024
2 parents ecdb916 + 59dddde commit 5503655
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,5 @@ gem 'pundit', '~> 2.3'
gem 'bundle-audit'

gem 'brakeman'

gem 'reverse_markdown'
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ GEM
regexp_parser (2.9.2)
reline (0.5.8)
io-console (~> 0.5)
reverse_markdown (2.1.1)
nokogiri
rexml (3.3.6)
strscan
rspec-core (3.13.0)
Expand Down Expand Up @@ -388,6 +390,7 @@ DEPENDENCIES
rails-controller-testing
redcarpet
redis (~> 4.0)
reverse_markdown
rspec-rails (~> 6.1)
rubocop
ruby-saml
Expand Down
5 changes: 4 additions & 1 deletion app/jobs/generate_message_response_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def perform(_message_id)
quip_thread = quip_client.get_thread(path)

prompt += 'QUIP DOCUMENT\n\n'
prompt += quip_thread.to_json
# The quip api only returns html which has too much extra junk.
# Convert to md for smaller size
markdown_quip = ReverseMarkdown.convert quip_thread['html']
prompt += markdown_quip
end

if assistant.confluence_spaces.present?
Expand Down
6 changes: 3 additions & 3 deletions lib/quip/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def update_user(user_id, picture_url: nil)

# Fetches a single thread by its ID
def get_thread(id)
get_request("threads/#{id}")
get_request("threads/#{id}/html")
end

# Fetches multiple threads by their IDs
Expand All @@ -96,15 +96,15 @@ def get_matching_threads(query, count: nil, only_match_titles: false, **kwargs)
private

def get_request(path, params = {})
uri = URI.join(@base_url, "/1/#{path}")
uri = URI.join(@base_url, "/2/#{path}")
uri.query = URI.encode_www_form(clean_params(params))
request = Net::HTTP::Get.new(uri)
request['Authorization'] = "Bearer #{@access_token}" if @access_token
execute_request(uri, request)
end

def post_request(path, post_data = {})
uri = URI.join(@base_url, "/1/#{path}")
uri = URI.join(@base_url, "/2/#{path}")
request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{@access_token}" if @access_token
request.set_form_data(clean_params(post_data))
Expand Down

0 comments on commit 5503655

Please sign in to comment.