tavus 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +4 -0
- data/.rubocop.yml +32 -0
- data/CHANGELOG.md +58 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +90 -0
- data/LICENSE.txt +21 -0
- data/README.md +736 -0
- data/Rakefile +153 -0
- data/examples/advanced_persona.rb +148 -0
- data/examples/basic_usage.rb +107 -0
- data/examples/complete_workflow.rb +200 -0
- data/lib/tavus/client.rb +150 -0
- data/lib/tavus/configuration.rb +26 -0
- data/lib/tavus/errors.rb +13 -0
- data/lib/tavus/resources/conversations.rb +66 -0
- data/lib/tavus/resources/documents.rb +61 -0
- data/lib/tavus/resources/guardrails.rb +88 -0
- data/lib/tavus/resources/objectives.rb +87 -0
- data/lib/tavus/resources/personas.rb +97 -0
- data/lib/tavus/resources/replicas.rb +64 -0
- data/lib/tavus/resources/videos.rb +90 -0
- data/lib/tavus/version.rb +5 -0
- data/lib/tavus.rb +31 -0
- metadata +168 -0
data/Rakefile
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rspec/core/rake_task"
|
|
5
|
+
|
|
6
|
+
# Define RSpec task
|
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
8
|
+
|
|
9
|
+
# Default task
|
|
10
|
+
task default: :spec
|
|
11
|
+
|
|
12
|
+
# Custom tasks for gem management
|
|
13
|
+
namespace :gem do
|
|
14
|
+
desc "Build the gem"
|
|
15
|
+
task :build do
|
|
16
|
+
sh "gem build tavus.gemspec"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
desc "Install the gem locally"
|
|
20
|
+
task install: :build do
|
|
21
|
+
version = File.read("lib/tavus/version.rb").match(/VERSION = "(.+)"/)[1]
|
|
22
|
+
sh "gem install ./tavus-#{version}.gem"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc "Uninstall the gem"
|
|
26
|
+
task :uninstall do
|
|
27
|
+
version = File.read("lib/tavus/version.rb").match(/VERSION = "(.+)"/)[1]
|
|
28
|
+
sh "gem uninstall tavus -v #{version}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
desc "Clean up built gems"
|
|
32
|
+
task :clean do
|
|
33
|
+
sh "rm -f *.gem"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
desc "Push gem to RubyGems"
|
|
37
|
+
task push: :build do
|
|
38
|
+
version = File.read("lib/tavus/version.rb").match(/VERSION = "(.+)"/)[1]
|
|
39
|
+
sh "gem push tavus-#{version}.gem"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Development tasks
|
|
44
|
+
namespace :dev do
|
|
45
|
+
desc "Run all tests"
|
|
46
|
+
task :test do
|
|
47
|
+
sh "bundle exec rspec"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
desc "Run tests with coverage"
|
|
51
|
+
task :coverage do
|
|
52
|
+
ENV['COVERAGE'] = 'true'
|
|
53
|
+
sh "bundle exec rspec"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
desc "Run security audit"
|
|
57
|
+
task :audit do
|
|
58
|
+
sh "bundle exec bundle-audit check --update"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
desc "Run all security checks"
|
|
62
|
+
task :security do
|
|
63
|
+
Rake::Task["dev:audit"].invoke
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
desc "Update dependencies"
|
|
67
|
+
task :update do
|
|
68
|
+
sh "bundle update"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
desc "Check for outdated dependencies"
|
|
72
|
+
task :outdated do
|
|
73
|
+
sh "bundle outdated"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Release tasks
|
|
78
|
+
namespace :release do
|
|
79
|
+
desc "Prepare for release (run tests, lint, build)"
|
|
80
|
+
task :prepare do
|
|
81
|
+
puts "🔍 Running tests..."
|
|
82
|
+
Rake::Task["dev:test"].invoke
|
|
83
|
+
|
|
84
|
+
puts "🔒 Running security checks..."
|
|
85
|
+
Rake::Task["dev:security"].invoke
|
|
86
|
+
|
|
87
|
+
puts "📦 Building gem..."
|
|
88
|
+
Rake::Task["gem:build"].invoke
|
|
89
|
+
|
|
90
|
+
puts "✅ Release preparation complete!"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
desc "Create a new release (tag, build, push)"
|
|
94
|
+
task :create do
|
|
95
|
+
version = File.read("lib/tavus/version.rb").match(/VERSION = "(.+)"/)[1]
|
|
96
|
+
|
|
97
|
+
puts "🏷️ Creating git tag v#{version}..."
|
|
98
|
+
sh "git tag v#{version}"
|
|
99
|
+
sh "git push origin v#{version}"
|
|
100
|
+
|
|
101
|
+
puts "📦 Building and pushing gem..."
|
|
102
|
+
Rake::Task["gem:push"].invoke
|
|
103
|
+
|
|
104
|
+
puts "🎉 Release v#{version} created successfully!"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
desc "Check if ready for release"
|
|
108
|
+
task :check do
|
|
109
|
+
version = File.read("lib/tavus/version.rb").match(/VERSION = "(.+)"/)[1]
|
|
110
|
+
|
|
111
|
+
puts "📋 Release Checklist for v#{version}:"
|
|
112
|
+
puts " ✓ Version updated in version.rb"
|
|
113
|
+
puts " ✓ CHANGELOG.md updated" if File.read("CHANGELOG.md").include?(version)
|
|
114
|
+
puts " ✓ All tests passing" if system("bundle exec rspec > /dev/null 2>&1")
|
|
115
|
+
puts " ✓ Documentation up to date"
|
|
116
|
+
puts " ✓ Ready for release!"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Help task
|
|
121
|
+
desc "Show available tasks"
|
|
122
|
+
task :help do
|
|
123
|
+
puts <<~HELP
|
|
124
|
+
🎵 ElevenLabs Client Gem - Available Rake Tasks
|
|
125
|
+
|
|
126
|
+
📦 Gem Management:
|
|
127
|
+
rake gem:build - Build the gem
|
|
128
|
+
rake gem:install - Install gem locally
|
|
129
|
+
rake gem:uninstall - Uninstall gem
|
|
130
|
+
rake gem:clean - Clean up built gems
|
|
131
|
+
rake gem:push - Push gem to RubyGems
|
|
132
|
+
|
|
133
|
+
🧪 Testing:
|
|
134
|
+
rake spec - Run all tests (default)
|
|
135
|
+
rake test:unit - Run unit tests only
|
|
136
|
+
rake test:integration - Run integration tests only
|
|
137
|
+
rake test:endpoint[name] - Run tests for specific endpoint
|
|
138
|
+
rake dev:coverage - Run tests with coverage
|
|
139
|
+
|
|
140
|
+
🔧 Development:
|
|
141
|
+
rake dev:audit - Run bundler-audit
|
|
142
|
+
rake dev:security - Run security checks
|
|
143
|
+
rake dev:update - Update dependencies
|
|
144
|
+
rake dev:outdated - Check outdated dependencies
|
|
145
|
+
|
|
146
|
+
🚀 Release:
|
|
147
|
+
rake release:prepare - Prepare for release
|
|
148
|
+
rake release:create - Create new release
|
|
149
|
+
rake release:check - Check release readiness
|
|
150
|
+
|
|
151
|
+
Use 'rake -T' to see all available tasks.
|
|
152
|
+
HELP
|
|
153
|
+
end
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "tavus"
|
|
6
|
+
|
|
7
|
+
# Configure the client
|
|
8
|
+
client = Tavus::Client.new(api_key: ENV.fetch("TAVUS_API_KEY", "your-api-key-here"))
|
|
9
|
+
|
|
10
|
+
puts "=== Advanced Persona Configuration Example ===\n\n"
|
|
11
|
+
|
|
12
|
+
# Create a persona with advanced layer configurations
|
|
13
|
+
puts "Creating an advanced persona with custom layers..."
|
|
14
|
+
|
|
15
|
+
begin
|
|
16
|
+
persona = client.personas.create(
|
|
17
|
+
persona_name: "Customer Support Agent",
|
|
18
|
+
system_prompt: "You are a helpful customer support agent for a SaaS company. " \
|
|
19
|
+
"You help customers with technical issues, billing questions, and general inquiries.",
|
|
20
|
+
pipeline_mode: "full",
|
|
21
|
+
context: "The company offers project management software with features including task tracking, " \
|
|
22
|
+
"team collaboration, and reporting. Pricing plans range from $10-$50 per user per month.",
|
|
23
|
+
layers: {
|
|
24
|
+
# Language Model Configuration
|
|
25
|
+
llm: {
|
|
26
|
+
model: "tavus-gpt-4o",
|
|
27
|
+
tools: [
|
|
28
|
+
{
|
|
29
|
+
type: "function",
|
|
30
|
+
function: {
|
|
31
|
+
name: "check_account_status",
|
|
32
|
+
description: "Check the status of a customer's account including subscription and usage",
|
|
33
|
+
parameters: {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
account_id: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "The customer's account ID"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
required: ["account_id"]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "function",
|
|
47
|
+
function: {
|
|
48
|
+
name: "create_support_ticket",
|
|
49
|
+
description: "Create a support ticket for issues that need follow-up",
|
|
50
|
+
parameters: {
|
|
51
|
+
type: "object",
|
|
52
|
+
properties: {
|
|
53
|
+
title: {
|
|
54
|
+
type: "string",
|
|
55
|
+
description: "Brief description of the issue"
|
|
56
|
+
},
|
|
57
|
+
priority: {
|
|
58
|
+
type: "string",
|
|
59
|
+
enum: ["low", "medium", "high", "urgent"],
|
|
60
|
+
description: "Priority level of the ticket"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
required: ["title", "priority"]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
# Text-to-Speech Configuration
|
|
71
|
+
tts: {
|
|
72
|
+
tts_engine: "cartesia",
|
|
73
|
+
voice_settings: {
|
|
74
|
+
speed: 1.0,
|
|
75
|
+
emotion: ["positivity:high", "curiosity:medium"]
|
|
76
|
+
},
|
|
77
|
+
tts_emotion_control: "true",
|
|
78
|
+
tts_model_name: "sonic"
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
# Speech-to-Text Configuration
|
|
82
|
+
stt: {
|
|
83
|
+
stt_engine: "tavus-turbo",
|
|
84
|
+
participant_pause_sensitivity: "medium",
|
|
85
|
+
participant_interrupt_sensitivity: "low",
|
|
86
|
+
smart_turn_detection: true,
|
|
87
|
+
hotwords: "SaaS, API, webhook, integration, dashboard"
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
# Perception Configuration
|
|
91
|
+
perception: {
|
|
92
|
+
perception_model: "raven-0",
|
|
93
|
+
ambient_awareness_queries: [
|
|
94
|
+
"Does the customer appear frustrated or confused?",
|
|
95
|
+
"Is the customer showing their screen or pointing at something?"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
puts "✓ Created advanced persona: #{persona['persona_id']}"
|
|
102
|
+
persona_id = persona["persona_id"]
|
|
103
|
+
|
|
104
|
+
# Demonstrate updating specific layers
|
|
105
|
+
puts "\nUpdating TTS emotion settings..."
|
|
106
|
+
|
|
107
|
+
operations = [
|
|
108
|
+
{
|
|
109
|
+
op: "replace",
|
|
110
|
+
path: "/layers/tts/voice_settings/emotion",
|
|
111
|
+
value: ["positivity:very-high", "enthusiasm:high"]
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
op: "replace",
|
|
115
|
+
path: "/layers/stt/participant_pause_sensitivity",
|
|
116
|
+
value: "low"
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
client.personas.patch(persona_id, operations)
|
|
121
|
+
puts "✓ Updated persona layers"
|
|
122
|
+
|
|
123
|
+
# Get the updated persona details
|
|
124
|
+
puts "\nRetrieving updated persona..."
|
|
125
|
+
updated_persona = client.personas.get(persona_id)
|
|
126
|
+
puts "✓ Persona configuration:"
|
|
127
|
+
puts " Name: #{updated_persona['data']&.first&.dig('persona_name')}"
|
|
128
|
+
puts " System Prompt: #{updated_persona['data']&.first&.dig('system_prompt')[0..80]}..."
|
|
129
|
+
|
|
130
|
+
tts_settings = updated_persona.dig("data", 0, "layers", "tts")
|
|
131
|
+
if tts_settings
|
|
132
|
+
puts " TTS Engine: #{tts_settings['tts_engine']}"
|
|
133
|
+
puts " Emotion Control: #{tts_settings['tts_emotion_control']}"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Cleanup (optional)
|
|
137
|
+
# puts "\nCleaning up..."
|
|
138
|
+
# client.personas.delete(persona_id)
|
|
139
|
+
# puts "✓ Deleted persona"
|
|
140
|
+
|
|
141
|
+
rescue Tavus::BadRequestError => e
|
|
142
|
+
puts "✗ Bad request: #{e.message}"
|
|
143
|
+
rescue Tavus::ApiError => e
|
|
144
|
+
puts "✗ API error: #{e.message}"
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
puts "\n=== Example Complete ==="
|
|
148
|
+
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "tavus"
|
|
6
|
+
|
|
7
|
+
# Configure the client
|
|
8
|
+
Tavus.configure do |config|
|
|
9
|
+
config.api_key = ENV.fetch("TAVUS_API_KEY", "your-api-key-here")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Or create a client instance directly
|
|
13
|
+
client = Tavus::Client.new(api_key: ENV.fetch("TAVUS_API_KEY", "your-api-key-here"))
|
|
14
|
+
|
|
15
|
+
puts "=== Tavus Ruby Client Examples ===\n\n"
|
|
16
|
+
|
|
17
|
+
# Example 1: Create a Persona
|
|
18
|
+
puts "1. Creating a persona..."
|
|
19
|
+
begin
|
|
20
|
+
persona = client.personas.create(
|
|
21
|
+
system_prompt: "You are a friendly sales coach who helps people improve their sales techniques.",
|
|
22
|
+
persona_name: "Sales Coach",
|
|
23
|
+
pipeline_mode: "full",
|
|
24
|
+
context: "You have 10 years of experience in B2B sales."
|
|
25
|
+
)
|
|
26
|
+
puts "✓ Created persona: #{persona['persona_id']}"
|
|
27
|
+
persona_id = persona["persona_id"]
|
|
28
|
+
rescue Tavus::ApiError => e
|
|
29
|
+
puts "✗ Error creating persona: #{e.message}"
|
|
30
|
+
exit 1
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Example 2: List Personas
|
|
34
|
+
puts "\n2. Listing personas..."
|
|
35
|
+
begin
|
|
36
|
+
personas = client.personas.list(limit: 10)
|
|
37
|
+
puts "✓ Found #{personas['total_count']} personas"
|
|
38
|
+
personas["data"]&.each do |p|
|
|
39
|
+
puts " - #{p['persona_name']} (#{p['persona_id']})"
|
|
40
|
+
end
|
|
41
|
+
rescue Tavus::ApiError => e
|
|
42
|
+
puts "✗ Error listing personas: #{e.message}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Example 3: Create a Conversation
|
|
46
|
+
puts "\n3. Creating a conversation..."
|
|
47
|
+
begin
|
|
48
|
+
conversation = client.conversations.create(
|
|
49
|
+
replica_id: "rfe12d8b9597", # Replace with your replica ID
|
|
50
|
+
persona_id: persona_id,
|
|
51
|
+
conversation_name: "Sales Training Session",
|
|
52
|
+
test_mode: true # Set to false for actual conversation
|
|
53
|
+
)
|
|
54
|
+
puts "✓ Created conversation: #{conversation['conversation_id']}"
|
|
55
|
+
puts " URL: #{conversation['conversation_url']}"
|
|
56
|
+
conversation_id = conversation["conversation_id"]
|
|
57
|
+
rescue Tavus::BadRequestError => e
|
|
58
|
+
puts "✗ Error creating conversation: #{e.message}"
|
|
59
|
+
puts " Note: Make sure to use a valid replica_id"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Example 4: List Conversations
|
|
63
|
+
puts "\n4. Listing conversations..."
|
|
64
|
+
begin
|
|
65
|
+
conversations = client.conversations.list(status: "active")
|
|
66
|
+
puts "✓ Found #{conversations['total_count']} active conversations"
|
|
67
|
+
rescue Tavus::ApiError => e
|
|
68
|
+
puts "✗ Error listing conversations: #{e.message}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Example 5: Update Persona
|
|
72
|
+
puts "\n5. Updating persona..."
|
|
73
|
+
begin
|
|
74
|
+
result = client.personas.update_field(
|
|
75
|
+
persona_id,
|
|
76
|
+
"/persona_name",
|
|
77
|
+
"Expert Sales Coach"
|
|
78
|
+
)
|
|
79
|
+
puts "✓ Updated persona name"
|
|
80
|
+
rescue Tavus::ApiError => e
|
|
81
|
+
puts "✗ Error updating persona: #{e.message}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Example 6: Get Persona Details
|
|
85
|
+
puts "\n6. Getting persona details..."
|
|
86
|
+
begin
|
|
87
|
+
persona_details = client.personas.get(persona_id)
|
|
88
|
+
puts "✓ Retrieved persona details"
|
|
89
|
+
puts " Name: #{persona_details['data']&.first&.dig('persona_name')}"
|
|
90
|
+
rescue Tavus::NotFoundError => e
|
|
91
|
+
puts "✗ Persona not found: #{e.message}"
|
|
92
|
+
rescue Tavus::ApiError => e
|
|
93
|
+
puts "✗ Error getting persona: #{e.message}"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Cleanup (optional)
|
|
97
|
+
puts "\n7. Cleaning up (optional)..."
|
|
98
|
+
# Uncomment to delete the created persona
|
|
99
|
+
# begin
|
|
100
|
+
# client.personas.delete(persona_id)
|
|
101
|
+
# puts "✓ Deleted persona"
|
|
102
|
+
# rescue Tavus::ApiError => e
|
|
103
|
+
# puts "✗ Error deleting persona: #{e.message}"
|
|
104
|
+
# end
|
|
105
|
+
|
|
106
|
+
puts "\n=== Examples Complete ==="
|
|
107
|
+
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "tavus"
|
|
6
|
+
|
|
7
|
+
# Configure the client
|
|
8
|
+
client = Tavus::Client.new(api_key: ENV.fetch("TAVUS_API_KEY", "your-api-key-here"))
|
|
9
|
+
|
|
10
|
+
puts "=== Complete Tavus Workflow Example ===\n\n"
|
|
11
|
+
|
|
12
|
+
# Step 1: Create a Replica
|
|
13
|
+
puts "1. Creating a replica..."
|
|
14
|
+
begin
|
|
15
|
+
replica = client.replicas.create(
|
|
16
|
+
train_video_url: "https://your-bucket.s3.amazonaws.com/training-video.mp4",
|
|
17
|
+
replica_name: "Sales Demo Replica",
|
|
18
|
+
model_name: "phoenix-3"
|
|
19
|
+
)
|
|
20
|
+
puts "✓ Created replica: #{replica['replica_id']}"
|
|
21
|
+
replica_id = replica["replica_id"]
|
|
22
|
+
rescue Tavus::BadRequestError => e
|
|
23
|
+
puts "✗ Error creating replica: #{e.message}"
|
|
24
|
+
puts " Note: Using placeholder replica_id for demo"
|
|
25
|
+
replica_id = "rfe12d8b9597"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Step 2: Upload documents to Knowledge Base
|
|
29
|
+
puts "\n2. Uploading documents to knowledge base..."
|
|
30
|
+
begin
|
|
31
|
+
document = client.documents.create(
|
|
32
|
+
document_url: "https://example.com/product-guide.pdf",
|
|
33
|
+
document_name: "Product Guide",
|
|
34
|
+
tags: ["product", "sales"],
|
|
35
|
+
properties: { category: "documentation" }
|
|
36
|
+
)
|
|
37
|
+
puts "✓ Uploaded document: #{document['uuid']}"
|
|
38
|
+
document_id = document["uuid"]
|
|
39
|
+
rescue Tavus::ApiError => e
|
|
40
|
+
puts "✗ Error uploading document: #{e.message}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Step 3: Create Objectives
|
|
44
|
+
puts "\n3. Creating conversation objectives..."
|
|
45
|
+
begin
|
|
46
|
+
objectives = client.objectives.create(
|
|
47
|
+
data: [
|
|
48
|
+
{
|
|
49
|
+
objective_name: "Qualify Lead",
|
|
50
|
+
objective_prompt: "Determine if the prospect has budget and authority",
|
|
51
|
+
confirmation_mode: "automatic",
|
|
52
|
+
modality: "verbal"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
)
|
|
56
|
+
puts "✓ Created objectives: #{objectives['objectives_id']}"
|
|
57
|
+
objectives_id = objectives["objectives_id"]
|
|
58
|
+
rescue Tavus::ApiError => e
|
|
59
|
+
puts "✗ Error creating objectives: #{e.message}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Step 4: Create Guardrails
|
|
63
|
+
puts "\n4. Creating guardrails..."
|
|
64
|
+
begin
|
|
65
|
+
guardrails = client.guardrails.create(
|
|
66
|
+
name: "Sales Compliance Guardrails",
|
|
67
|
+
data: [
|
|
68
|
+
{
|
|
69
|
+
guardrails_prompt: "Never make unrealistic promises or discuss competitor pricing",
|
|
70
|
+
modality: "verbal"
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
)
|
|
74
|
+
puts "✓ Created guardrails: #{guardrails['guardrails_id']}"
|
|
75
|
+
guardrails_id = guardrails["guardrails_id"]
|
|
76
|
+
rescue Tavus::ApiError => e
|
|
77
|
+
puts "✗ Error creating guardrails: #{e.message}"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Step 5: Create a Persona
|
|
81
|
+
puts "\n5. Creating a persona..."
|
|
82
|
+
begin
|
|
83
|
+
persona = client.personas.create(
|
|
84
|
+
persona_name: "Sales Expert",
|
|
85
|
+
system_prompt: "You are an expert sales representative who helps qualify leads and answer product questions.",
|
|
86
|
+
pipeline_mode: "full",
|
|
87
|
+
context: "You work for a SaaS company selling project management software.",
|
|
88
|
+
default_replica_id: replica_id,
|
|
89
|
+
document_ids: document_id ? [document_id] : [],
|
|
90
|
+
layers: {
|
|
91
|
+
tts: {
|
|
92
|
+
tts_engine: "cartesia",
|
|
93
|
+
voice_settings: {
|
|
94
|
+
speed: 1.0,
|
|
95
|
+
emotion: ["positivity:high", "professionalism:high"]
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
puts "✓ Created persona: #{persona['persona_id']}"
|
|
101
|
+
persona_id = persona["persona_id"]
|
|
102
|
+
rescue Tavus::ApiError => e
|
|
103
|
+
puts "✗ Error creating persona: #{e.message}"
|
|
104
|
+
exit 1
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Step 6: Create a Conversation
|
|
108
|
+
puts "\n6. Creating a conversation..."
|
|
109
|
+
begin
|
|
110
|
+
conversation = client.conversations.create(
|
|
111
|
+
replica_id: replica_id,
|
|
112
|
+
persona_id: persona_id,
|
|
113
|
+
conversation_name: "Sales Demo Call",
|
|
114
|
+
test_mode: true
|
|
115
|
+
)
|
|
116
|
+
puts "✓ Created conversation: #{conversation['conversation_id']}"
|
|
117
|
+
puts " URL: #{conversation['conversation_url']}"
|
|
118
|
+
conversation_id = conversation["conversation_id"]
|
|
119
|
+
rescue Tavus::ApiError => e
|
|
120
|
+
puts "✗ Error creating conversation: #{e.message}"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Step 7: Generate a Video
|
|
124
|
+
puts "\n7. Generating a video..."
|
|
125
|
+
begin
|
|
126
|
+
video = client.videos.generate_from_text(
|
|
127
|
+
replica_id: replica_id,
|
|
128
|
+
script: "Hello! I'm excited to show you how our platform can help your team collaborate better.",
|
|
129
|
+
video_name: "Sales Demo Video",
|
|
130
|
+
fast: true
|
|
131
|
+
)
|
|
132
|
+
puts "✓ Created video: #{video['video_id']}"
|
|
133
|
+
puts " Status: #{video['status']}"
|
|
134
|
+
puts " Hosted URL: #{video['hosted_url']}"
|
|
135
|
+
video_id = video["video_id"]
|
|
136
|
+
rescue Tavus::ApiError => e
|
|
137
|
+
puts "✗ Error generating video: #{e.message}"
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Step 8: Check status and list resources
|
|
141
|
+
puts "\n8. Checking created resources..."
|
|
142
|
+
begin
|
|
143
|
+
# List replicas
|
|
144
|
+
replicas = client.replicas.list(limit: 5)
|
|
145
|
+
puts "✓ Total replicas: #{replicas['total_count']}"
|
|
146
|
+
|
|
147
|
+
# List personas
|
|
148
|
+
personas = client.personas.list(limit: 5)
|
|
149
|
+
puts "✓ Total personas: #{personas['total_count']}"
|
|
150
|
+
|
|
151
|
+
# List conversations
|
|
152
|
+
conversations = client.conversations.list(limit: 5)
|
|
153
|
+
puts "✓ Total conversations: #{conversations['total_count']}"
|
|
154
|
+
|
|
155
|
+
# List videos
|
|
156
|
+
videos = client.videos.list(limit: 5)
|
|
157
|
+
puts "✓ Total videos: #{videos['total_count']}"
|
|
158
|
+
rescue Tavus::ApiError => e
|
|
159
|
+
puts "✗ Error listing resources: #{e.message}"
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Step 9: Update resources
|
|
163
|
+
puts "\n9. Updating resources..."
|
|
164
|
+
begin
|
|
165
|
+
if persona_id
|
|
166
|
+
client.personas.update_field(
|
|
167
|
+
persona_id,
|
|
168
|
+
"/persona_name",
|
|
169
|
+
"Expert Sales Agent"
|
|
170
|
+
)
|
|
171
|
+
puts "✓ Updated persona name"
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
if video_id
|
|
175
|
+
client.videos.rename(video_id, "Updated Sales Demo")
|
|
176
|
+
puts "✓ Updated video name"
|
|
177
|
+
end
|
|
178
|
+
rescue Tavus::ApiError => e
|
|
179
|
+
puts "✗ Error updating resources: #{e.message}"
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# Optional cleanup
|
|
183
|
+
puts "\n10. Cleanup (commented out - uncomment to enable)..."
|
|
184
|
+
# client.conversations.delete(conversation_id) if conversation_id
|
|
185
|
+
# client.videos.delete(video_id) if video_id
|
|
186
|
+
# client.personas.delete(persona_id) if persona_id
|
|
187
|
+
# client.guardrails.delete(guardrails_id) if guardrails_id
|
|
188
|
+
# client.objectives.delete(objectives_id) if objectives_id
|
|
189
|
+
# client.documents.delete(document_id) if document_id
|
|
190
|
+
# puts "✓ Cleaned up all resources"
|
|
191
|
+
|
|
192
|
+
puts "\n=== Workflow Complete ==="
|
|
193
|
+
puts "\nThis example demonstrated:"
|
|
194
|
+
puts " • Creating and managing replicas"
|
|
195
|
+
puts " • Uploading documents to knowledge base"
|
|
196
|
+
puts " • Setting up objectives and guardrails"
|
|
197
|
+
puts " • Creating personas with custom configurations"
|
|
198
|
+
puts " • Starting conversations"
|
|
199
|
+
puts " • Generating videos"
|
|
200
|
+
puts " • Listing and updating resources"
|