Class: Tavus::Resources::Personas
- Inherits:
-
Object
- Object
- Tavus::Resources::Personas
- Defined in:
- lib/tavus/resources/personas.rb
Instance Method Summary collapse
-
#build_patch_operation(field, value, operation: "replace") ⇒ Hash
Helper method to build patch operations.
-
#create(system_prompt: nil, **options) ⇒ Hash
Create a new persona.
-
#delete(persona_id) ⇒ Hash
Delete a persona.
-
#get(persona_id) ⇒ Hash
Get a single persona by ID.
-
#initialize(client) ⇒ Personas
constructor
A new instance of Personas.
-
#list(**options) ⇒ Hash
List all personas.
-
#patch(persona_id, operations) ⇒ Hash
Update a persona using JSON Patch operations.
-
#update_field(persona_id, field, value) ⇒ Hash
Convenient method to replace a field.
Constructor Details
#initialize(client) ⇒ Personas
Returns a new instance of Personas.
6 7 8 |
# File 'lib/tavus/resources/personas.rb', line 6 def initialize(client) @client = client end |
Instance Method Details
#build_patch_operation(field, value, operation: "replace") ⇒ Hash
Helper method to build patch operations
73 74 75 76 77 |
# File 'lib/tavus/resources/personas.rb', line 73 def build_patch_operation(field, value, operation: "replace") op = { op: operation, path: field } op[:value] = value unless operation == "remove" op end |
#create(system_prompt: nil, **options) ⇒ Hash
Create a new persona
21 22 23 24 25 26 |
# File 'lib/tavus/resources/personas.rb', line 21 def create(system_prompt: nil, **) body = .dup body[:system_prompt] = system_prompt if system_prompt @client.post("/v2/personas", body: body) end |
#delete(persona_id) ⇒ Hash
Delete a persona
92 93 94 |
# File 'lib/tavus/resources/personas.rb', line 92 def delete(persona_id) @client.delete("/v2/personas/#{persona_id}") end |
#get(persona_id) ⇒ Hash
Get a single persona by ID
31 32 33 |
# File 'lib/tavus/resources/personas.rb', line 31 def get(persona_id) @client.get("/v2/personas/#{persona_id}") end |
#list(**options) ⇒ Hash
List all personas
41 42 43 |
# File 'lib/tavus/resources/personas.rb', line 41 def list(**) @client.get("/v2/personas", params: ) end |
#patch(persona_id, operations) ⇒ Hash
Update a persona using JSON Patch operations
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/tavus/resources/personas.rb', line 55 def patch(persona_id, operations) raise ArgumentError, "Operations must be an array" unless operations.is_a?(Array) raise ArgumentError, "Operations cannot be empty" if operations.empty? # Validate each operation has required fields operations.each do |op| raise ArgumentError, "Each operation must have 'op' and 'path'" unless op[:op] && op[:path] raise ArgumentError, "Operation 'op' must be one of: add, remove, replace, copy, move, test" unless %w[add remove replace copy move test].include?(op[:op]) end @client.patch("/v2/personas/#{persona_id}", body: operations) end |
#update_field(persona_id, field, value) ⇒ Hash
Convenient method to replace a field
84 85 86 87 |
# File 'lib/tavus/resources/personas.rb', line 84 def update_field(persona_id, field, value) operation = build_patch_operation(field, value, operation: "replace") patch(persona_id, [operation]) end |