Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base moderation to Providers #513

Open
wants to merge 4 commits into
base: v1.0
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion crates/goose-server/src/routes/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use axum::{
use bytes::Bytes;
use futures::{stream::StreamExt, Stream};
use goose::message::{Message, MessageContent};
use goose::providers::base::{Moderation, ModerationResult};
use mcp_core::{content::Content, role::Role};
use serde::Deserialize;
use serde_json::{json, Value};
Expand Down Expand Up @@ -406,7 +407,7 @@ mod tests {

#[async_trait::async_trait]
impl Provider for MockProvider {
async fn complete(
async fn complete_internal(
&self,
_system_prompt: &str,
_messages: &[Message],
Expand All @@ -423,6 +424,16 @@ mod tests {
}
}

#[async_trait::async_trait]
impl Moderation for MockProvider {
async fn moderate_content(
&self,
_content: &str,
) -> Result<ModerationResult, anyhow::Error> {
Ok(ModerationResult::new(false, None, None))
}
}

#[test]
fn test_convert_messages_user_only() {
let incoming = vec![IncomingMessage {
Expand Down
12 changes: 9 additions & 3 deletions crates/goose/src/providers/anthropic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use serde_json::{json, Value};
use std::collections::HashSet;
use std::time::Duration;

use super::base::ProviderUsage;
use super::base::{Provider, Usage};
use super::base::{Moderation, ModerationResult, Provider, ProviderUsage, Usage};
use super::configs::{AnthropicProviderConfig, ModelConfig, ProviderModelConfig};
use super::model_pricing::cost;
use super::model_pricing::model_pricing_for;
Expand Down Expand Up @@ -212,7 +211,7 @@ impl AnthropicProvider {

#[async_trait]
impl Provider for AnthropicProvider {
async fn complete(
async fn complete_internal(
&self,
system: &str,
messages: &[Message],
Expand Down Expand Up @@ -273,6 +272,13 @@ impl Provider for AnthropicProvider {
}
}

#[async_trait]
impl Moderation for AnthropicProvider {
async fn moderate_content(&self, content: &str) -> Result<ModerationResult> {
Ok(ModerationResult::new(false, None, None))
}
}

#[cfg(test)]
mod tests {
use crate::providers::configs::ModelConfig;
Expand Down
Loading
Loading