Skip to content

Commit 08a6ff1

Browse files
committed
Update documentation
1 parent 14477e7 commit 08a6ff1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+747
-377
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ async def main():
151151
)
152152

153153
async def call(self, inputs, training=False):
154+
if not inputs:
155+
return None
154156
x = await self.answer(inputs, training=training)
155157
return x
156158

api_gen.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Modified from: keras/api_gen.py
2+
# Original authors: François Chollet et al. (Keras Team)
3+
# License Apache 2.0: (c) 2025 Yoan Sallami (Synalinks Team)
4+
15
"""Script to generate synalinks public API in `synalinks/api` directory.
26
37
Usage:

coverage-badge.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/Deployment/Building a REST API.md

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ First, let's see how a production-ready project is structured.
88

99
In this tutorial, we will focus only on the backend of your application.
1010

11-
For the purpose of this tutorial, we will skip authentification. There is different ways of handling it, but the most easy one is using JWT tokens combined with Google Oauth. But because is is higly dependent on your business usecase/frontend, we will not handle it here.
11+
For the purpose of this tutorial, we will skip authentification. But because is is higly dependent on your business usecase/frontend, we will not handle it here.
1212

1313
### Project Structure
1414

@@ -25,7 +25,7 @@ demo/
2525
│ └── ... (your frontend code)
2626
├── scripts/
2727
│ ├── export_program.py
28-
│ └── train.py
28+
│ └── train.py (refer to the code examples to learn how to train programs)
2929
├── docker-compose.yml
3030
├── .env.backend
3131
├── .end.frontend
@@ -91,14 +91,19 @@ app.add_middleware(
9191
allow_headers=["*"],
9292
)
9393

94-
# Load your program
95-
program = synalinks.Program.load("checkpoint.program.json")
94+
# The dictionary mapping the name of your custom modules to the class
95+
custom_modules = {}
9696

97+
# Load your program
98+
program = synalinks.Program.load(
99+
"checkpoint.program.json",
100+
custom_modules=custom_modules,
101+
)
97102

98103
@app.post("/v1/chat_completion")
99104
async def chat_completion(messages: synalinks.ChatMessages):
100105
result = await program(messages)
101-
return result.json() if result else None
106+
return result.json()
102107

103108

104109
if __name__ == "__main__":
@@ -113,11 +118,6 @@ if __name__ == "__main__":
113118

114119
For obvious reasons, you will need to have a separate logic to train your application. This script will specify the program architecture, training and evaluation procedure and will end up saving your program into a serializable JSON format.
115120

116-
```python title="train.py"
117-
import synalinks
118-
119-
```
120-
121121
To ease the migration, we'll also make a small script that export the trained program into our backend folder.
122122

123123
```python title="export_program.py"
@@ -187,16 +187,6 @@ services:
187187
image: ghcr.io/mlflow/mlflow:latest
188188
ports:
189189
- "5000:5000"
190-
frontend:
191-
build:
192-
context: ./frontend
193-
dockerfile: Dockerfile
194-
ports:
195-
- "3000:3000"
196-
depends_on:
197-
- backend
198-
env_file:
199-
- .env.frontend
200190
backend:
201191
build:
202192
context: ./backend
@@ -216,6 +206,6 @@ cd demo
216206
docker compose up
217207
```
218208

219-
### Testing your application
209+
### Testing your application backend
220210

221211
Open you browser to `http://127.0.0.1/docs` and test your API

docs/Deployment/index.md

Whitespace-only changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
::: synalinks.src.backend.pydantic.DataModel
2+
::: synalinks.src.backend.pydantic.core
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
::: synalinks.src.backend.common.json_data_model.JsonDataModel
2+
::: synalinks.src.backend.common.json_data_model
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
::: synalinks.src.backend.common.symbolic_data_model.SymbolicDataModel
2+
::: synalinks.src.backend.common.symbolic_data_model

docs/Synalinks API/Modules API/Core Modules/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
- [Generator module](Generator module.md)
55
- [Decision module](Decision module.md)
66
- [Action module](Action module.md)
7-
- [Router module](Router module.md)
7+
- [Branch module](Branch module.md)

docs/Synalinks API/Modules API/index.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,35 @@ A module instance is callable, much like a function:
66

77
``` py
88
import synalinks
9+
import asyncio
910

10-
class Query(synalinks.DataModel):
11-
query: str
11+
async def main():
12+
class Query(synalinks.DataModel):
13+
query: str = synalinks.Field(
14+
description="The user query",
15+
)
1216

13-
class ChainOfThought(synalinks.DataModel):
14-
thinking: str
15-
answer: str
17+
class AnswerWithThinking(synalinks.DataModel):
18+
thinking: str = synalinks.Field(
19+
description="Your step by step thinking",
20+
)
21+
answer: str = synalinks.Field(
22+
description="The correct answer",
23+
)
1624

17-
language_model = LanguageModel("ollama_chat/deepseek-r1")
25+
language_model = LanguageModel("ollama_chat/deepseek-r1")
1826

19-
generator = synalinks.Generator(
20-
data_model=ChainOfThought,
21-
language_model=language_model,
22-
)
27+
generator = synalinks.Generator(
28+
data_model=AnswerWithThinking,
29+
language_model=language_model,
30+
)
2331

24-
inputs = Query(query="What is the capital of France?")
25-
outputs = generator(inputs)
32+
inputs = Query(query="What is the capital of France?")
33+
outputs = await generator(inputs)
34+
35+
36+
if __name__ == "__main__":
37+
asyncio.run(main())
2638
```
2739

2840
## Modules API overview
@@ -44,8 +56,8 @@ outputs = generator(inputs)
4456
### Merging Modules
4557

4658
- [Concat Module](Merging Modules/Concat module.md)
47-
- [Logical And](Merging Modules/Logical And module.md)
48-
- [Logical Or](Merging Modules/Logical Or module.md)
59+
- [Logical And](Merging Modules/And module.md)
60+
- [Logical Or](Merging Modules/Or module.md)
4961

5062
---
5163

0 commit comments

Comments
 (0)