rageval-sdk 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.pyo
|
|
5
|
+
.venv/
|
|
6
|
+
venv/
|
|
7
|
+
env/
|
|
8
|
+
*.egg-info/
|
|
9
|
+
dist/
|
|
10
|
+
build/
|
|
11
|
+
.eggs/
|
|
12
|
+
|
|
13
|
+
# 環境変数(絶対にコミットしない)
|
|
14
|
+
.env
|
|
15
|
+
.env.local
|
|
16
|
+
.env.*.local
|
|
17
|
+
|
|
18
|
+
# Node.js
|
|
19
|
+
node_modules/
|
|
20
|
+
.next/
|
|
21
|
+
out/
|
|
22
|
+
|
|
23
|
+
# OS
|
|
24
|
+
.DS_Store
|
|
25
|
+
Thumbs.db
|
|
26
|
+
|
|
27
|
+
# IDE
|
|
28
|
+
.vscode/
|
|
29
|
+
.idea/
|
|
30
|
+
*.swp
|
|
31
|
+
|
|
32
|
+
# テスト・カバレッジ
|
|
33
|
+
.pytest_cache/
|
|
34
|
+
.coverage
|
|
35
|
+
htmlcov/
|
|
36
|
+
|
|
37
|
+
# Vercel
|
|
38
|
+
.vercel
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rageval-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: RAG evaluation SDK — RAGの回答品質を3行で計測
|
|
5
|
+
Project-URL: Homepage, https://github.com/A-1ro/rag-eval
|
|
6
|
+
Project-URL: Documentation, https://github.com/A-1ro/rag-eval#readme
|
|
7
|
+
Project-URL: Issues, https://github.com/A-1ro/rag-eval/issues
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: evaluation,llm,observability,rag
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Requires-Dist: httpx>=0.24.0
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# rag-eval SDK
|
|
23
|
+
|
|
24
|
+
RAGアプリの回答品質を3行で計測できるSDKです。
|
|
25
|
+
|
|
26
|
+
## インストール
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install rag-eval
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 使い方
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from rag_eval import track
|
|
36
|
+
|
|
37
|
+
# 既存のRAGコードに3行追加するだけ
|
|
38
|
+
answer = your_rag_system.query(question)
|
|
39
|
+
track(
|
|
40
|
+
question=question,
|
|
41
|
+
answer=answer,
|
|
42
|
+
chunks=[{"content": chunk.text, "source": chunk.source} for chunk in retrieved_chunks],
|
|
43
|
+
api_key="rag_eval_xxxx", # または環境変数 RAG_EVAL_API_KEY
|
|
44
|
+
latency_ms=elapsed_ms, # 任意
|
|
45
|
+
)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 非同期版(FastAPI / asyncio)
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from rag_eval import atrack
|
|
52
|
+
|
|
53
|
+
await atrack(question=question, answer=answer, chunks=chunks)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### セルフホスト版
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
track(
|
|
60
|
+
question=question,
|
|
61
|
+
answer=answer,
|
|
62
|
+
chunks=chunks,
|
|
63
|
+
api_url="https://your-own-server.com", # または環境変数 RAG_EVAL_API_URL
|
|
64
|
+
api_key="your-key",
|
|
65
|
+
)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 環境変数
|
|
69
|
+
|
|
70
|
+
| 変数名 | 説明 |
|
|
71
|
+
|--------|------|
|
|
72
|
+
| `RAG_EVAL_API_KEY` | APIキー |
|
|
73
|
+
| `RAG_EVAL_API_URL` | APIのURL(セルフホスト時) |
|
|
74
|
+
|
|
75
|
+
## ライセンス
|
|
76
|
+
|
|
77
|
+
MIT
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# rag-eval SDK
|
|
2
|
+
|
|
3
|
+
RAGアプリの回答品質を3行で計測できるSDKです。
|
|
4
|
+
|
|
5
|
+
## インストール
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install rag-eval
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使い方
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from rag_eval import track
|
|
15
|
+
|
|
16
|
+
# 既存のRAGコードに3行追加するだけ
|
|
17
|
+
answer = your_rag_system.query(question)
|
|
18
|
+
track(
|
|
19
|
+
question=question,
|
|
20
|
+
answer=answer,
|
|
21
|
+
chunks=[{"content": chunk.text, "source": chunk.source} for chunk in retrieved_chunks],
|
|
22
|
+
api_key="rag_eval_xxxx", # または環境変数 RAG_EVAL_API_KEY
|
|
23
|
+
latency_ms=elapsed_ms, # 任意
|
|
24
|
+
)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 非同期版(FastAPI / asyncio)
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from rag_eval import atrack
|
|
31
|
+
|
|
32
|
+
await atrack(question=question, answer=answer, chunks=chunks)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### セルフホスト版
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
track(
|
|
39
|
+
question=question,
|
|
40
|
+
answer=answer,
|
|
41
|
+
chunks=chunks,
|
|
42
|
+
api_url="https://your-own-server.com", # または環境変数 RAG_EVAL_API_URL
|
|
43
|
+
api_key="your-key",
|
|
44
|
+
)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 環境変数
|
|
48
|
+
|
|
49
|
+
| 変数名 | 説明 |
|
|
50
|
+
|--------|------|
|
|
51
|
+
| `RAG_EVAL_API_KEY` | APIキー |
|
|
52
|
+
| `RAG_EVAL_API_URL` | APIのURL(セルフホスト時) |
|
|
53
|
+
|
|
54
|
+
## ライセンス
|
|
55
|
+
|
|
56
|
+
MIT
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rageval-sdk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "RAG evaluation SDK — RAGの回答品質を3行で計測"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
keywords = ["rag", "llm", "evaluation", "observability"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.9",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
]
|
|
23
|
+
dependencies = ["httpx>=0.24.0"]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://github.com/A-1ro/rag-eval"
|
|
27
|
+
Documentation = "https://github.com/A-1ro/rag-eval#readme"
|
|
28
|
+
Issues = "https://github.com/A-1ro/rag-eval/issues"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.wheel]
|
|
31
|
+
packages = ["rag_eval"]
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
DEFAULT_API_URL = "https://rag-eval-api.vercel.app"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def track(
|
|
10
|
+
question: str,
|
|
11
|
+
answer: str,
|
|
12
|
+
chunks: Optional[list] = None,
|
|
13
|
+
api_key: Optional[str] = None,
|
|
14
|
+
api_url: Optional[str] = None,
|
|
15
|
+
latency_ms: Optional[int] = None,
|
|
16
|
+
) -> Optional[str]:
|
|
17
|
+
"""
|
|
18
|
+
RAGの質問・回答・チャンクをCollector APIに送信する。
|
|
19
|
+
|
|
20
|
+
失敗してもRAG本体を止めない(例外を握りつぶす)。
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
question: ユーザーの質問
|
|
24
|
+
answer: RAGの回答
|
|
25
|
+
chunks: 取得されたチャンクのリスト [{"content": "...", "source": "..."}]
|
|
26
|
+
api_key: APIキー(未指定の場合は RAG_EVAL_API_KEY 環境変数を使用)
|
|
27
|
+
api_url: APIのURL(未指定の場合はデフォルトのSaaS URLを使用)
|
|
28
|
+
latency_ms: RAGの応答時間(ミリ秒)
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
evaluation_id(成功時)または None(失敗時)
|
|
32
|
+
"""
|
|
33
|
+
url = (api_url or os.getenv("RAG_EVAL_API_URL") or DEFAULT_API_URL).rstrip("/")
|
|
34
|
+
key = api_key or os.getenv("RAG_EVAL_API_KEY")
|
|
35
|
+
|
|
36
|
+
if not key:
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
payload = {
|
|
40
|
+
"question": question,
|
|
41
|
+
"answer": answer,
|
|
42
|
+
"chunks": chunks or [],
|
|
43
|
+
"latency_ms": latency_ms,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
response = httpx.post(
|
|
48
|
+
f"{url}/api/track",
|
|
49
|
+
json=payload,
|
|
50
|
+
headers={"X-API-Key": key},
|
|
51
|
+
timeout=5.0,
|
|
52
|
+
)
|
|
53
|
+
response.raise_for_status()
|
|
54
|
+
return response.json().get("id")
|
|
55
|
+
except Exception:
|
|
56
|
+
return None
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
async def atrack(
|
|
60
|
+
question: str,
|
|
61
|
+
answer: str,
|
|
62
|
+
chunks: Optional[list] = None,
|
|
63
|
+
api_key: Optional[str] = None,
|
|
64
|
+
api_url: Optional[str] = None,
|
|
65
|
+
latency_ms: Optional[int] = None,
|
|
66
|
+
) -> Optional[str]:
|
|
67
|
+
"""
|
|
68
|
+
非同期版 track()。asyncio / FastAPI 環境向け。
|
|
69
|
+
|
|
70
|
+
引数・戻り値は track() と同じ。
|
|
71
|
+
"""
|
|
72
|
+
url = (api_url or os.getenv("RAG_EVAL_API_URL") or DEFAULT_API_URL).rstrip("/")
|
|
73
|
+
key = api_key or os.getenv("RAG_EVAL_API_KEY")
|
|
74
|
+
|
|
75
|
+
if not key:
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
payload = {
|
|
79
|
+
"question": question,
|
|
80
|
+
"answer": answer,
|
|
81
|
+
"chunks": chunks or [],
|
|
82
|
+
"latency_ms": latency_ms,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
try:
|
|
86
|
+
async with httpx.AsyncClient() as client:
|
|
87
|
+
response = await client.post(
|
|
88
|
+
f"{url}/api/track",
|
|
89
|
+
json=payload,
|
|
90
|
+
headers={"X-API-Key": key},
|
|
91
|
+
timeout=5.0,
|
|
92
|
+
)
|
|
93
|
+
response.raise_for_status()
|
|
94
|
+
return response.json().get("id")
|
|
95
|
+
except Exception:
|
|
96
|
+
return None
|