From 9412081749059f0da581b6ace9c7eb448af892aa Mon Sep 17 00:00:00 2001 From: Stanislas Polu Date: Thu, 19 Sep 2024 12:14:23 +0200 Subject: [PATCH] Pass workspaceId as metadata.user_id to Anthropic (#7513) * work * pass metadata to chat interactions --- core/src/providers/anthropic.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/src/providers/anthropic.rs b/core/src/providers/anthropic.rs index 947823f81774..e93b98285c89 100644 --- a/core/src/providers/anthropic.rs +++ b/core/src/providers/anthropic.rs @@ -699,11 +699,16 @@ struct StreamMessageDelta { pub struct AnthropicLLM { id: String, api_key: Option, + user_id: Option, } impl AnthropicLLM { pub fn new(id: String) -> Self { - Self { id, api_key: None } + Self { + id, + api_key: None, + user_id: None, + } } fn messages_uri(&self) -> Result { @@ -756,6 +761,12 @@ impl AnthropicLLM { }, }); + if let Some(user_id) = self.user_id.as_ref() { + body["metadata"] = json!({ + "user_id": user_id, + }); + } + if system.is_some() { body["system"] = json!(system); } @@ -858,6 +869,12 @@ impl AnthropicLLM { "stream": true, }); + if let Some(user_id) = self.user_id.as_ref() { + body["metadata"] = json!({ + "user_id": user_id, + }); + } + if system.is_some() { body["system"] = json!(system); } @@ -1489,6 +1506,12 @@ impl LLM for AnthropicLLM { ))?, }, } + match credentials.get("DUST_WORKSPACE_ID") { + Some(workspace_id) => { + self.user_id = Some(workspace_id.clone()); + } + None => (), + } Ok(()) }