Import required modules for Threads, Messages, Feedback, and Users. More details about these concepts and data types can be found on the overview page.
Threads are a flexible data format that support customizable message types, including user, AI response, RAG lookup, and other. You can optionally specify when a thread was created using the createdAt field.
melodiClient = MelodiClient(verbose=True)threadExternalId ="external-thread-id-1"externalUser = User( externalId="test-user-id-1", name="Test User", email="test-user@example.com", segments={"team":"engineering",})message1 = Message( externalId="1", role='user', content='Hello!',)message2 = Message( externalId="2", role='assistant', content='Hi! How can I help you today?',)message3 = Message( externalId="3", role='user', content="What's the company's primary brand color?",)message4 = Message( externalId="4", role='RAG lookup',type='json', jsonContent={"BrandColorInfo":{"type":"primary","color":"blue","hexCode":"#1570EF"}})message5 = Message( externalId="5", role='assistant', content="The company's primary brand color is blue #1570EF.",)thread = Thread( projectName="Melodi SDK Test", externalId=threadExternalId, messages=[message1, message2, message3, message4, message5], externalUser=externalUser, createdAt=datetime(2024,1,1,12,0,0)# Example date)melodi_thread = melodiClient.threads.create_or_update(thread)print(melodi_thread)
Attributes are additional metadata that can be added to feedback that becomes filterable in the UI. Feedback attributes can be created from the Settings page.
These attributes and options need to already exist in your organization or this call will fail
feedback_with_attributes = Feedback( externalThreadId=threadExternalId, feedbackText="This is so funny",# These attributes and options need to already exist in your organization# Or this call will fail attributes={"Humor Level":"High",})melodi_feedback_with_attributes = melodiClient.feedback.create(feedback_with_attributes)print(melodi_feedback_with_attributes)