In Literal AI, the concept of a user is designed to seamlessly integrate with your application, allowing developers to create and manage user profiles that mirror their own application’s user base.
It’s important to note that the concept of User only exists at the Thread level, not at the Step level.
Filtering Threads by User
Create a User
import os
from literalai import LiteralClient
literal_client = LiteralClient( api_key= os. getenv( "LITERAL_API_KEY" ) )
@literal_client. step ( )
def my_step ( input_message) :
answer = "answer"
return answer
def run ( input_message) :
with literal_client. thread( ) as thread:
literal_client. message( content= input_message, type = "user_message" , name= "User" )
user = literal_client. api. create_user( identifier= "John Doe" )
thread. user = user
answer = my_step( input_message)
literal_client. message( content= answer, type = "assistant_message" , name= "Assistant" )
return answer
run( "Hello" )
client. flush_and_stop( )
Retrieve Threads of a User
You can retrieve all Threads of a specific User with the SDKs. You do this by using the participantId
filter.
from literalai import LiteralClient
literal_client = LiteralClient( )
user_id = '9c3d9c77-77ec-4e7c-a05e-60c97e917b0a'
threads = literal_client. api. list_threads(
filters= [ { "operator" : "eq" , "field" : "participantId" , "value" : user_id} ]
)
for d in threads. data:
print ( d. to_dict( ) )
client. flush_and_stop( )