gaard-llm 0.1.0__py3-none-any.whl
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.
- gaard_llm/__init__.py +0 -0
- gaard_llm/anthropic/__init__.py +0 -0
- gaard_llm/azure_openai/__init__.py +0 -0
- gaard_llm/ollama/__init__.py +0 -0
- gaard_llm/openai/__init__.py +0 -0
- gaard_llm/openai_compatible/__init__.py +0 -0
- gaard_llm/openai_compatible/client.py +74 -0
- gaard_llm/providers/__init__.py +0 -0
- gaard_llm/providers/models.py +21 -0
- gaard_llm/vertex/__init__.py +0 -0
- gaard_llm-0.1.0.dist-info/METADATA +28 -0
- gaard_llm-0.1.0.dist-info/RECORD +14 -0
- gaard_llm-0.1.0.dist-info/WHEEL +5 -0
- gaard_llm-0.1.0.dist-info/top_level.txt +1 -0
gaard_llm/__init__.py
ADDED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import httpx
|
|
4
|
+
|
|
5
|
+
from gaard_core.errors import LlmProviderError
|
|
6
|
+
from gaard_llm.providers.models import ChatCompletionRequest, ChatCompletionResponse
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class OpenAICompatibleClient:
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
base_url: str,
|
|
13
|
+
api_key: str,
|
|
14
|
+
timeout_seconds: int = 60,
|
|
15
|
+
) -> None:
|
|
16
|
+
self.base_url = base_url.rstrip("/")
|
|
17
|
+
self.api_key = api_key
|
|
18
|
+
self.timeout_seconds = timeout_seconds
|
|
19
|
+
|
|
20
|
+
def create_chat_completion(
|
|
21
|
+
self,
|
|
22
|
+
request: ChatCompletionRequest,
|
|
23
|
+
) -> ChatCompletionResponse:
|
|
24
|
+
url = f"{self.base_url}/chat/completions"
|
|
25
|
+
|
|
26
|
+
payload: dict[str, Any] = {
|
|
27
|
+
"model": request.model,
|
|
28
|
+
"messages": [
|
|
29
|
+
{
|
|
30
|
+
"role": message.role,
|
|
31
|
+
"content": message.content,
|
|
32
|
+
}
|
|
33
|
+
for message in request.messages
|
|
34
|
+
],
|
|
35
|
+
"temperature": request.temperature,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
payload.update(request.extra_body)
|
|
39
|
+
|
|
40
|
+
headers = {
|
|
41
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
response = httpx.post(
|
|
47
|
+
url,
|
|
48
|
+
json=payload,
|
|
49
|
+
headers=headers,
|
|
50
|
+
timeout=self.timeout_seconds,
|
|
51
|
+
)
|
|
52
|
+
response.raise_for_status()
|
|
53
|
+
except httpx.HTTPStatusError as exc:
|
|
54
|
+
detail = exc.response.text.strip()
|
|
55
|
+
detail_suffix = f" {detail[:500]}" if detail else ""
|
|
56
|
+
|
|
57
|
+
raise LlmProviderError(
|
|
58
|
+
f"LLM provider returned HTTP {exc.response.status_code}.{detail_suffix}"
|
|
59
|
+
) from exc
|
|
60
|
+
except httpx.HTTPError as exc:
|
|
61
|
+
raise LlmProviderError("LLM provider request failed.") from exc
|
|
62
|
+
|
|
63
|
+
data: dict[str, Any] = response.json()
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
content = data["choices"][0]["message"]["content"]
|
|
67
|
+
except (KeyError, IndexError, TypeError) as exc:
|
|
68
|
+
raise LlmProviderError("Invalid OpenAI-compatible response format.") from exc
|
|
69
|
+
|
|
70
|
+
return ChatCompletionResponse(
|
|
71
|
+
content=content.strip(),
|
|
72
|
+
model=data.get("model"),
|
|
73
|
+
raw=data,
|
|
74
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ChatMessage(BaseModel):
|
|
7
|
+
role: str
|
|
8
|
+
content: str
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ChatCompletionRequest(BaseModel):
|
|
12
|
+
model: str
|
|
13
|
+
messages: list[ChatMessage]
|
|
14
|
+
temperature: float = 0.0
|
|
15
|
+
extra_body: dict[str, Any] = Field(default_factory=dict)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ChatCompletionResponse(BaseModel):
|
|
19
|
+
content: str
|
|
20
|
+
model: str | None = None
|
|
21
|
+
raw: dict[str, Any] = Field(default_factory=dict)
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gaard-llm
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LLM provider adapters for GAARD
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: gaard-core==0.1.0
|
|
8
|
+
Requires-Dist: httpx>=0.27.0
|
|
9
|
+
Requires-Dist: pydantic>=2.7.0
|
|
10
|
+
Provides-Extra: openai
|
|
11
|
+
Requires-Dist: openai>=1.0.0; extra == "openai"
|
|
12
|
+
Provides-Extra: anthropic
|
|
13
|
+
Requires-Dist: anthropic>=0.34.0; extra == "anthropic"
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
16
|
+
Requires-Dist: ruff>=0.5.0; extra == "dev"
|
|
17
|
+
Requires-Dist: mypy>=1.10.0; extra == "dev"
|
|
18
|
+
|
|
19
|
+
# GAARD - Governed AI Access to Relational Data
|
|
20
|
+
|
|
21
|
+
GAARD is a self-hosted AI SQL Gateway for governed natural-language access to relational data.
|
|
22
|
+
|
|
23
|
+
GAARD allows applications and users to ask questions about relational databases using natural language while keeping SQL generation, validation, execution, prompts, connectors, and auditability under control.
|
|
24
|
+
|
|
25
|
+
For more informacion see https://github.com/pkroliszewski/gaard
|
|
26
|
+
|
|
27
|
+
# This package
|
|
28
|
+
Package gaard-llm extends gaard functionality by adding support for various ai providers.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
gaard_llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
gaard_llm/anthropic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
gaard_llm/azure_openai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
gaard_llm/ollama/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
gaard_llm/openai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
gaard_llm/openai_compatible/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
gaard_llm/openai_compatible/client.py,sha256=g3-_MMGnVPinDagTCMh0qICMm5mj0ePrGvLF1_aB3nw,2218
|
|
8
|
+
gaard_llm/providers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
gaard_llm/providers/models.py,sha256=TstySxokyhbjm-XmMHedl34g3lx3QwaMUSXxGK525ks,447
|
|
10
|
+
gaard_llm/vertex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
gaard_llm-0.1.0.dist-info/METADATA,sha256=370ekzbb5Kwh1F4fMaf4hfbS64zdiJGPLnflssRMRoM,1081
|
|
12
|
+
gaard_llm-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
13
|
+
gaard_llm-0.1.0.dist-info/top_level.txt,sha256=bQIuyw6fh91AGKw_X-3cnIF-G3JB30fIir0BgjXIliM,10
|
|
14
|
+
gaard_llm-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
gaard_llm
|