ragfly 0.2.0__tar.gz → 0.3.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.
- ragfly-0.3.0/CHANGELOG.md +10 -0
- ragfly-0.3.0/PKG-INFO +78 -0
- ragfly-0.3.0/README.md +66 -0
- ragfly-0.3.0/examples/ask_example.py +16 -0
- {ragfly-0.2.0 → ragfly-0.3.0}/pyproject.toml +2 -2
- ragfly-0.3.0/ragfly/__init__.py +21 -0
- ragfly-0.3.0/ragfly/client.py +358 -0
- ragfly-0.3.0/ragfly/models.py +60 -0
- ragfly-0.3.0/tests/parity_cases.json +40 -0
- ragfly-0.3.0/tests/test_agent_context.py +45 -0
- ragfly-0.3.0/tests/test_parity.py +76 -0
- ragfly-0.2.0/PKG-INFO +0 -61
- ragfly-0.2.0/README.md +0 -49
- ragfly-0.2.0/examples/ask_example.py +0 -22
- ragfly-0.2.0/ragfly/__init__.py +0 -5
- ragfly-0.2.0/ragfly/client.py +0 -289
- ragfly-0.2.0/ragfly/codes.py +0 -65
- ragfly-0.2.0/ragfly/models.py +0 -45
- {ragfly-0.2.0 → ragfly-0.3.0}/.github/workflows/release.yml +0 -0
- {ragfly-0.2.0 → ragfly-0.3.0}/.gitignore +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
- Talks only to the English REST `/v1` contract. An API key no longer reaches internal routes, so 0.2.0 stops working with API keys.
|
|
6
|
+
- One method per `/v1` route, plus `list_operations`, `get_operation` and `run_operation` for every operation of the RAGfly application.
|
|
7
|
+
- English models: `Document(code, name, summary, …)`, `Chunk(text, page, extra)`, `SearchResult(total_documents, …)`, `AskResponse(answer, conversation_id, extra)`.
|
|
8
|
+
- `RAGflyError` carries the public `code` and `details`.
|
|
9
|
+
- Removed: `ask(stream=True)` (`/v1/ask` returns the full answer), the client-side code translator and the Spanish `estado` alias.
|
|
10
|
+
- Every request sends `X-RAGfly-Client: sdk-python`.
|
ragfly-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ragfly
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: RAGfly Python SDK — retrieval infrastructure for your AI agents
|
|
5
|
+
Project-URL: Homepage, https://ragfly.ai
|
|
6
|
+
Project-URL: Documentation, https://api.ragfly.ai/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/RAGfly/ragfly-python
|
|
8
|
+
License: MIT
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# RAGfly Python SDK
|
|
14
|
+
|
|
15
|
+
Official Python client for [RAGfly](https://ragfly.ai). It speaks the English REST `/v1` contract.
|
|
16
|
+
|
|
17
|
+
> Using TypeScript/JavaScript? See the [TypeScript SDK](https://github.com/RAGfly/ragfly-typescript) (`npm install @ragfly/sdk`) — same surface.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install ragfly
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from ragfly import RAGfly
|
|
29
|
+
|
|
30
|
+
client = RAGfly(api_key="rf_...")
|
|
31
|
+
|
|
32
|
+
# RAG end to end
|
|
33
|
+
print(client.ask("What are the Q1 sales figures?").answer)
|
|
34
|
+
|
|
35
|
+
# Retrieval only
|
|
36
|
+
results = client.search("maintenance contracts", limit=5)
|
|
37
|
+
for doc in results.documents:
|
|
38
|
+
print(doc.name, doc.max_similarity)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Operations
|
|
42
|
+
|
|
43
|
+
Everything the RAGfly application lets your user do is available as an operation, with the same permissions and audit as the web app.
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
ops = client.list_operations()["operations"] # what this key can run
|
|
47
|
+
schema = client.get_operation("document_types.update") # input_schema / output_schema
|
|
48
|
+
|
|
49
|
+
client.run_operation("document_types.update", {"code": "TDOC_...", "name": "Invoices"})
|
|
50
|
+
|
|
51
|
+
# write_confirm operations (deletes, reverts, resets) need confirm=True
|
|
52
|
+
preview = client.run_operation("document_types.delete", {"code": "TDOC_..."})
|
|
53
|
+
assert preview["executed"] is False
|
|
54
|
+
client.run_operation("document_types.delete", {"code": "TDOC_..."}, confirm=True)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Errors raise `RAGflyError` with `status_code`, the public `code` (`NOT_FOUND`, `VALIDATION_ERROR`, …) and `details`.
|
|
58
|
+
|
|
59
|
+
## API keys
|
|
60
|
+
|
|
61
|
+
Create an API key from [app.ragfly.ai](https://app.ragfly.ai) → API Keys. A key only works on `/v1`; creating or revoking keys needs a signed-in person.
|
|
62
|
+
|
|
63
|
+
## Methods
|
|
64
|
+
|
|
65
|
+
| Area | Methods |
|
|
66
|
+
|------|---------|
|
|
67
|
+
| Session and documents | `session`, `list_documents`, `get_document`, `document_edges`, `search` |
|
|
68
|
+
| Working spaces | `list_spaces`, `get_space`, `refresh_space`, `promote_space`, `compose_spaces`, `read_space` |
|
|
69
|
+
| Queue, catalog, skills | `queue`, `list_runs`, `catalog`, `get_function`, `list_skills`, `get_skill`, `run_skill` |
|
|
70
|
+
| Answers and agents | `ask`, `agent_context`, `run_agent_tool` |
|
|
71
|
+
| Organization | `get_organization`, `update_organization`, `draft_organization` |
|
|
72
|
+
| Usage, conversations, processes | `get_usage`, `list_conversations`, `delete_conversation`, `list_processes`, `get_process`, `update_process` |
|
|
73
|
+
| Operations | `list_operations`, `get_operation`, `run_operation` |
|
|
74
|
+
|
|
75
|
+
## Links
|
|
76
|
+
|
|
77
|
+
- Docs: https://api.ragfly.ai/docs
|
|
78
|
+
- Site: https://ragfly.ai
|
ragfly-0.3.0/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# RAGfly Python SDK
|
|
2
|
+
|
|
3
|
+
Official Python client for [RAGfly](https://ragfly.ai). It speaks the English REST `/v1` contract.
|
|
4
|
+
|
|
5
|
+
> Using TypeScript/JavaScript? See the [TypeScript SDK](https://github.com/RAGfly/ragfly-typescript) (`npm install @ragfly/sdk`) — same surface.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install ragfly
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from ragfly import RAGfly
|
|
17
|
+
|
|
18
|
+
client = RAGfly(api_key="rf_...")
|
|
19
|
+
|
|
20
|
+
# RAG end to end
|
|
21
|
+
print(client.ask("What are the Q1 sales figures?").answer)
|
|
22
|
+
|
|
23
|
+
# Retrieval only
|
|
24
|
+
results = client.search("maintenance contracts", limit=5)
|
|
25
|
+
for doc in results.documents:
|
|
26
|
+
print(doc.name, doc.max_similarity)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Operations
|
|
30
|
+
|
|
31
|
+
Everything the RAGfly application lets your user do is available as an operation, with the same permissions and audit as the web app.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
ops = client.list_operations()["operations"] # what this key can run
|
|
35
|
+
schema = client.get_operation("document_types.update") # input_schema / output_schema
|
|
36
|
+
|
|
37
|
+
client.run_operation("document_types.update", {"code": "TDOC_...", "name": "Invoices"})
|
|
38
|
+
|
|
39
|
+
# write_confirm operations (deletes, reverts, resets) need confirm=True
|
|
40
|
+
preview = client.run_operation("document_types.delete", {"code": "TDOC_..."})
|
|
41
|
+
assert preview["executed"] is False
|
|
42
|
+
client.run_operation("document_types.delete", {"code": "TDOC_..."}, confirm=True)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Errors raise `RAGflyError` with `status_code`, the public `code` (`NOT_FOUND`, `VALIDATION_ERROR`, …) and `details`.
|
|
46
|
+
|
|
47
|
+
## API keys
|
|
48
|
+
|
|
49
|
+
Create an API key from [app.ragfly.ai](https://app.ragfly.ai) → API Keys. A key only works on `/v1`; creating or revoking keys needs a signed-in person.
|
|
50
|
+
|
|
51
|
+
## Methods
|
|
52
|
+
|
|
53
|
+
| Area | Methods |
|
|
54
|
+
|------|---------|
|
|
55
|
+
| Session and documents | `session`, `list_documents`, `get_document`, `document_edges`, `search` |
|
|
56
|
+
| Working spaces | `list_spaces`, `get_space`, `refresh_space`, `promote_space`, `compose_spaces`, `read_space` |
|
|
57
|
+
| Queue, catalog, skills | `queue`, `list_runs`, `catalog`, `get_function`, `list_skills`, `get_skill`, `run_skill` |
|
|
58
|
+
| Answers and agents | `ask`, `agent_context`, `run_agent_tool` |
|
|
59
|
+
| Organization | `get_organization`, `update_organization`, `draft_organization` |
|
|
60
|
+
| Usage, conversations, processes | `get_usage`, `list_conversations`, `delete_conversation`, `list_processes`, `get_process`, `update_process` |
|
|
61
|
+
| Operations | `list_operations`, `get_operation`, `run_operation` |
|
|
62
|
+
|
|
63
|
+
## Links
|
|
64
|
+
|
|
65
|
+
- Docs: https://api.ragfly.ai/docs
|
|
66
|
+
- Site: https://ragfly.ai
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Basic RAGfly SDK example."""
|
|
2
|
+
from ragfly import RAGfly
|
|
3
|
+
|
|
4
|
+
client = RAGfly(api_key="rf_your_api_key")
|
|
5
|
+
|
|
6
|
+
print(client.ask("What are the Q1 sales figures?").answer)
|
|
7
|
+
|
|
8
|
+
results = client.search("maintenance contracts", limit=5)
|
|
9
|
+
print(f"\n{results.total_documents} documents found")
|
|
10
|
+
for doc in results.documents:
|
|
11
|
+
print(f" · {doc.name} (score: {doc.rrf_score or 0:.3f})")
|
|
12
|
+
for chunk in doc.chunks[:1]:
|
|
13
|
+
print(f' "{chunk.text[:120]}…"')
|
|
14
|
+
|
|
15
|
+
for op in client.list_operations()["operations"][:5]:
|
|
16
|
+
print(op["code"], op["kind"])
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ragfly"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "RAGfly Python SDK — retrieval infrastructure for your AI agents"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -16,7 +16,7 @@ dependencies = [
|
|
|
16
16
|
[project.urls]
|
|
17
17
|
Homepage = "https://ragfly.ai"
|
|
18
18
|
Documentation = "https://api.ragfly.ai/docs"
|
|
19
|
-
Repository = "https://github.com/
|
|
19
|
+
Repository = "https://github.com/RAGfly/ragfly-python"
|
|
20
20
|
|
|
21
21
|
[tool.hatch.build.targets.wheel]
|
|
22
22
|
packages = ["ragfly"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from .client import RAGfly, RAGflyError
|
|
2
|
+
from .models import (
|
|
3
|
+
AgentContext,
|
|
4
|
+
AgentLayer,
|
|
5
|
+
AskResponse,
|
|
6
|
+
Chunk,
|
|
7
|
+
Document,
|
|
8
|
+
SearchResult,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"RAGfly",
|
|
13
|
+
"RAGflyError",
|
|
14
|
+
"SearchResult",
|
|
15
|
+
"AskResponse",
|
|
16
|
+
"Document",
|
|
17
|
+
"Chunk",
|
|
18
|
+
"AgentContext",
|
|
19
|
+
"AgentLayer",
|
|
20
|
+
]
|
|
21
|
+
__version__ = "0.3.0"
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"""RAGfly Python SDK — official client for the English REST ``/v1`` contract."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Optional
|
|
4
|
+
from urllib.parse import quote
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
|
|
8
|
+
from .models import AgentContext, AgentLayer, AskResponse, Chunk, Document, SearchResult
|
|
9
|
+
|
|
10
|
+
DEFAULT_BASE_URL = "https://api.ragfly.ai"
|
|
11
|
+
#: Default interface function for ``ask()`` (sets the conversation's LLM model).
|
|
12
|
+
DEFAULT_FUNCTION = "CHAT-USER"
|
|
13
|
+
CLIENT_HEADER = {"X-RAGfly-Client": "sdk-python"}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class RAGflyError(Exception):
|
|
17
|
+
"""A ``/v1`` error: ``status_code``, public ``code`` (e.g. ``NOT_FOUND``) and ``details``."""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
message: str,
|
|
22
|
+
status_code: Optional[int] = None,
|
|
23
|
+
code: Optional[str] = None,
|
|
24
|
+
details: Optional[dict] = None,
|
|
25
|
+
):
|
|
26
|
+
super().__init__(message)
|
|
27
|
+
self.status_code = status_code
|
|
28
|
+
self.code = code
|
|
29
|
+
self.details = details or {}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _segment(value: Any) -> str:
|
|
33
|
+
return quote(str(value), safe="")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _compact(values: dict) -> dict:
|
|
37
|
+
return {key: value for key, value in values.items() if value is not None}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _query(values: dict) -> dict:
|
|
41
|
+
return {key: ("true" if value is True else "false" if value is False else value) for key, value in _compact(values).items()}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class RAGfly:
|
|
45
|
+
"""Official RAGfly client.
|
|
46
|
+
|
|
47
|
+
Basic usage::
|
|
48
|
+
|
|
49
|
+
from ragfly import RAGfly
|
|
50
|
+
|
|
51
|
+
client = RAGfly(api_key="rf_...")
|
|
52
|
+
print(client.ask("What were Q1 sales?").answer)
|
|
53
|
+
|
|
54
|
+
Every method maps to one ``/v1`` route. Operations of the RAGfly
|
|
55
|
+
application that have no named route run through :meth:`list_operations`,
|
|
56
|
+
:meth:`get_operation` and :meth:`run_operation`.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
def __init__(
|
|
60
|
+
self,
|
|
61
|
+
api_key: str,
|
|
62
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
63
|
+
timeout: float = 60.0,
|
|
64
|
+
*,
|
|
65
|
+
transport: Optional[httpx.BaseTransport] = None,
|
|
66
|
+
):
|
|
67
|
+
self._base_url = base_url.rstrip("/")
|
|
68
|
+
self._http = httpx.Client(
|
|
69
|
+
timeout=httpx.Timeout(timeout, connect=10.0),
|
|
70
|
+
headers={"Authorization": f"Bearer {api_key}", **CLIENT_HEADER},
|
|
71
|
+
transport=transport,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
# ── Transport ────────────────────────────────────────────────────────────
|
|
75
|
+
|
|
76
|
+
def _request(self, method: str, path: str, *, params: Optional[dict] = None, body: Any = None) -> Any:
|
|
77
|
+
resp = self._http.request(
|
|
78
|
+
method,
|
|
79
|
+
f"{self._base_url}{path}",
|
|
80
|
+
params=_query(params or {}) or None,
|
|
81
|
+
json=body,
|
|
82
|
+
)
|
|
83
|
+
if resp.status_code >= 400:
|
|
84
|
+
try:
|
|
85
|
+
payload = resp.json()
|
|
86
|
+
except ValueError:
|
|
87
|
+
payload = {}
|
|
88
|
+
payload = payload if isinstance(payload, dict) else {}
|
|
89
|
+
raise RAGflyError(
|
|
90
|
+
payload.get("message") or resp.text or f"HTTP {resp.status_code}",
|
|
91
|
+
status_code=resp.status_code,
|
|
92
|
+
code=payload.get("code"),
|
|
93
|
+
details=payload.get("details"),
|
|
94
|
+
)
|
|
95
|
+
if not resp.content:
|
|
96
|
+
return None
|
|
97
|
+
return resp.json()
|
|
98
|
+
|
|
99
|
+
# ── Session and documents ────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
def session(self) -> dict:
|
|
102
|
+
"""Identity, group and entity of the credential."""
|
|
103
|
+
return self._request("GET", "/v1/session")
|
|
104
|
+
|
|
105
|
+
def list_documents(self, *, status: Optional[str] = None, limit: int = 20, page: int = 1) -> dict:
|
|
106
|
+
"""List documents. ``status`` in English, e.g. ``VECTORIZED``."""
|
|
107
|
+
return self._request("GET", "/v1/documents", params={"status": status, "limit": limit, "page": page})
|
|
108
|
+
|
|
109
|
+
def get_document(self, document_code: str) -> dict:
|
|
110
|
+
return self._request("GET", f"/v1/documents/{_segment(document_code)}")
|
|
111
|
+
|
|
112
|
+
def document_edges(self, document_code: str, *, neighbor_limit: int = 50) -> dict:
|
|
113
|
+
return self._request(
|
|
114
|
+
"GET", f"/v1/documents/{_segment(document_code)}/edges", params={"neighbor_limit": neighbor_limit}
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
def search(
|
|
118
|
+
self,
|
|
119
|
+
query: str,
|
|
120
|
+
*,
|
|
121
|
+
limit: int = 10,
|
|
122
|
+
min_similarity: float = 0.0,
|
|
123
|
+
entity_code: Optional[str] = None,
|
|
124
|
+
) -> SearchResult:
|
|
125
|
+
"""Hybrid semantic search (vector + lexical)."""
|
|
126
|
+
data = self._request(
|
|
127
|
+
"POST",
|
|
128
|
+
"/v1/documents/search",
|
|
129
|
+
body=_compact({"query": query, "limit": limit, "min_similarity": min_similarity, "entity_code": entity_code}),
|
|
130
|
+
) or {}
|
|
131
|
+
documents = [
|
|
132
|
+
Document(
|
|
133
|
+
code=d.get("code"),
|
|
134
|
+
name=d.get("name"),
|
|
135
|
+
summary=d.get("summary"),
|
|
136
|
+
location=d.get("location"),
|
|
137
|
+
url=d.get("url"),
|
|
138
|
+
rrf_score=d.get("rrf_score"),
|
|
139
|
+
max_similarity=d.get("max_similarity"),
|
|
140
|
+
rerank_score=d.get("rerank_score"),
|
|
141
|
+
fs=d.get("fs"),
|
|
142
|
+
chunks=[
|
|
143
|
+
Chunk(text=c.get("text", ""), page=c.get("page"), extra=c.get("extra") or {})
|
|
144
|
+
for c in d.get("chunks") or []
|
|
145
|
+
],
|
|
146
|
+
)
|
|
147
|
+
for d in data.get("documents") or []
|
|
148
|
+
]
|
|
149
|
+
return SearchResult(
|
|
150
|
+
query=query,
|
|
151
|
+
total_documents=data.get("total_documents", len(documents)),
|
|
152
|
+
total_chunks=data.get("total_chunks", 0),
|
|
153
|
+
duration_ms=data.get("duration_ms"),
|
|
154
|
+
documents=documents,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
# ── Working spaces ───────────────────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
def list_spaces(self, *, limit: int = 20) -> dict:
|
|
160
|
+
return self._request("GET", "/v1/spaces", params={"limit": limit})
|
|
161
|
+
|
|
162
|
+
def get_space(self, space_id: int, *, document_limit: int = 20) -> dict:
|
|
163
|
+
return self._request("GET", f"/v1/spaces/{_segment(space_id)}", params={"document_limit": document_limit})
|
|
164
|
+
|
|
165
|
+
def refresh_space(self, space_id: int) -> dict:
|
|
166
|
+
return self._request("POST", f"/v1/spaces/{_segment(space_id)}/refresh")
|
|
167
|
+
|
|
168
|
+
def promote_space(self, space_id: int) -> dict:
|
|
169
|
+
return self._request("POST", f"/v1/spaces/{_segment(space_id)}/promote")
|
|
170
|
+
|
|
171
|
+
def compose_spaces(
|
|
172
|
+
self, operation: str, space_id_a: int, space_id_b: int, *, name: str = "", space_type: str = "AREA"
|
|
173
|
+
) -> dict:
|
|
174
|
+
"""``operation``: union, intersection, difference or symmetric_difference."""
|
|
175
|
+
return self._request("POST", "/v1/spaces/compose", body={
|
|
176
|
+
"operation": operation, "space_id_a": space_id_a, "space_id_b": space_id_b,
|
|
177
|
+
"name": name, "space_type": space_type,
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
def read_space(self, space_id: int, *, resolution: str = "manifest", query: str = "", limit: int = 50) -> dict:
|
|
181
|
+
"""``resolution``: count, manifest, chunks or text."""
|
|
182
|
+
return self._request(
|
|
183
|
+
"POST", f"/v1/spaces/{_segment(space_id)}/read",
|
|
184
|
+
body={"resolution": resolution, "query": query, "limit": limit},
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# ── Queue, catalog and skills ────────────────────────────────────────────
|
|
188
|
+
|
|
189
|
+
def queue(self, *, process: Optional[str] = None, status: Optional[str] = None, limit: int = 20) -> dict:
|
|
190
|
+
return self._request("GET", "/v1/queue", params={"process": process, "status": status, "limit": limit})
|
|
191
|
+
|
|
192
|
+
def list_runs(self, *, limit: int = 10) -> dict:
|
|
193
|
+
return self._request("GET", "/v1/runs", params={"limit": limit})
|
|
194
|
+
|
|
195
|
+
def catalog(self, *, type: str = "ALL") -> dict:
|
|
196
|
+
"""``type``: ALL, FUNCTIONS or SKILLS."""
|
|
197
|
+
return self._request("GET", "/v1/catalog", params={"type": type})
|
|
198
|
+
|
|
199
|
+
def get_function(self, function_code: str) -> dict:
|
|
200
|
+
"""A function (screen) with its behaviors and the operations it allows."""
|
|
201
|
+
return self._request("GET", f"/v1/functions/{_segment(function_code)}")
|
|
202
|
+
|
|
203
|
+
def list_skills(self) -> dict:
|
|
204
|
+
return self._request("GET", "/v1/skills")
|
|
205
|
+
|
|
206
|
+
def get_skill(self, skill_code: str) -> dict:
|
|
207
|
+
return self._request("GET", f"/v1/skills/{_segment(skill_code)}")
|
|
208
|
+
|
|
209
|
+
def run_skill(self, skill_code: str, *, space_id: Optional[int] = None, document_code: Optional[str] = None) -> dict:
|
|
210
|
+
return self._request(
|
|
211
|
+
"POST", f"/v1/skills/{_segment(skill_code)}/run",
|
|
212
|
+
body=_compact({"space_id": space_id, "document_code": document_code}),
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
# ── Answers and agents ───────────────────────────────────────────────────
|
|
216
|
+
|
|
217
|
+
def ask(
|
|
218
|
+
self, question: str, *, conversation_id: Optional[int] = None, function_code: str = DEFAULT_FUNCTION
|
|
219
|
+
) -> AskResponse:
|
|
220
|
+
"""RAG end to end: retrieve and generate. Reuse ``conversation_id`` to continue."""
|
|
221
|
+
data = self._request("POST", "/v1/ask", body=_compact({
|
|
222
|
+
"question": question, "conversation_id": conversation_id, "function_code": function_code,
|
|
223
|
+
})) or {}
|
|
224
|
+
return AskResponse(
|
|
225
|
+
answer=data.get("answer", ""),
|
|
226
|
+
conversation_id=data.get("conversation_id"),
|
|
227
|
+
extra={k: v for k, v in data.items() if k not in {"answer", "conversation_id"}},
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
def agent_context(self, *, function_profile: str = "user_chat") -> AgentContext:
|
|
231
|
+
"""The authenticated prompt, identity and tools for an agent."""
|
|
232
|
+
data = self._request("GET", "/v1/agent/context", params={"function_profile": function_profile})
|
|
233
|
+
return AgentContext(
|
|
234
|
+
function_profile=data["function_profile"],
|
|
235
|
+
system_prompt=data["system_prompt"],
|
|
236
|
+
system_prompt_hash=data["system_prompt_hash"],
|
|
237
|
+
layers=[AgentLayer(**item) for item in data.get("layers", [])],
|
|
238
|
+
identity=data.get("identity") or {},
|
|
239
|
+
tools=data.get("tools") or [],
|
|
240
|
+
limits=data.get("limits") or {},
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
def run_agent_tool(self, public_name: str, arguments: dict, *, function_profile: str = "user_chat") -> Any:
|
|
244
|
+
"""Run one tool authorized by :meth:`agent_context`."""
|
|
245
|
+
if not isinstance(arguments, dict):
|
|
246
|
+
raise TypeError("arguments must be a dict")
|
|
247
|
+
return self._request(
|
|
248
|
+
"POST", f"/v1/agent/tools/{_segment(public_name)}",
|
|
249
|
+
body={"arguments": arguments, "function_profile": function_profile},
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
# ── Organization profile ─────────────────────────────────────────────────
|
|
253
|
+
|
|
254
|
+
def get_organization(self, *, entity_code: Optional[str] = None) -> dict:
|
|
255
|
+
return self._request("GET", "/v1/organization", params={"entity_code": entity_code})
|
|
256
|
+
|
|
257
|
+
def update_organization(
|
|
258
|
+
self,
|
|
259
|
+
*,
|
|
260
|
+
group_description: Optional[str] = None,
|
|
261
|
+
group_system_prompt: Optional[str] = None,
|
|
262
|
+
entity_description: Optional[str] = None,
|
|
263
|
+
entity_system_prompt: Optional[str] = None,
|
|
264
|
+
entity_code: Optional[str] = None,
|
|
265
|
+
) -> dict:
|
|
266
|
+
"""Only the fields you pass are written."""
|
|
267
|
+
return self._request("PUT", "/v1/organization", body=_compact({
|
|
268
|
+
"group_description": group_description,
|
|
269
|
+
"group_system_prompt": group_system_prompt,
|
|
270
|
+
"entity_description": entity_description,
|
|
271
|
+
"entity_system_prompt": entity_system_prompt,
|
|
272
|
+
"entity_code": entity_code,
|
|
273
|
+
}))
|
|
274
|
+
|
|
275
|
+
def draft_organization(self, *, source_text: str = "", entity_code: Optional[str] = None) -> dict:
|
|
276
|
+
return self._request(
|
|
277
|
+
"POST", "/v1/organization/draft", body=_compact({"source_text": source_text, "entity_code": entity_code})
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
# ── Usage, conversations and processes ───────────────────────────────────
|
|
281
|
+
|
|
282
|
+
def get_usage(self) -> dict:
|
|
283
|
+
return self._request("GET", "/v1/usage")
|
|
284
|
+
|
|
285
|
+
def list_conversations(self, *, function_code: Optional[str] = None, limit: int = 50) -> dict:
|
|
286
|
+
return self._request("GET", "/v1/conversations", params={"function_code": function_code, "limit": limit})
|
|
287
|
+
|
|
288
|
+
def delete_conversation(self, conversation_id: int) -> Any:
|
|
289
|
+
return self._request("DELETE", f"/v1/conversations/{_segment(conversation_id)}")
|
|
290
|
+
|
|
291
|
+
def list_processes(
|
|
292
|
+
self,
|
|
293
|
+
*,
|
|
294
|
+
status: Optional[str] = None,
|
|
295
|
+
process_type: Optional[str] = None,
|
|
296
|
+
category: Optional[str] = None,
|
|
297
|
+
mine: Optional[bool] = None,
|
|
298
|
+
only_open: Optional[bool] = None,
|
|
299
|
+
limit: int = 20,
|
|
300
|
+
page: int = 1,
|
|
301
|
+
) -> dict:
|
|
302
|
+
return self._request("GET", "/v1/processes", params={
|
|
303
|
+
"status": status, "process_type": process_type, "category": category,
|
|
304
|
+
"mine": mine, "only_open": only_open, "limit": limit, "page": page,
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
def get_process(self, process_code: str) -> dict:
|
|
308
|
+
return self._request("GET", f"/v1/processes/{_segment(process_code)}")
|
|
309
|
+
|
|
310
|
+
def update_process(
|
|
311
|
+
self,
|
|
312
|
+
process_code: str,
|
|
313
|
+
*,
|
|
314
|
+
status: Optional[str] = None,
|
|
315
|
+
priority: Optional[str] = None,
|
|
316
|
+
name: Optional[str] = None,
|
|
317
|
+
description: Optional[str] = None,
|
|
318
|
+
comments: Optional[str] = None,
|
|
319
|
+
assigned_to: Optional[str] = None,
|
|
320
|
+
due_at: Optional[str] = None,
|
|
321
|
+
finished_at: Optional[str] = None,
|
|
322
|
+
cost: Optional[float] = None,
|
|
323
|
+
) -> dict:
|
|
324
|
+
"""Only the fields you pass are written."""
|
|
325
|
+
return self._request("PATCH", f"/v1/processes/{_segment(process_code)}", body=_compact({
|
|
326
|
+
"status": status, "priority": priority, "name": name, "description": description,
|
|
327
|
+
"comments": comments, "assigned_to": assigned_to, "due_at": due_at,
|
|
328
|
+
"finished_at": finished_at, "cost": cost,
|
|
329
|
+
}))
|
|
330
|
+
|
|
331
|
+
# ── Generic operations ───────────────────────────────────────────────────
|
|
332
|
+
|
|
333
|
+
def list_operations(self) -> dict:
|
|
334
|
+
"""Operations this credential can run: code, kind and confirm_required."""
|
|
335
|
+
return self._request("GET", "/v1/operations")
|
|
336
|
+
|
|
337
|
+
def get_operation(self, code: str) -> dict:
|
|
338
|
+
"""One operation with its ``input_schema`` and ``output_schema``."""
|
|
339
|
+
return self._request("GET", f"/v1/operations/{_segment(code)}")
|
|
340
|
+
|
|
341
|
+
def run_operation(self, code: str, input: Optional[dict] = None, *, confirm: bool = False) -> dict:
|
|
342
|
+
"""Run an operation. A ``write_confirm`` operation only runs with ``confirm=True``;
|
|
343
|
+
without it the result is ``{"executed": False, "preview": ...}``."""
|
|
344
|
+
return self._request(
|
|
345
|
+
"POST", f"/v1/operations/{_segment(code)}:execute",
|
|
346
|
+
body={"input": input or {}, "confirm": bool(confirm)},
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
# ── Lifecycle ────────────────────────────────────────────────────────────
|
|
350
|
+
|
|
351
|
+
def close(self) -> None:
|
|
352
|
+
self._http.close()
|
|
353
|
+
|
|
354
|
+
def __enter__(self):
|
|
355
|
+
return self
|
|
356
|
+
|
|
357
|
+
def __exit__(self, *_):
|
|
358
|
+
self.close()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@dataclass
|
|
6
|
+
class Chunk:
|
|
7
|
+
text: str
|
|
8
|
+
page: Optional[int] = None
|
|
9
|
+
extra: dict = field(default_factory=dict)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class Document:
|
|
14
|
+
code: Optional[str]
|
|
15
|
+
name: Optional[str]
|
|
16
|
+
summary: Optional[str] = None
|
|
17
|
+
location: Optional[str] = None
|
|
18
|
+
url: Optional[str] = None
|
|
19
|
+
rrf_score: Optional[float] = None
|
|
20
|
+
max_similarity: Optional[float] = None
|
|
21
|
+
rerank_score: Optional[float] = None
|
|
22
|
+
#: How to open the original file (see ``fs.how_to_open``).
|
|
23
|
+
fs: Optional[dict] = None
|
|
24
|
+
chunks: list[Chunk] = field(default_factory=list)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass
|
|
28
|
+
class SearchResult:
|
|
29
|
+
query: str
|
|
30
|
+
total_documents: int
|
|
31
|
+
total_chunks: int
|
|
32
|
+
duration_ms: Optional[float]
|
|
33
|
+
documents: list[Document]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class AskResponse:
|
|
38
|
+
"""Full answer of :meth:`RAGfly.ask`."""
|
|
39
|
+
answer: str
|
|
40
|
+
conversation_id: Optional[int]
|
|
41
|
+
#: Remaining fields of the answer (citations, usage, message id…).
|
|
42
|
+
extra: dict = field(default_factory=dict)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class AgentLayer:
|
|
47
|
+
code: str
|
|
48
|
+
name: str
|
|
49
|
+
sha256: str
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class AgentContext:
|
|
54
|
+
function_profile: str
|
|
55
|
+
system_prompt: str
|
|
56
|
+
system_prompt_hash: str
|
|
57
|
+
layers: list[AgentLayer] = field(default_factory=list)
|
|
58
|
+
identity: dict = field(default_factory=dict)
|
|
59
|
+
tools: list[dict] = field(default_factory=list)
|
|
60
|
+
limits: dict = field(default_factory=dict)
|