Skip to content

Commit

Permalink
Docs/v1.4.1 (#193)
Browse files Browse the repository at this point in the history
* version 1.2.1

* version 1.3.0

* version 1.4.1
  • Loading branch information
naruse666 committed Aug 20, 2024
1 parent ea7f544 commit 8207248
Show file tree
Hide file tree
Showing 43 changed files with 1,777 additions and 6 deletions.
8 changes: 7 additions & 1 deletion apps/docs/docs/features/guardian.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ export const GuardianApiName = () => {
最大500文字までを受け付けています。

**`score_threshold`** integer optional <br/>
`0-1`までの値を受け付けています。 <br />
`0.1-1`までの値を受け付けています。 <br />
default値は`0.5`です。

**`model`** string optional <br/>
指定可能なモデル
- gpt-4o-mini
- claude-3-haiku
- gemini-1.5-flash


### リクエスト例
<details>
Expand Down
15 changes: 15 additions & 0 deletions apps/docs/docs/quick-start.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: クイックスタート
---

## APIを試してみる
APIキーを発行せずに試してみましょう。

1. [管理ページ](https://peeace.net)にアクセスし、`平和ネットAPIを使う`をクリックしてください。<br/><br/>
![](/img/top.png)

2. `ログインしないで使ってみる`から簡単にAPIを試すことができます! <br/><br/>
![](/img/anon-login.png)

3. Playgroundページで試しましょう!<br/><br/>
![](/img/playground.png)
2 changes: 1 addition & 1 deletion apps/docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const config: Config = {
lastVersion: 'current',
versions: {
current: {
label: '1.2.1 (latest)',
label: '1.4.1 (latest)',
path: '/',
},
},
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const sidebars: SidebarsConfig = {
{
type: 'category',
label: 'API 概要',
link: { type: 'doc', id: 'overview' },
items: ['how-to-use/basic'],
link: { type: 'doc', id: 'quick-start' },
items: ['quick-start','how-to-use/basic'],
},
{
type: 'category',
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function HomepageHeader() {
<div className={styles.buttons}>
<Link
className="button button--secondary button--lg"
to="/docs/overview">
Peace Net API 概要- 5min ⏱️
to="/docs/quick-start">
Peace Net API 概要- 3min ⏱️
</Link>
</div>
</div>
Expand Down
Binary file added apps/docs/static/img/anon-login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/docs/static/img/playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/docs/static/img/top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions apps/docs/versioned_docs/version-1.2.0/code-reference/golang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Go

```go
// main.go
package main

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)

var (
apiKey = "YOUR_API_KEY"
apiUrl = "https://api.peeace.net/v1/guardians/text"
)

func main() {
// リクエストを作成
body, err := json.Marshal(map[string]string{
"text": "最低な文章",
})
if err != nil {
fmt.Println("Error marshalling request body:", err)
return
}

req, err := http.NewRequest("POST", apiUrl, bytes.NewBuffer(body))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))

// リクエスト
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()

// レスポンスをチェック
if resp.StatusCode != http.StatusOK {
fmt.Println("Request failed with status:", resp.Status)
return
}

var responseBody map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&responseBody); err != nil {
fmt.Println("Error decoding response body:", err)
return
}

fmt.Println("Response:", responseBody)
}
```

### 実行

```sh
go run main.go
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# コードリファレンス

<!-- <言語名>がタイトルだと望ましい -->
- [Node.js](./node-js.md)
- [Go](./golang.md)
29 changes: 29 additions & 0 deletions apps/docs/versioned_docs/version-1.2.0/code-reference/node-js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Node.js

```js
// 変数をセット
//// YOUR_API_KEYを取得したものに変更してください
const apiKey= 'YOUR_API_KEY';

const apiUrl = "https://api.peeace.net/v1/guardians/text";
const requestBody = {
text: "最低な文章"
};

fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify(requestBody)
})
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SDK for Go

### [GitHub Issues](https://github.com/naruse666/peace-net-sdk-go/issues)
バグや機能リクエストは[Issues](https://github.com/naruse666/peace-net-sdk-go/issues)からお願いします✨ <br/>

### サンプルコード
```go
// main.go
package main

import (
"fmt"
"github.com/naruse666/peace-net-sdk-go/guardian"
"os"
)

func main() {
apiKey, ok := os.LookupEnv("API_KEY")
if !ok {
fmt.Println("API_KEY is not set")
return
}

guardianInput := guardian.GuardianInput{
Text: "最低な文章!",
APIKey: apiKey,
}

resp, err := guardian.RequestGuardian(guardianInput)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(resp)
}
```

### 実行
```go
go run main.go
```
42 changes: 42 additions & 0 deletions apps/docs/versioned_docs/version-1.2.0/errors/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: よくあるエラー
---

import useDocusaurusContext from '@docusaurus/useDocusaurusContext'

export const ApiName = () => {
const { siteConfig } = useDocusaurusContext()
return siteConfig.customFields.peace_net
}

# エラー

<ApiName />へのリクエストを完了できない場合、エラーが返される 表示されます。エラー メッセージを解析し、適切に処理することで、 予測できます。

エラー レスポンスの形式は次のとおりです。

```json
{
"error": string,
"details": string,
"status": 400 | 401 | 404 | 429 | 500 | 501
}
```

## よくあるエラー

以下に、一般的な API エラーと、次の場合に行う推奨の対応を示します。

:::info
推奨される対応を行ってもエラーが解決しない場合は、 [サポートに連絡](https://github.com/TECH-C-LT/Peace-Net/issues/new)して問題を報告してください。
:::


| エラーコード | 説明 | 推奨される対応 |
|------------|------|--------------|
| 400 Invalid Input | リクエストの形式が正しくないか、必要なパラメータが不足しています。 | リクエストのパラメータと形式を確認し、必要な情報がすべて含まれていることを確認してください。 |
| 401 Unauthorized | APIキーが無効であるか、認証に失敗しました。 | APIキーが正しいことを確認し、必要に応じて新しいキーを生成してください。 |
| 404 Invalid Request | リクエストされたリソースが見つかりません。 | URLとリソースIDが正しいことを確認してください。 |
| 429 Usage Limit Exceeded | レート制限を超えています。 | リクエストの頻度を下げるか、より高いレート制限のプランにアップグレードすることを検討してください。 |
| 500 Internal Server Error | サーバー側で予期しないエラーが発生しました。 | しばらく待ってから再試行してください。問題が続く場合はサポートに連絡してください。 |
| 501 Not Implemented | リクエストされた機能が実装されていません。 | 他のエンドポイントを使用するか、サポートに問い合わせてください。 |
89 changes: 89 additions & 0 deletions apps/docs/versioned_docs/version-1.2.0/features/guardian.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: Guardian API
---

import useDocusaurusContext from '@docusaurus/useDocusaurusContext'

export const GuardianApiName = () => {
const { siteConfig } = useDocusaurusContext()
return siteConfig.customFields.guardian
}

# <GuardianApiName />

**POST `v1/guardians/text`**

## リクエスト
#### ヘッダー
**`accept`** string

#### リクエストボディ
**`text`** string **required** <br/>
最大500文字までを受け付けています。

**`score_threshold`** integer optional <br/>
`0-1`までの値を受け付けています。 <br />
default値は`0.5`です。


### リクエスト例
<details>
<summary>cURL</summary>
<pre>
<code>
```
curl -X POST \
--location 'https://api.peeace.net/v1/guardians/text' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <API_KEY>" \
-d '{
"text": "<TEXT>"
}'
```
</code>
</pre>
</details>

## レスポンス
<details>
<summary>レスポンス例</summary>

status: `200`
<pre>
<code>
```
{
"flagged": true,
"categories": {
"sexual": false,
"hate": false,
"self_harm": true,
"violence": false,
"defamation": true
},
"category_scores": {
"sexual": 0,
"hate": 0,
"self_harm": 0.9,
"violence": 0,
"defamation": 0.8
}
}
```
</code>
</pre>
</details>

### レスポンスステータスコード

| Status Code | Description |
| ---- | ---- |
| `200` | Success |
| `400` | Validation |
| `401` | Unauthorized |
| `404` | Not Found |
| `429` | Usage Limit Exceeded |
| `500` | Internal Server Error |
| `501` | Not Implemented Error |

エラーの詳細は[よくあるエラー](/docs/errors)を参照してください。
Loading

0 comments on commit 8207248

Please sign in to comment.