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

feat: add article opt-out-model-improvement-dotnet-sdk #30

Open
wants to merge 6 commits into
base: main
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Opting Out of Model Improvement Partnership in Deepgram's .NET SDK

To opt out of the Deepgram Model Improvement Partnership (MIP) for sensitive content transcriptions using Deepgram's .NET SDK, use a custom parameter `mip_opt_out` in your API requests. Opting out may lead to higher costs, so it's essential to be aware of the impact on pricing before proceeding.

## Opting Out Using .NET SDK

The Deepgram .NET SDK does not natively include the `mip_opt_out` in the `PreRecordedSchema`. However, it allows for passing custom parameters to the API call, which you can use to set this option. Here's a quick example of how to do this:

### Code Example:
```csharp
using Deepgram;
using Deepgram.Models;

class Program
{
static async Task Main(string[] args)
{
var deepgramClient = new DeepgramClient("YOUR_API_KEY");
var options = new PreRecordedTranscriptionOptions
{
// Add custom parameter to opt-out of MIP
CustomParameters = new Dictionary<string, string>
{
{ "mip_opt_out", "true" }
}
};

var transcription = await deepgramClient.Transcription.PreRecordedAsync(
new Uri("YOUR_AUDIO_FILE_URL"),
options
);

Console.WriteLine(transcription.Transcript);
}
}
```

### Important Considerations:

- **Pricing Impact**: Opting out of MIP results in higher transcription costs. Ensure you verify this change through your billing or usage logs.
- **Verification**: You can confirm if the opt-out was successful by checking the price increase in the usage logs for the same transcription.

## Conclusion
Utilizing the `mip_opt_out` parameter when needed in sensitive content cases will help you manage data privacy more effectively.

For more detailed information on custom parameters in the .NET SDK, visit the [Deepgram .NET SDK documentation](https://developers.deepgram.com/docs/using-custom-parameters-sdks#net-sdk).

### References:
- [Deepgram Model Improvement Partnership Program](https://developers.deepgram.com/docs/the-deepgram-model-improvement-partnership-program)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// C# example using Deepgram SDK
// Ensure 'DeepgramApi' NuGet package is installed
// For environment variables, use a .env file or IDE settings

using System;
using System.Threading.Tasks;
using Deepgram;

namespace DeepgramExample
{
class Program
{
static async Task Main(string[] args)
{
var apiKey = Environment.GetEnvironmentVariable("DEEPGRAM_API_KEY");
var audioUrl = Environment.GetEnvironmentVariable("AUDIO_FILE_URL");

var deepgramClient = new DeepgramClient(apiKey);

var options = new Deepgram.Options.PreRecordedTranscriptionOptions {
Url = audioUrl,
MipOptOut = true
};

var response = await deepgramClient.Transcription.PrerecordedAsync(options);

Console.WriteLine(response);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Go example using Deepgram SDK
// Ensure 'github.com/deepgram/deepgram-go-sdk' is installed
// For environment variables, use a package like 'godotenv'

package main

import (
"fmt"
"os"

"github.com/deepgram/deepgram-go-sdk/deepgram"
)

func main() {
apiKey := os.Getenv("DEEPGRAM_API_KEY")
audioUrl := os.Getenv("AUDIO_FILE_URL")

dg := deepgram.New(apiKey)

options := deepgram.PreRecordedOptions{
URL: audioUrl,
MipOptOut: true,
}

response, err := dg.TranscribePr(
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// JavaScript Node.js example using axios
// Ensure 'axios' library is installed: `npm install axios`

const axios = require('axios');
require('dotenv').config();

const apiKey = process.env.DEEPGRAM_API_KEY;
const audioUrl = process.env.AUDIO_FILE_URL;

const url = 'https://api.deepgram.com/v1/listen?mip_opt_out=true';

axios.post(url, {
url: audioUrl
}, {
headers: {
'Authorization': `Token ${apiKey}`,
'Content-Type': 'application/json'
}
})
.then(response => {
console.log('Transcription:', response.data);
})
.catch(error => {
console.error('Failed to transcribe audio:', error.response.status);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Python example using requests
# Ensure 'requests' library is installed: `pip install requests`

import os
import requests

# Load environment variables
api_key = os.getenv('DEEPGRAM_API_KEY')
audio_url = os.getenv('AUDIO_FILE_URL')

url = 'https://api.deepgram.com/v1/listen?mip_opt_out=true'

headers = {
'Authorization': f'Token {api_key}',
'Content-Type': 'application/json',
}

data = {
"url": audio_url
}

response = requests.post(url, headers=headers, json=data)

if response.ok:
print("Transcription:", response.json())
else:
print("Failed to transcribe audio:", response.status_code)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Rust does not have an official Deepgram SDK, but we can use an HTTP client like `reqwest`.
// This example uses env variables and async runtime.

use reqwest::Client;
use std::env;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load environment variables
let api_key = env::var("DEEPGRAM_API_KEY").expect("DEEPGRAM_API_KEY not set");
let file_url = env::var("AUDIO_FILE_URL").expect("AUDIO_FILE_URL not set");

// URL for Deepgram API
let url = "https://api.deepgram.com/v1/listen?mip_opt_out=true";

// Making the request
let client = Client::new();
let response = client
.post(url)
.header("Authorization", format!("Token {}", api_key))
.header("Content-Type", "application/json")
.body(format!("{{\"url\": \"{}\"}}", file_url))
.send()
.await?;

// Check response
if response.status().is_success() {
let result: serde_json::Value = response.json().await?;
println!("Response: {:?}", result);
} else {
println!("Failed to transcribe audio: {}", response.status());
}

Ok(())
}