Skip to content

Commit

Permalink
Pass workspaceId as metadata.user_id to Anthropic (#7513)
Browse files Browse the repository at this point in the history
* work

* pass metadata to chat interactions
  • Loading branch information
spolu authored Sep 19, 2024
1 parent 5c4cda7 commit 9412081
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion core/src/providers/anthropic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,16 @@ struct StreamMessageDelta {
pub struct AnthropicLLM {
id: String,
api_key: Option<String>,
user_id: Option<String>,
}

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<Uri> {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(())
}

Expand Down

0 comments on commit 9412081

Please sign in to comment.