Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/gradient_labs/_conversation_add_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ class Message:
# attachments contains any files that were uploaded with this message.
attachments: Optional[List[Attachment]] = None

# conversation_token is the raw sensitive token that can be optionally provided in every message.
# The latest token of the conversation will be echoed back in future Webhooks, under the header `X-GradientLabs-Token`,
# as well as in HTTP Tools using templates.
conversation_token: Optional[str] = None


def add_message(
*, client: HttpClient, conversation_id: str, params: AddMessageParams
Expand All @@ -101,6 +106,8 @@ def add_message(
body["metadata"] = params.metadata
if params.attachments is not None:
body["attachments"] = [a.to_dict() for a in params.attachments]
if params.conversation_token is not None:
body["conversation_token"] = params.conversation_token

rsp = client.post(path=f"conversations/{conversation_id}/messages", body=body)
return Message.from_dict(rsp)
7 changes: 7 additions & 0 deletions src/gradient_labs/_conversation_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class StartConversationParams:
# during the conversation. You can also use resources as parameters for your tools.
resources: Optional[Dict[str, Any]] = None

# conversation_token is the raw sensitive token that can be optionally provided when starting a conversation.
# The latest token of the conversation will be echoed back in future Webhooks, under the header `X-GradientLabs-Token`,
# as well as in HTTP Tools using templates.
conversation_token: Optional[str] = None


def start_conversation(
*, client: HttpClient, params: StartConversationParams
Expand All @@ -62,6 +67,8 @@ def start_conversation(
body["created"] = HttpClient.localize(params.created)
if params.resources is not None:
body["resources"] = params.resources
if params.conversation_token is not None:
body["conversation_token"] = params.conversation_token

rsp = client.post(
path="conversations",
Expand Down
3 changes: 3 additions & 0 deletions src/gradient_labs/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Webhook:
SCHEME = "v1"
LEEWAY = timedelta(minutes=5)

SIGNATURE_HEADER_NAME = "X-GradientLabs-Signature"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat weirdly, in our Python client, we assume the company can extract HTTP headers. We don't do this ourselves (unlike in the Go client where we extract the header ourselves).

Anyway, let's at least give them the header names!

TOKEN_HEADER_NAME = "X-GradientLabs-Token"

@classmethod
def parse_event(
cls,
Expand Down