|
| 1 | +#!/usr/bin/env ruby |
| 2 | + |
| 3 | +require_relative "../lib/ai-chat" |
| 4 | +require "dotenv" |
| 5 | +Dotenv.load(File.expand_path("../.env", __dir__)) |
| 6 | +require "amazing_print" |
| 7 | + |
| 8 | +puts "\n=== AI::Chat Verbosity Tests ===" |
| 9 | +puts |
| 10 | + |
| 11 | +puts "1. Supports verbosity = :low" |
| 12 | +puts "-" * 30 |
| 13 | +chat1 = AI::Chat.new |
| 14 | +chat1.verbosity = :low |
| 15 | +chat1.user("How high do planes typically fly?") |
| 16 | +response = chat1.generate![:content] |
| 17 | +puts response |
| 18 | +puts |
| 19 | +puts "Total characters: #{response.length}" |
| 20 | +puts |
| 21 | + |
| 22 | +puts "2. Supports verbosity = :medium" |
| 23 | +puts "-" * 30 |
| 24 | +chat2 = AI::Chat.new |
| 25 | +chat2.verbosity = :medium |
| 26 | +chat2.user("How high do planes typically fly?") |
| 27 | +response = chat2.generate![:content] |
| 28 | +puts response |
| 29 | +puts |
| 30 | +puts "Total characters: #{response.length}" |
| 31 | +puts |
| 32 | + |
| 33 | +puts "3. Supports verbosity = :high" |
| 34 | +puts "-" * 30 |
| 35 | +chat3 = AI::Chat.new |
| 36 | +chat3.verbosity = :medium |
| 37 | +chat3.user("How high do planes typically fly?") |
| 38 | +response = chat3.generate![:content] |
| 39 | +puts response |
| 40 | +puts |
| 41 | +puts "Total characters: #{response.length}" |
| 42 | +puts |
| 43 | + |
| 44 | +puts "4. Raises error for unsupported verbosity values" |
| 45 | +puts "-" * 30 |
| 46 | +chat4 = AI::Chat.new |
| 47 | +chat4.user("How high do planes typically fly?") |
| 48 | + begin |
| 49 | + chat4.verbosity = :extreme |
| 50 | + puts "✗ Failed to raise ArgumentError for invalid verbosity: #{chat4.verbosity}" |
| 51 | +rescue ArgumentError => e |
| 52 | + puts "✓ Raises Argument error correctly: #{e.message}" |
| 53 | +end |
| 54 | +puts |
| 55 | + |
| 56 | +puts |
| 57 | +puts "5. Supports verbosity with Structured Outputs" |
| 58 | +puts "-" * 30 |
| 59 | +path = "my_schemas/test.json" |
| 60 | +File.delete(path) if File.exist?(path) |
| 61 | +AI::Chat.generate_schema!("A user with full name (required), first_name (required), last_name (required), coolness_level (score between 0-10 representing how cool the user sounds), coolness_reasoning (the explanation of the coolness_leve)", location: path, api_key: ENV["OPENAI_API_KEY"]) |
| 62 | + |
| 63 | +chat5 = AI::Chat.new |
| 64 | +chat5.verbosity = :low |
| 65 | +chat5.schema_file = path |
| 66 | +chat5.system("Extract the profile information from the user message. Describe it like a 90's robot.") |
| 67 | +chat5.user("My name is Bryan. I like to skateboard and be cool. I'm seventeen and a quarter. You can reach me at bryan@example.com.") |
| 68 | +puts chat5.last[:content] |
| 69 | +puts |
| 70 | +begin |
| 71 | + response = chat5.generate![:content] |
| 72 | + puts "✓ Generates structured output response with verbosity" |
| 73 | +rescue => e |
| 74 | + puts "✗ Failed to generate structured output response with verbosity: #{e.message}" |
| 75 | +end |
| 76 | +puts |
| 77 | + |
| 78 | +puts "6. Supports verbosity = :medium for gpt-4.1-nano" |
| 79 | +puts "-" * 30 |
| 80 | +chat6 = AI::Chat.new |
| 81 | +chat6.model = "gpt-4.1-nano" |
| 82 | +chat6.verbosity = :medium |
| 83 | +chat6.user("How high do planes typically fly?") |
| 84 | +response = chat6.generate![:content] |
| 85 | +puts response |
| 86 | +puts |
| 87 | +puts "Total characters: #{response.length}" |
| 88 | +puts |
| 89 | + |
| 90 | +puts "7. Fails verbosity = :low for gpt-4.1-nano" |
| 91 | +puts "-" * 30 |
| 92 | +chat7 = AI::Chat.new |
| 93 | +chat7.model = "gpt-4.1-nano" |
| 94 | +chat7.verbosity = :low |
| 95 | +chat7.user("How high do planes typically fly?") |
| 96 | +begin |
| 97 | + response = chat7.generate![:content] |
| 98 | + puts "✗ Failed to raise error when setting :low verbosity on unsupported model." |
| 99 | +rescue OpenAI::Errors::BadRequestError => e |
| 100 | + puts "✓ Successfully raises error on for unsupported verbosity for older model: #{e.message}" |
| 101 | +end |
| 102 | +puts |
0 commit comments