Skip to content

Commit c735b9d

Browse files
Add Spam Classify
1 parent ef9af72 commit c735b9d

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,44 @@ client.Task.FraudSpamicity(mirage.FraudSpamicityRequest {
405405
}
406406
```
407407

408+
#### ➡️ Spam Classify
409+
410+
* **Method:** `client.Task.SpamClassify(data)`
411+
* **Reference:** [Spam Classify](https://docs.mirage-ai.com/references/api/v1/#spam-classify)
412+
413+
* **Request:**
414+
415+
```go
416+
client.Task.SpamClassify(mirage.SpamClassifyRequest {
417+
Sender: mirage.SpamClassifyRequestSender {
418+
Name: "John Doe",
419+
420+
},
421+
422+
Transcript: []mirage.SpamClassifyRequestTranscript {
423+
mirage.SpamClassifyRequestTranscript {
424+
From: "customer",
425+
Origin: "chat",
426+
Text: "Hello, I would like to discuss your services",
427+
},
428+
},
429+
})
430+
```
431+
432+
* **Response:**
433+
434+
```json
435+
{
436+
"reason": "processed",
437+
438+
"data": {
439+
"class": "spam",
440+
"confidence": 0.13,
441+
"logprob": -0.10
442+
}
443+
}
444+
```
445+
408446
### Data API
409447

410448
#### ➡️ Context Ingest

examples/task_spam_classify/main.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// go-mirage-api
2+
//
3+
// Copyright 2024, Valerian Saliou
4+
// Author: Valerian Saliou <[email protected]>
5+
6+
package main
7+
8+
import (
9+
"github.com/mirage-ai-com/go-mirage-api"
10+
"fmt"
11+
)
12+
13+
const (
14+
CONFIG_USER_ID = "ui_xxxxxx"
15+
CONFIG_SECRET_KEY = "sk_xxxxxx"
16+
)
17+
18+
func main() {
19+
client := mirage.New(CONFIG_USER_ID, CONFIG_SECRET_KEY)
20+
21+
// Spam classification on email messages
22+
data, err := client.Task.SpamClassify(mirage.SpamClassifyRequest {
23+
Sender: mirage.SpamClassifyRequestSender {
24+
Name: "John Doe",
25+
26+
},
27+
28+
Transcript: []mirage.SpamClassifyRequestTranscript {
29+
mirage.SpamClassifyRequestTranscript {
30+
From: "customer",
31+
Origin: "chat",
32+
Text: "Hello, I would like to discuss your services",
33+
},
34+
},
35+
})
36+
37+
if err != nil {
38+
fmt.Printf("Error: %s", err)
39+
} else {
40+
fmt.Printf("Spam classify results (raw): %s\n", data)
41+
}
42+
}

task_spam.go

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// go-mirage-api
2+
//
3+
// Copyright 2024, Valerian Saliou
4+
// Author: Valerian Saliou <[email protected]>
5+
6+
package mirage
7+
8+
9+
// SpamClassifyRequest mapping
10+
type SpamClassifyRequest struct {
11+
Sender SpamClassifyRequestSender `json:"sender"`
12+
Transcript []SpamClassifyRequestTranscript `json:"transcript"`
13+
}
14+
15+
// SpamClassifyRequestSender mapping
16+
type SpamClassifyRequestSender struct {
17+
Name string `json:"name"`
18+
Email string `json:"email"`
19+
}
20+
21+
// SpamClassifyRequestTranscript mapping
22+
type SpamClassifyRequestTranscript struct {
23+
From string `json:"from"`
24+
Origin string `json:"origin"`
25+
Text string `json:"text"`
26+
}
27+
28+
29+
// SpamClassifyResponseData mapping
30+
type SpamClassifyResponseData struct {
31+
Data *SpamClassifyResponse `json:"data"`
32+
}
33+
34+
// SpamClassifyResponse mapping
35+
type SpamClassifyResponse struct {
36+
Class string `json:"class"`
37+
Confidence float32 `json:"confidence"`
38+
LogProb float32 `json:"logprob"`
39+
}
40+
41+
42+
// String returns the string representation of SpamClassifyResponse
43+
func (instance SpamClassifyResponse) String() string {
44+
return Stringify(instance)
45+
}
46+
47+
48+
// SpamClassify spam check classification on spammy emails using a sender name, sender email and transcript.
49+
func (service *TaskService) SpamClassify(data SpamClassifyRequest) (*SpamClassifyResponse, error) {
50+
req, _ := service.client.NewRequest("POST", "task/spam/classify", data)
51+
52+
result := new(SpamClassifyResponseData)
53+
_, err := service.client.Do(req, result)
54+
if err != nil {
55+
return nil, err
56+
}
57+
58+
return result.Data, err
59+
}

0 commit comments

Comments
 (0)