POST
/
api
/
clone
/
generate_response
curl --location \
--request POST 'https://api.withdelphi.com/api/clone/generate_response' \
--header 'x-api-key: <key>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "conversation_id": "b4177da8-40fc-4e5f-9c26-f7915d7e35e3",
    "user_message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
}'
{
  "clone_response": {
    "conversation_id": "b4177da8-40fc-4e5f-9c26-f7915d7e35e3",
    "text": "Sed tincidunt mauris vitae elit fringilla, sit amet finibus mauris rhoncus.",
    "created_at": "2023-06-04T15:32:04+00:00"
  }
}

Body

conversation_id
uuid

The id of the conversation that you want the clone generated response to be a part of Clone responses use the history of the selectd conversation while generating a response, so ensure that this id is correct Use the Get Conversation History endpoint if you would like to see the previous messages in a given conversation in order to validate

user_message
string

The text of the message that you are sending to the clone to get a response

image_url
string
default: "None"

Publicly accessible link to an image if you want to use clone vision capabilities.

stream
boolean
default: "false"

Determines whether or not the response will be the default response format, or if the clone’s response will be streamed back to the requester token by token in a stream of Server-Sent Events

⚠️ Prerequisite ⚠️

In order for the clone to be able to generate responses it must have a purpose, description, and at least one document all added on the clone editing page.

If your clone does not yet, you will receive a 403 response from this endpoint warning you to add these before continuing.

Default Response

clone_response
object
conversation_id
uuid

The id of the conversation that the generated clone response belongs to

text
string

The text of the generated clone response

created_at
datetime

UTC datetime string of when the clone’s response was generated

citations
array

An array of citations that are used in the clone’s response (url, title, text, and type)

imageUrl
string

A publicly accessible image url (if any) that the clone may send when appropriate for its response.

affiliate
dict

Affiliate product (if any) related to the user’s query.

Stream Response

The stream response will send the clone respoonse back to the user in a stream of server-sent events as tokens in the response become available

The format of the events are similar to the Default Response except:

  • There is one extra field in the stream response type, current_token
  • The clone_response field is null while the response is still generating. The response event will include the full details at the end of the stream in the last event

View the Example Stream Response on the sidebar to see an example

current_token
string

The next generated token in the clone’s response string

The clone has finished generating when this is [DONE], indicating the last event in the stream

clone_response
null or object

During the stream of events before the final event this field will not be present.

In the last event in the stream, when current_token is [DONE]. this will contain the same information as the Default Response above

Example Python code to accept a stream of server-sent events

import os
import json
import requests


# The base url for the API (fill in your actual base url here)
base_url = "https://api.withdelphi.com"

# The endpoint path
endpoint = "/api/clone/generate_response"

# Combine base url and endpoint
url = base_url + endpoint

# Your parameters (replace with actual parameters)
params = {
    'conversation_id': '<my_convo_id>',
    'user_message': 'Hello my clone friend',
    'slug': 'my-test-clone',
    'stream': True
}

# Your API key
api_key = os.getenv("DELPHI_API_KEY")

# Headers
headers = {
    'x-api-key': api_key
}

# Making a POST request
response = requests.post(url, json=params, headers=headers, stream=True)
response_text = ""

# Process the stream of server-sent events
if response.status_code == 200:
    print("Stream started. Processing tokens...")
    for line in response.iter_lines():
        if line:
            decoded_line = line.decode("utf-8")
            if decoded_line.startswith("data:"):
                event_data = decoded_line[6:]
                event = json.loads(event_data)
                current_token = event.get("current_token")
                if current_token == "[DONE]":
                    print(decoded_line)
                    print(f"Stream finished. Final response: {response_text}")
                    break
                else:
                    print(f"Current token: '{current_token}'")
                    response_text += current_token
else:
    print(f"Error: {response.status_code}")
    print(response.text)