16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/tfhelps.rb', line 16
def format_text(text)
prompt = " Format the following text into a professional and readable structure.\n Follow these guidelines:\n 1. Combine sentences into a single paragraph if they are separated by a single empty line.\n 2. Create a new paragraph whenever there are two or more empty lines separating the text.\n 3. Ensure proper spacing, punctuation, and capitalization throughout the text.\n 4. Maintain a clean and polished format suitable for professional use.\n 5. Replace all curved (smart) double quotation marks (e.g., \u201C \u201D) with straight (normal) double quotation marks (\").\n 6. Do not add a title or any additional text content that is not present in the original text.\n\n Text to format:\n \#{text}\n PRO\n\n http = Net::HTTP.new(@url.host, @url.port)\n http.use_ssl = true\n request = Net::HTTP::Post.new(@url.request_uri)\n request.content_type = \"application/json\"\n\n payload = {\n contents: [{\n parts: [{\n text: prompt\n }]\n }]\n }.to_json\n\n request.body = payload\n\n response = http.request(request)\n\n return JSON.parse(response.body)[\"candidates\"][0][\"content\"][\"parts\"][0][\"text\"] if response.is_a?(Net::HTTPOK)\n\n raise Error, \"Failed to format text: \#{response.code} - \#{response.body}\"\nend\n"
|