clovis 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.
- clovis-0.3.0/PKG-INFO +98 -0
- clovis-0.3.0/README.md +74 -0
- {clovis-0.2.0 → clovis-0.3.0}/pyproject.toml +1 -1
- {clovis-0.2.0 → clovis-0.3.0}/ruvector.db +0 -0
- {clovis-0.2.0 → clovis-0.3.0}/src/clovis/__init__.py +1 -1
- clovis-0.3.0/src/clovis/_client.py +170 -0
- clovis-0.3.0/test_live.py +108 -0
- clovis-0.2.0/PKG-INFO +0 -79
- clovis-0.2.0/README.md +0 -55
- clovis-0.2.0/src/clovis/_client.py +0 -154
- clovis-0.2.0/test_live.py +0 -78
- {clovis-0.2.0 → clovis-0.3.0}/src/clovis/_cli.py +0 -0
- {clovis-0.2.0 → clovis-0.3.0}/src/clovis/_server.py +0 -0
clovis-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: clovis
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: cloooooo — personal LLM client, prompt/context/thinking interface over local Ollama
|
|
5
|
+
Author: Clovis Sfeir
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: ai,llm,local-ai,ollama,openai
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Requires-Dist: fastapi>=0.111
|
|
18
|
+
Requires-Dist: httpx>=0.27
|
|
19
|
+
Requires-Dist: pydantic>=2.0
|
|
20
|
+
Requires-Dist: rich>=13.0
|
|
21
|
+
Requires-Dist: typer>=0.12
|
|
22
|
+
Requires-Dist: uvicorn[standard]>=0.30
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# clovis
|
|
26
|
+
|
|
27
|
+
Client Python personnel pour un LLM local via [Ollama](https://ollama.com). Interface ultra-simple : `prompt`, `negative_prompt`, `thinking`, `context`.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install clovis
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from clovis import cloooooo
|
|
39
|
+
|
|
40
|
+
ai = cloooooo()
|
|
41
|
+
|
|
42
|
+
# Appel direct
|
|
43
|
+
print(ai("Explique les trous noirs"))
|
|
44
|
+
|
|
45
|
+
# Avec options
|
|
46
|
+
print(ai(
|
|
47
|
+
"Génère un poème sur la mer",
|
|
48
|
+
negative_prompt="pas de rimes",
|
|
49
|
+
thinking=True,
|
|
50
|
+
context="Tu es un poète du 19e siècle.",
|
|
51
|
+
))
|
|
52
|
+
|
|
53
|
+
# Streaming token par token
|
|
54
|
+
for token in ai.stream("Raconte une histoire courte"):
|
|
55
|
+
print(token, end="", flush=True)
|
|
56
|
+
|
|
57
|
+
# Conversation avec mémoire
|
|
58
|
+
conv = ai.conversation(context="Tu es un expert en finance.")
|
|
59
|
+
conv("Explique le CAPM")
|
|
60
|
+
conv("Et ses limites ?") # se souvient de la réponse précédente
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## CLI
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
clovis "Explique les trous noirs" # question directe
|
|
67
|
+
clovis "Génère un poème" --no "sans rimes" # avec negative prompt
|
|
68
|
+
clovis "Résous ce problème" --think # mode réflexion
|
|
69
|
+
clovis repl # conversation interactive
|
|
70
|
+
clovis serve --port 8000 # démarre le serveur API
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## API server
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
clovis serve --port 8000 --key sk-montoken
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Requête :
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
curl -X POST http://localhost:8000/ia \
|
|
83
|
+
-H "Authorization: Bearer sk-montoken" \
|
|
84
|
+
-H "Content-Type: application/json" \
|
|
85
|
+
-d '{"prompt": "Bonjour !", "thinking": false}'
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Réponse : `{"response": "Bonjour ! Comment puis-je t'aider ?"}`
|
|
89
|
+
|
|
90
|
+
Streaming : ajouter `"stream": true` → réponse en `text/plain` token par token.
|
|
91
|
+
|
|
92
|
+
## Config
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
export CLOVIS_MODEL="qwen3-72b-q5km" # modèle Ollama
|
|
96
|
+
export CLOVIS_OLLAMA_URL="http://localhost:11434"
|
|
97
|
+
export CLOVIS_API_KEY="sk-..." # clé API pour le serveur
|
|
98
|
+
```
|
clovis-0.3.0/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# clovis
|
|
2
|
+
|
|
3
|
+
Client Python personnel pour un LLM local via [Ollama](https://ollama.com). Interface ultra-simple : `prompt`, `negative_prompt`, `thinking`, `context`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install clovis
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from clovis import cloooooo
|
|
15
|
+
|
|
16
|
+
ai = cloooooo()
|
|
17
|
+
|
|
18
|
+
# Appel direct
|
|
19
|
+
print(ai("Explique les trous noirs"))
|
|
20
|
+
|
|
21
|
+
# Avec options
|
|
22
|
+
print(ai(
|
|
23
|
+
"Génère un poème sur la mer",
|
|
24
|
+
negative_prompt="pas de rimes",
|
|
25
|
+
thinking=True,
|
|
26
|
+
context="Tu es un poète du 19e siècle.",
|
|
27
|
+
))
|
|
28
|
+
|
|
29
|
+
# Streaming token par token
|
|
30
|
+
for token in ai.stream("Raconte une histoire courte"):
|
|
31
|
+
print(token, end="", flush=True)
|
|
32
|
+
|
|
33
|
+
# Conversation avec mémoire
|
|
34
|
+
conv = ai.conversation(context="Tu es un expert en finance.")
|
|
35
|
+
conv("Explique le CAPM")
|
|
36
|
+
conv("Et ses limites ?") # se souvient de la réponse précédente
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## CLI
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
clovis "Explique les trous noirs" # question directe
|
|
43
|
+
clovis "Génère un poème" --no "sans rimes" # avec negative prompt
|
|
44
|
+
clovis "Résous ce problème" --think # mode réflexion
|
|
45
|
+
clovis repl # conversation interactive
|
|
46
|
+
clovis serve --port 8000 # démarre le serveur API
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## API server
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
clovis serve --port 8000 --key sk-montoken
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Requête :
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
curl -X POST http://localhost:8000/ia \
|
|
59
|
+
-H "Authorization: Bearer sk-montoken" \
|
|
60
|
+
-H "Content-Type: application/json" \
|
|
61
|
+
-d '{"prompt": "Bonjour !", "thinking": false}'
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Réponse : `{"response": "Bonjour ! Comment puis-je t'aider ?"}`
|
|
65
|
+
|
|
66
|
+
Streaming : ajouter `"stream": true` → réponse en `text/plain` token par token.
|
|
67
|
+
|
|
68
|
+
## Config
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
export CLOVIS_MODEL="qwen3-72b-q5km" # modèle Ollama
|
|
72
|
+
export CLOVIS_OLLAMA_URL="http://localhost:11434"
|
|
73
|
+
export CLOVIS_API_KEY="sk-..." # clé API pour le serveur
|
|
74
|
+
```
|
|
Binary file
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from typing import Iterator, Optional
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
_SERVER_URL = "https://cloooooo.com" # API publique par défaut
|
|
10
|
+
_OLLAMA_URL = "http://localhost:11434" # fallback local
|
|
11
|
+
_MODEL = "qwen3:14b"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _build_messages(
|
|
15
|
+
prompt: str,
|
|
16
|
+
context: Optional[str],
|
|
17
|
+
negative_prompt: Optional[str],
|
|
18
|
+
thinking: bool,
|
|
19
|
+
history: list[dict],
|
|
20
|
+
) -> list[dict]:
|
|
21
|
+
system_parts = []
|
|
22
|
+
if context:
|
|
23
|
+
system_parts.append(context)
|
|
24
|
+
if negative_prompt:
|
|
25
|
+
system_parts.append(f"Évite absolument dans ta réponse : {negative_prompt}")
|
|
26
|
+
if thinking:
|
|
27
|
+
system_parts.append("Réfléchis étape par étape avant de répondre.")
|
|
28
|
+
|
|
29
|
+
messages = []
|
|
30
|
+
if system_parts:
|
|
31
|
+
messages.append({"role": "system", "content": "\n".join(system_parts)})
|
|
32
|
+
messages.extend(history)
|
|
33
|
+
messages.append({"role": "user", "content": prompt})
|
|
34
|
+
return messages
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Conversation:
|
|
38
|
+
def __init__(self, ai: "cloooooo", context: Optional[str] = None) -> None:
|
|
39
|
+
self._ai = ai
|
|
40
|
+
self._context = context
|
|
41
|
+
self._history: list[dict] = []
|
|
42
|
+
|
|
43
|
+
def __call__(self, prompt: str, *, negative_prompt: Optional[str] = None, thinking: bool = False) -> str:
|
|
44
|
+
messages = _build_messages(prompt, self._context, negative_prompt, thinking, self._history)
|
|
45
|
+
reply = self._ai._send(messages)
|
|
46
|
+
self._history += [{"role": "user", "content": prompt}, {"role": "assistant", "content": reply}]
|
|
47
|
+
return reply
|
|
48
|
+
|
|
49
|
+
def stream(self, prompt: str, *, negative_prompt: Optional[str] = None, thinking: bool = False) -> Iterator[str]:
|
|
50
|
+
messages = _build_messages(prompt, self._context, negative_prompt, thinking, self._history)
|
|
51
|
+
full = ""
|
|
52
|
+
for token in self._ai._stream(messages):
|
|
53
|
+
full += token
|
|
54
|
+
yield token
|
|
55
|
+
self._history += [{"role": "user", "content": prompt}, {"role": "assistant", "content": full}]
|
|
56
|
+
|
|
57
|
+
def reset(self) -> None:
|
|
58
|
+
self._history.clear()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class cloooooo:
|
|
62
|
+
"""
|
|
63
|
+
from clovis import cloooooo
|
|
64
|
+
|
|
65
|
+
ai = cloooooo() # → cloooooo.com (aucune config requise)
|
|
66
|
+
ai = cloooooo(local=True) # → localhost:11434
|
|
67
|
+
ai = cloooooo(server="http://...") # → serveur custom
|
|
68
|
+
|
|
69
|
+
print(ai("Explique les trous noirs"))
|
|
70
|
+
print(ai("Écris un poème", negative_prompt="sans rimes", thinking=True))
|
|
71
|
+
for token in ai.stream("Raconte une histoire"): print(token, end="", flush=True)
|
|
72
|
+
conv = ai.conversation(context="Tu es un expert en finance")
|
|
73
|
+
conv("Explique le CAPM") ; conv("Et ses limites ?")
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
def __init__(
|
|
77
|
+
self,
|
|
78
|
+
server: Optional[str] = None,
|
|
79
|
+
*,
|
|
80
|
+
local: bool = False,
|
|
81
|
+
ollama_url: Optional[str] = None,
|
|
82
|
+
model: str = _MODEL,
|
|
83
|
+
) -> None:
|
|
84
|
+
# Priorité : server arg > CLOVIS_SERVER env > cloooooo.com
|
|
85
|
+
# Si local=True ou CLOVIS_OLLAMA_URL défini → mode Ollama direct
|
|
86
|
+
env_server = os.getenv("CLOVIS_SERVER")
|
|
87
|
+
env_ollama = os.getenv("CLOVIS_OLLAMA_URL")
|
|
88
|
+
|
|
89
|
+
if local or ollama_url or env_ollama:
|
|
90
|
+
self._mode = "ollama"
|
|
91
|
+
self._url = ollama_url or env_ollama or _OLLAMA_URL
|
|
92
|
+
self._model = os.getenv("CLOVIS_MODEL", model)
|
|
93
|
+
else:
|
|
94
|
+
self._mode = "server"
|
|
95
|
+
self._url = server or env_server or _SERVER_URL
|
|
96
|
+
|
|
97
|
+
self._http = httpx.Client()
|
|
98
|
+
|
|
99
|
+
def __call__(self, prompt: str, *, negative_prompt: Optional[str] = None, thinking: bool = False, context: Optional[str] = None) -> str:
|
|
100
|
+
if self._mode == "server":
|
|
101
|
+
return self._call_server(prompt, negative_prompt=negative_prompt, thinking=thinking, context=context)
|
|
102
|
+
messages = _build_messages(prompt, context, negative_prompt, thinking, [])
|
|
103
|
+
return self._send(messages)
|
|
104
|
+
|
|
105
|
+
def stream(self, prompt: str, *, negative_prompt: Optional[str] = None, thinking: bool = False, context: Optional[str] = None) -> Iterator[str]:
|
|
106
|
+
if self._mode == "server":
|
|
107
|
+
yield from self._stream_server(prompt, negative_prompt=negative_prompt, thinking=thinking, context=context)
|
|
108
|
+
return
|
|
109
|
+
messages = _build_messages(prompt, context, negative_prompt, thinking, [])
|
|
110
|
+
yield from self._stream(messages)
|
|
111
|
+
|
|
112
|
+
def conversation(self, context: Optional[str] = None) -> Conversation:
|
|
113
|
+
return Conversation(self, context=context)
|
|
114
|
+
|
|
115
|
+
# --- mode server (cloooooo.com/ia) ---
|
|
116
|
+
|
|
117
|
+
def _call_server(self, prompt: str, **kwargs) -> str:
|
|
118
|
+
resp = self._http.post(
|
|
119
|
+
f"{self._url}/ia",
|
|
120
|
+
json={"prompt": prompt, **{k: v for k, v in kwargs.items() if v is not None}},
|
|
121
|
+
timeout=120,
|
|
122
|
+
)
|
|
123
|
+
resp.raise_for_status()
|
|
124
|
+
return resp.json()["response"]
|
|
125
|
+
|
|
126
|
+
def _stream_server(self, prompt: str, **kwargs) -> Iterator[str]:
|
|
127
|
+
with self._http.stream(
|
|
128
|
+
"POST",
|
|
129
|
+
f"{self._url}/ia",
|
|
130
|
+
json={"prompt": prompt, "stream": True, **{k: v for k, v in kwargs.items() if v is not None}},
|
|
131
|
+
timeout=120,
|
|
132
|
+
) as resp:
|
|
133
|
+
resp.raise_for_status()
|
|
134
|
+
for chunk in resp.iter_text():
|
|
135
|
+
if chunk:
|
|
136
|
+
yield chunk
|
|
137
|
+
|
|
138
|
+
# --- mode ollama (local) ---
|
|
139
|
+
|
|
140
|
+
def _send(self, messages: list[dict]) -> str:
|
|
141
|
+
resp = self._http.post(
|
|
142
|
+
f"{self._url}/api/chat",
|
|
143
|
+
json={"model": self._model, "messages": messages, "stream": False, "think": False},
|
|
144
|
+
timeout=120,
|
|
145
|
+
)
|
|
146
|
+
resp.raise_for_status()
|
|
147
|
+
return resp.json()["message"]["content"]
|
|
148
|
+
|
|
149
|
+
def _stream(self, messages: list[dict]) -> Iterator[str]:
|
|
150
|
+
with self._http.stream(
|
|
151
|
+
"POST",
|
|
152
|
+
f"{self._url}/api/chat",
|
|
153
|
+
json={"model": self._model, "messages": messages, "stream": True, "think": False},
|
|
154
|
+
timeout=120,
|
|
155
|
+
) as resp:
|
|
156
|
+
resp.raise_for_status()
|
|
157
|
+
for line in resp.iter_lines():
|
|
158
|
+
if not line:
|
|
159
|
+
continue
|
|
160
|
+
data = json.loads(line)
|
|
161
|
+
token = data.get("message", {}).get("content", "")
|
|
162
|
+
if token:
|
|
163
|
+
yield token
|
|
164
|
+
if data.get("done"):
|
|
165
|
+
break
|
|
166
|
+
|
|
167
|
+
@classmethod
|
|
168
|
+
def serve(cls, port: int = 8000, host: str = "0.0.0.0", api_key: Optional[str] = None) -> None:
|
|
169
|
+
from ._server import start_server
|
|
170
|
+
start_server(host=host, port=port, api_key=api_key)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Test live end-to-end — lance avec : python3 test_live.py"""
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_import():
|
|
7
|
+
from clovis import cloooooo
|
|
8
|
+
ai = cloooooo()
|
|
9
|
+
print(f" import OK — modèle: {ai._model}, url: {ai._url}")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_basic_call():
|
|
13
|
+
from clovis import cloooooo
|
|
14
|
+
ai = cloooooo()
|
|
15
|
+
resp = ai('Réponds uniquement par le mot "ok".')
|
|
16
|
+
assert isinstance(resp, str) and len(resp) > 0
|
|
17
|
+
print(f" appel OK — réponse: {resp!r}")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_negative_prompt():
|
|
21
|
+
from clovis import cloooooo
|
|
22
|
+
ai = cloooooo()
|
|
23
|
+
resp = ai("Présente-toi en 10 mots.", negative_prompt="ne mentionne pas ton nom")
|
|
24
|
+
assert isinstance(resp, str) and len(resp) > 0
|
|
25
|
+
print(f" negative_prompt OK — réponse: {resp!r}")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_thinking():
|
|
29
|
+
from clovis import cloooooo
|
|
30
|
+
ai = cloooooo()
|
|
31
|
+
resp = ai("Combien font 17 × 23 ?", thinking=True)
|
|
32
|
+
assert isinstance(resp, str) and len(resp) > 0
|
|
33
|
+
print(f" thinking OK — réponse: {resp!r}")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_context():
|
|
37
|
+
from clovis import cloooooo
|
|
38
|
+
ai = cloooooo()
|
|
39
|
+
resp = ai("Comment ça va ?", context="Tu es un pirate des Caraïbes. Réponds toujours en argot de marin.")
|
|
40
|
+
assert isinstance(resp, str) and len(resp) > 0
|
|
41
|
+
print(f" context OK — réponse: {resp!r}")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_stream():
|
|
45
|
+
from clovis import cloooooo
|
|
46
|
+
ai = cloooooo()
|
|
47
|
+
tokens = list(ai.stream("Compte jusqu'à 5, un nombre par ligne."))
|
|
48
|
+
assert len(tokens) > 0
|
|
49
|
+
full = "".join(tokens)
|
|
50
|
+
assert len(full) > 0
|
|
51
|
+
print(f" stream OK — {len(tokens)} tokens, texte: {full!r}")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_conversation():
|
|
55
|
+
from clovis import cloooooo
|
|
56
|
+
ai = cloooooo()
|
|
57
|
+
conv = ai.conversation(context="Réponds toujours en une seule phrase courte.")
|
|
58
|
+
r1 = conv("Mon prénom est Clovis.")
|
|
59
|
+
r2 = conv("Quel est mon prénom ?")
|
|
60
|
+
assert "Clovis" in r2 or "clovis" in r2.lower(), f"Prénom pas mémorisé: {r2!r}"
|
|
61
|
+
print(f" conversation OK — mémoire: {r2!r}")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_conversation_stream():
|
|
65
|
+
from clovis import cloooooo
|
|
66
|
+
ai = cloooooo()
|
|
67
|
+
conv = ai.conversation()
|
|
68
|
+
tokens = list(conv.stream("Dis bonjour en 3 langues."))
|
|
69
|
+
full = "".join(tokens)
|
|
70
|
+
assert len(full) > 0
|
|
71
|
+
print(f" conversation stream OK — {len(tokens)} tokens")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_conversation_reset():
|
|
75
|
+
from clovis import cloooooo
|
|
76
|
+
ai = cloooooo()
|
|
77
|
+
conv = ai.conversation()
|
|
78
|
+
conv("Mon prénom est Clovis.")
|
|
79
|
+
conv.reset()
|
|
80
|
+
assert len(conv._history) == 0
|
|
81
|
+
print(" conversation reset OK")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
tests = [
|
|
86
|
+
test_import,
|
|
87
|
+
test_basic_call,
|
|
88
|
+
test_negative_prompt,
|
|
89
|
+
test_thinking,
|
|
90
|
+
test_context,
|
|
91
|
+
test_stream,
|
|
92
|
+
test_conversation,
|
|
93
|
+
test_conversation_stream,
|
|
94
|
+
test_conversation_reset,
|
|
95
|
+
]
|
|
96
|
+
passed = 0
|
|
97
|
+
for t in tests:
|
|
98
|
+
print(f"\n{t.__name__}")
|
|
99
|
+
try:
|
|
100
|
+
t()
|
|
101
|
+
passed += 1
|
|
102
|
+
except Exception as e:
|
|
103
|
+
print(f" FAILED: {e}")
|
|
104
|
+
import traceback; traceback.print_exc()
|
|
105
|
+
|
|
106
|
+
print(f"\n{'='*40}")
|
|
107
|
+
print(f"Résultat: {passed}/{len(tests)} tests passés")
|
|
108
|
+
sys.exit(0 if passed == len(tests) else 1)
|
clovis-0.2.0/PKG-INFO
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: clovis
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: cloooooo — personal LLM client, prompt/context/thinking interface over local Ollama
|
|
5
|
-
Author: Clovis Sfeir
|
|
6
|
-
License: MIT
|
|
7
|
-
Keywords: ai,llm,local-ai,ollama,openai
|
|
8
|
-
Classifier: Development Status :: 3 - Alpha
|
|
9
|
-
Classifier: Intended Audience :: Developers
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
-
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
-
Requires-Python: >=3.10
|
|
17
|
-
Requires-Dist: fastapi>=0.111
|
|
18
|
-
Requires-Dist: httpx>=0.27
|
|
19
|
-
Requires-Dist: pydantic>=2.0
|
|
20
|
-
Requires-Dist: rich>=13.0
|
|
21
|
-
Requires-Dist: typer>=0.12
|
|
22
|
-
Requires-Dist: uvicorn[standard]>=0.30
|
|
23
|
-
Description-Content-Type: text/markdown
|
|
24
|
-
|
|
25
|
-
# clovis
|
|
26
|
-
|
|
27
|
-
OpenAI-compatible Python client over a local [Ollama](https://ollama.com) instance.
|
|
28
|
-
|
|
29
|
-
## Install
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
pip install clovis
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Usage
|
|
36
|
-
|
|
37
|
-
```python
|
|
38
|
-
from clovis import cloooooo
|
|
39
|
-
|
|
40
|
-
client = cloooooo() # connects to localhost:11434 by default
|
|
41
|
-
|
|
42
|
-
# Chat
|
|
43
|
-
resp = client.chat.completions.create(
|
|
44
|
-
model="qwen3-72b",
|
|
45
|
-
messages=[{"role": "user", "content": "Bonjour !"}]
|
|
46
|
-
)
|
|
47
|
-
print(resp.choices[0].message.content)
|
|
48
|
-
|
|
49
|
-
# Streaming
|
|
50
|
-
for chunk in client.chat.completions.create(
|
|
51
|
-
messages=[{"role": "user", "content": "Écris un poème"}],
|
|
52
|
-
stream=True,
|
|
53
|
-
):
|
|
54
|
-
print(chunk.choices[0].delta.get("content", ""), end="", flush=True)
|
|
55
|
-
|
|
56
|
-
# Conversation with auto history
|
|
57
|
-
with client.conversation(system="Tu es un expert en finance.") as conv:
|
|
58
|
-
print(conv.chat("Explique le CAPM"))
|
|
59
|
-
print(conv.chat("Et ses limites ?")) # remembers context
|
|
60
|
-
|
|
61
|
-
# Start API server
|
|
62
|
-
cloooooo.serve(port=8000, api_key="sk-...")
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## CLI
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
clovis "Explique les trous noirs" # direct question
|
|
69
|
-
clovis repl # interactive conversation
|
|
70
|
-
clovis serve --port 8000 # start API server
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Config
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
export CLOVIS_MODEL="qwen3-72b"
|
|
77
|
-
export CLOVIS_OLLAMA_URL="http://localhost:11434"
|
|
78
|
-
export CLOVIS_API_KEY="sk-..."
|
|
79
|
-
```
|
clovis-0.2.0/README.md
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# clovis
|
|
2
|
-
|
|
3
|
-
OpenAI-compatible Python client over a local [Ollama](https://ollama.com) instance.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pip install clovis
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```python
|
|
14
|
-
from clovis import cloooooo
|
|
15
|
-
|
|
16
|
-
client = cloooooo() # connects to localhost:11434 by default
|
|
17
|
-
|
|
18
|
-
# Chat
|
|
19
|
-
resp = client.chat.completions.create(
|
|
20
|
-
model="qwen3-72b",
|
|
21
|
-
messages=[{"role": "user", "content": "Bonjour !"}]
|
|
22
|
-
)
|
|
23
|
-
print(resp.choices[0].message.content)
|
|
24
|
-
|
|
25
|
-
# Streaming
|
|
26
|
-
for chunk in client.chat.completions.create(
|
|
27
|
-
messages=[{"role": "user", "content": "Écris un poème"}],
|
|
28
|
-
stream=True,
|
|
29
|
-
):
|
|
30
|
-
print(chunk.choices[0].delta.get("content", ""), end="", flush=True)
|
|
31
|
-
|
|
32
|
-
# Conversation with auto history
|
|
33
|
-
with client.conversation(system="Tu es un expert en finance.") as conv:
|
|
34
|
-
print(conv.chat("Explique le CAPM"))
|
|
35
|
-
print(conv.chat("Et ses limites ?")) # remembers context
|
|
36
|
-
|
|
37
|
-
# Start API server
|
|
38
|
-
cloooooo.serve(port=8000, api_key="sk-...")
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## CLI
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
clovis "Explique les trous noirs" # direct question
|
|
45
|
-
clovis repl # interactive conversation
|
|
46
|
-
clovis serve --port 8000 # start API server
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Config
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
export CLOVIS_MODEL="qwen3-72b"
|
|
53
|
-
export CLOVIS_OLLAMA_URL="http://localhost:11434"
|
|
54
|
-
export CLOVIS_API_KEY="sk-..."
|
|
55
|
-
```
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
from typing import Iterator, Optional
|
|
6
|
-
|
|
7
|
-
import httpx
|
|
8
|
-
|
|
9
|
-
_OLLAMA_URL = "http://localhost:11434"
|
|
10
|
-
_MODEL = "qwen3-72b-q5km"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def _build_messages(
|
|
14
|
-
prompt: str,
|
|
15
|
-
context: Optional[str],
|
|
16
|
-
negative_prompt: Optional[str],
|
|
17
|
-
thinking: bool,
|
|
18
|
-
history: list[dict],
|
|
19
|
-
) -> list[dict]:
|
|
20
|
-
system_parts = []
|
|
21
|
-
if context:
|
|
22
|
-
system_parts.append(context)
|
|
23
|
-
if negative_prompt:
|
|
24
|
-
system_parts.append(f"Évite absolument dans ta réponse : {negative_prompt}")
|
|
25
|
-
if thinking:
|
|
26
|
-
system_parts.append("Réfléchis étape par étape avant de répondre.")
|
|
27
|
-
|
|
28
|
-
messages = []
|
|
29
|
-
if system_parts:
|
|
30
|
-
messages.append({"role": "system", "content": "\n".join(system_parts)})
|
|
31
|
-
messages.extend(history)
|
|
32
|
-
messages.append({"role": "user", "content": prompt})
|
|
33
|
-
return messages
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
class Conversation:
|
|
37
|
-
def __init__(self, ai: "cloooooo", context: Optional[str] = None) -> None:
|
|
38
|
-
self._ai = ai
|
|
39
|
-
self._context = context
|
|
40
|
-
self._history: list[dict] = []
|
|
41
|
-
|
|
42
|
-
def __call__(
|
|
43
|
-
self,
|
|
44
|
-
prompt: str,
|
|
45
|
-
*,
|
|
46
|
-
negative_prompt: Optional[str] = None,
|
|
47
|
-
thinking: bool = False,
|
|
48
|
-
) -> str:
|
|
49
|
-
messages = _build_messages(prompt, self._context, negative_prompt, thinking, self._history)
|
|
50
|
-
reply = self._ai._send(messages)
|
|
51
|
-
self._history += [{"role": "user", "content": prompt}, {"role": "assistant", "content": reply}]
|
|
52
|
-
return reply
|
|
53
|
-
|
|
54
|
-
def stream(
|
|
55
|
-
self,
|
|
56
|
-
prompt: str,
|
|
57
|
-
*,
|
|
58
|
-
negative_prompt: Optional[str] = None,
|
|
59
|
-
thinking: bool = False,
|
|
60
|
-
) -> Iterator[str]:
|
|
61
|
-
messages = _build_messages(prompt, self._context, negative_prompt, thinking, self._history)
|
|
62
|
-
full = ""
|
|
63
|
-
for token in self._ai._stream(messages):
|
|
64
|
-
full += token
|
|
65
|
-
yield token
|
|
66
|
-
self._history += [{"role": "user", "content": prompt}, {"role": "assistant", "content": full}]
|
|
67
|
-
|
|
68
|
-
def reset(self) -> None:
|
|
69
|
-
self._history.clear()
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
class cloooooo:
|
|
73
|
-
"""
|
|
74
|
-
Usage::
|
|
75
|
-
|
|
76
|
-
from clovis import cloooooo
|
|
77
|
-
|
|
78
|
-
ai = cloooooo()
|
|
79
|
-
print(ai("Explique les trous noirs"))
|
|
80
|
-
print(ai("Génère un poème", negative_prompt="pas de rimes", thinking=True))
|
|
81
|
-
|
|
82
|
-
for token in ai.stream("Raconte une histoire"):
|
|
83
|
-
print(token, end="", flush=True)
|
|
84
|
-
|
|
85
|
-
conv = ai.conversation(context="Tu es un expert en finance")
|
|
86
|
-
conv("Explique le CAPM")
|
|
87
|
-
conv("Et ses limites ?") # se souvient du contexte
|
|
88
|
-
"""
|
|
89
|
-
|
|
90
|
-
def __init__(
|
|
91
|
-
self,
|
|
92
|
-
ollama_url: str = _OLLAMA_URL,
|
|
93
|
-
model: str = _MODEL,
|
|
94
|
-
) -> None:
|
|
95
|
-
self._url = os.getenv("CLOVIS_OLLAMA_URL", ollama_url)
|
|
96
|
-
self._model = os.getenv("CLOVIS_MODEL", model)
|
|
97
|
-
self._http = httpx.Client()
|
|
98
|
-
|
|
99
|
-
def __call__(
|
|
100
|
-
self,
|
|
101
|
-
prompt: str,
|
|
102
|
-
*,
|
|
103
|
-
negative_prompt: Optional[str] = None,
|
|
104
|
-
thinking: bool = False,
|
|
105
|
-
context: Optional[str] = None,
|
|
106
|
-
) -> str:
|
|
107
|
-
messages = _build_messages(prompt, context, negative_prompt, thinking, [])
|
|
108
|
-
return self._send(messages)
|
|
109
|
-
|
|
110
|
-
def stream(
|
|
111
|
-
self,
|
|
112
|
-
prompt: str,
|
|
113
|
-
*,
|
|
114
|
-
negative_prompt: Optional[str] = None,
|
|
115
|
-
thinking: bool = False,
|
|
116
|
-
context: Optional[str] = None,
|
|
117
|
-
) -> Iterator[str]:
|
|
118
|
-
messages = _build_messages(prompt, context, negative_prompt, thinking, [])
|
|
119
|
-
return self._stream(messages)
|
|
120
|
-
|
|
121
|
-
def conversation(self, context: Optional[str] = None) -> Conversation:
|
|
122
|
-
return Conversation(self, context=context)
|
|
123
|
-
|
|
124
|
-
def _send(self, messages: list[dict]) -> str:
|
|
125
|
-
resp = self._http.post(
|
|
126
|
-
f"{self._url}/api/chat",
|
|
127
|
-
json={"model": self._model, "messages": messages, "stream": False},
|
|
128
|
-
timeout=600,
|
|
129
|
-
)
|
|
130
|
-
resp.raise_for_status()
|
|
131
|
-
return resp.json()["message"]["content"]
|
|
132
|
-
|
|
133
|
-
def _stream(self, messages: list[dict]) -> Iterator[str]:
|
|
134
|
-
with self._http.stream(
|
|
135
|
-
"POST",
|
|
136
|
-
f"{self._url}/api/chat",
|
|
137
|
-
json={"model": self._model, "messages": messages, "stream": True},
|
|
138
|
-
timeout=600,
|
|
139
|
-
) as resp:
|
|
140
|
-
resp.raise_for_status()
|
|
141
|
-
for line in resp.iter_lines():
|
|
142
|
-
if not line:
|
|
143
|
-
continue
|
|
144
|
-
data = json.loads(line)
|
|
145
|
-
token = data.get("message", {}).get("content", "")
|
|
146
|
-
if token:
|
|
147
|
-
yield token
|
|
148
|
-
if data.get("done"):
|
|
149
|
-
break
|
|
150
|
-
|
|
151
|
-
@classmethod
|
|
152
|
-
def serve(cls, port: int = 8000, host: str = "0.0.0.0", api_key: Optional[str] = None) -> None:
|
|
153
|
-
from ._server import start_server
|
|
154
|
-
start_server(host=host, port=port, api_key=api_key)
|
clovis-0.2.0/test_live.py
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"""Test live end-to-end — lance avec : python3 test_live.py"""
|
|
2
|
-
from clovis import cloooooo, ClovisConnectionError, ClovisModelNotFound
|
|
3
|
-
|
|
4
|
-
TEST_MODEL = "gemma3:4b" # petit modèle pour le test, qwen3-72b-q5km après
|
|
5
|
-
|
|
6
|
-
def test_basic_chat():
|
|
7
|
-
client = cloooooo(model=TEST_MODEL)
|
|
8
|
-
resp = client.chat.completions.create(
|
|
9
|
-
messages=[{"role": "user", "content": "Réponds juste 'ok' et rien d'autre."}]
|
|
10
|
-
)
|
|
11
|
-
assert resp.choices[0].message.content
|
|
12
|
-
assert resp.choices[0].message.role == "assistant"
|
|
13
|
-
assert resp.usage.total_tokens > 0
|
|
14
|
-
print(f" chat OK — réponse : {resp.choices[0].message.content!r}")
|
|
15
|
-
|
|
16
|
-
def test_streaming():
|
|
17
|
-
client = cloooooo(model=TEST_MODEL)
|
|
18
|
-
chunks = list(client.chat.completions.create(
|
|
19
|
-
messages=[{"role": "user", "content": "Dis juste 'bonjour'."}],
|
|
20
|
-
stream=True,
|
|
21
|
-
))
|
|
22
|
-
full = "".join(c.choices[0].delta.get("content", "") for c in chunks)
|
|
23
|
-
assert len(full) > 0
|
|
24
|
-
print(f" streaming OK — {len(chunks)} chunks, texte : {full!r}")
|
|
25
|
-
|
|
26
|
-
def test_conversation():
|
|
27
|
-
client = cloooooo(model=TEST_MODEL)
|
|
28
|
-
with client.conversation(system="Réponds toujours en une seule phrase.") as conv:
|
|
29
|
-
r1 = conv.chat("Mon prénom est Clovis.")
|
|
30
|
-
r2 = conv.chat("Quel est mon prénom ?")
|
|
31
|
-
assert "Clovis" in r2 or "clovis" in r2.lower()
|
|
32
|
-
assert len(conv.history) == 5 # system + 2x (user+assistant)
|
|
33
|
-
print(f" conversation OK — mémoire : {r2!r}")
|
|
34
|
-
|
|
35
|
-
def test_models_list():
|
|
36
|
-
client = cloooooo(model=TEST_MODEL)
|
|
37
|
-
models = client.models()
|
|
38
|
-
assert isinstance(models, list)
|
|
39
|
-
assert len(models) > 0
|
|
40
|
-
print(f" models() OK — {models}")
|
|
41
|
-
|
|
42
|
-
def test_model_not_found():
|
|
43
|
-
client = cloooooo(model="inexistant:99b")
|
|
44
|
-
try:
|
|
45
|
-
client.chat.completions.create(
|
|
46
|
-
messages=[{"role": "user", "content": "test"}]
|
|
47
|
-
)
|
|
48
|
-
assert False, "Aurait dû lever ClovisModelNotFound"
|
|
49
|
-
except ClovisModelNotFound as e:
|
|
50
|
-
print(f" ClovisModelNotFound OK — {e}")
|
|
51
|
-
|
|
52
|
-
def test_connection_error():
|
|
53
|
-
try:
|
|
54
|
-
cloooooo(ollama_url="http://localhost:9999")
|
|
55
|
-
assert False, "Aurait dû lever ClovisConnectionError"
|
|
56
|
-
except ClovisConnectionError as e:
|
|
57
|
-
print(f" ClovisConnectionError OK — {e}")
|
|
58
|
-
|
|
59
|
-
if __name__ == "__main__":
|
|
60
|
-
tests = [
|
|
61
|
-
test_basic_chat,
|
|
62
|
-
test_streaming,
|
|
63
|
-
test_conversation,
|
|
64
|
-
test_models_list,
|
|
65
|
-
test_model_not_found,
|
|
66
|
-
test_connection_error,
|
|
67
|
-
]
|
|
68
|
-
passed = 0
|
|
69
|
-
for t in tests:
|
|
70
|
-
print(f"\n{t.__name__}")
|
|
71
|
-
try:
|
|
72
|
-
t()
|
|
73
|
-
passed += 1
|
|
74
|
-
except Exception as e:
|
|
75
|
-
print(f" FAILED: {e}")
|
|
76
|
-
|
|
77
|
-
print(f"\n{'='*40}")
|
|
78
|
-
print(f"Résultat : {passed}/{len(tests)} tests passés")
|
|
File without changes
|
|
File without changes
|