pydantic-rpc 0.2.2__tar.gz → 0.3.1__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.
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/PKG-INFO +96 -3
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/README.md +95 -2
- pydantic_rpc-0.3.1/examples/agent_aio_grpc.py +74 -0
- pydantic_rpc-0.3.1/examples/barservice.proto +17 -0
- pydantic_rpc-0.3.1/examples/fooservice.proto +21 -0
- pydantic_rpc-0.3.1/examples/olympicsagent.proto +144 -0
- pydantic_rpc-0.3.1/examples/olympicsagent_pb2.py +34 -0
- pydantic_rpc-0.3.1/examples/olympicsagent_pb2.pyi +37 -0
- pydantic_rpc-0.3.1/examples/olympicsagent_pb2_grpc.py +125 -0
- pydantic_rpc-0.3.1/examples/olympicslocationagent.proto +18 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/olympicslocationagent_pb2_grpc.py +45 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/pyproject.toml +1 -1
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/src/pydantic_rpc/core.py +93 -20
- pydantic_rpc-0.2.2/examples/agent_aio_grpc.py +0 -43
- pydantic_rpc-0.2.2/examples/barservice.proto +0 -69
- pydantic_rpc-0.2.2/examples/fooservice.proto +0 -73
- pydantic_rpc-0.2.2/examples/olympicslocationagent.proto +0 -76
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/.gitignore +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/.python-version +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/LICENSE +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/README.md +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/agent_connecpy.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/asyncio_greeting.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/barservice_pb2.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/barservice_pb2.pyi +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/barservice_pb2_grpc.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/foobar.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/foobar_client.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/fooservice_pb2.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/fooservice_pb2.pyi +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/fooservice_pb2_grpc.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/google/protobuf/duration.proto +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/google/protobuf/timestamp.proto +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeter.proto +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeter_client.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeter_connecpy.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeter_connecpy_client.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeter_pb2.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeter_pb2.pyi +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeter_pb2_grpc.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeter_sonora_client.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeting.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeting_asgi.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeting_connecpy.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeting_using_exsiting_pb2_modules.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/greeting_wsgi.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/olympicslocationagent_connecpy.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/olympicslocationagent_pb2.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/examples/olympicslocationagent_pb2.pyi +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/requirements-dev.lock +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/requirements.lock +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/src/pydantic_rpc/__init__.py +0 -0
- {pydantic_rpc-0.2.2 → pydantic_rpc-0.3.1}/src/pydantic_rpc/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: pydantic-rpc
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: A Python library for building gRPC/ConnectRPC services with Pydantic models.
|
|
5
5
|
Author: Yasushi Itoh
|
|
6
6
|
Requires-Python: >=3.11
|
|
@@ -14,7 +14,7 @@ Description-Content-Type: text/markdown
|
|
|
14
14
|
|
|
15
15
|
# 🚀 PydanticRPC
|
|
16
16
|
|
|
17
|
-
**PydanticRPC** is a Python library that enables you to rapidly expose [Pydantic](https://docs.pydantic.dev/) models via [gRPC](https://grpc.io/)/[
|
|
17
|
+
**PydanticRPC** is a Python library that enables you to rapidly expose [Pydantic](https://docs.pydantic.dev/) models via [gRPC](https://grpc.io/)/[Connect RPC](https://connectrpc.com/docs/protocol/) services without writing any protobuf files. Instead, it automatically generates protobuf files on the fly from the method signatures of your Python objects and the type signatures of your Pydantic models.
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
Below is an example of a simple gRPC service that exposes a [PydanticAI](https://ai.pydantic.dev/) agent:
|
|
@@ -54,7 +54,7 @@ if __name__ == "__main__":
|
|
|
54
54
|
loop.run_until_complete(s.run(OlympicsLocationAgent()))
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
And here is an example of a simple
|
|
57
|
+
And here is an example of a simple Connect RPC service that exposes the same agent as an ASGI application:
|
|
58
58
|
|
|
59
59
|
```python
|
|
60
60
|
import asyncio
|
|
@@ -254,6 +254,88 @@ When this variable is set to "true", PydanticRPC will load existing pre-generate
|
|
|
254
254
|
|
|
255
255
|
## 💎 Advanced Features
|
|
256
256
|
|
|
257
|
+
### 🌊 Response Streaming
|
|
258
|
+
PydanticRPC supports streaming for responses in asynchronous gRPC and gRPC-Web services only.
|
|
259
|
+
|
|
260
|
+
Please see the sample code below:
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
import asyncio
|
|
264
|
+
from typing import AsyncIterator
|
|
265
|
+
|
|
266
|
+
from pydantic import field_validator
|
|
267
|
+
from pydantic_ai import Agent
|
|
268
|
+
from pydantic_rpc import AsyncIOServer, Message
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
# `Message` is just a pydantic BaseModel alias
|
|
272
|
+
class CityLocation(Message):
|
|
273
|
+
city: str
|
|
274
|
+
country: str
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
class OlympicsQuery(Message):
|
|
278
|
+
year: int
|
|
279
|
+
|
|
280
|
+
def prompt(self):
|
|
281
|
+
return f"Where were the Olympics held in {self.year}?"
|
|
282
|
+
|
|
283
|
+
@field_validator("year")
|
|
284
|
+
def validate_year(cls, value):
|
|
285
|
+
if value < 1896:
|
|
286
|
+
raise ValueError("The first modern Olympics was held in 1896.")
|
|
287
|
+
|
|
288
|
+
return value
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
class OlympicsDurationQuery(Message):
|
|
292
|
+
start: int
|
|
293
|
+
end: int
|
|
294
|
+
|
|
295
|
+
def prompt(self):
|
|
296
|
+
return f"From {self.start} to {self.end}, how many Olympics were held? Please provide the list of countries and cities."
|
|
297
|
+
|
|
298
|
+
@field_validator("start")
|
|
299
|
+
def validate_start(cls, value):
|
|
300
|
+
if value < 1896:
|
|
301
|
+
raise ValueError("The first modern Olympics was held in 1896.")
|
|
302
|
+
|
|
303
|
+
return value
|
|
304
|
+
|
|
305
|
+
@field_validator("end")
|
|
306
|
+
def validate_end(cls, value):
|
|
307
|
+
if value < 1896:
|
|
308
|
+
raise ValueError("The first modern Olympics was held in 1896.")
|
|
309
|
+
|
|
310
|
+
return value
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
class StreamingResult(Message):
|
|
314
|
+
answer: str
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
class OlympicsAgent:
|
|
318
|
+
def __init__(self):
|
|
319
|
+
self._agent = Agent("ollama:llama3.2")
|
|
320
|
+
|
|
321
|
+
async def ask(self, req: OlympicsQuery) -> CityLocation:
|
|
322
|
+
result = await self._agent.run(req.prompt(), result_type=CityLocation)
|
|
323
|
+
return result.data
|
|
324
|
+
|
|
325
|
+
async def ask_stream(
|
|
326
|
+
self, req: OlympicsDurationQuery
|
|
327
|
+
) -> AsyncIterator[StreamingResult]:
|
|
328
|
+
async with self._agent.run_stream(req.prompt(), result_type=str) as result:
|
|
329
|
+
async for data in result.stream_text(delta=True):
|
|
330
|
+
yield StreamingResult(answer=data)
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
if __name__ == "__main__":
|
|
334
|
+
s = AsyncIOServer()
|
|
335
|
+
loop = asyncio.get_event_loop()
|
|
336
|
+
loop.run_until_complete(s.run(OlympicsAgent()))
|
|
337
|
+
```
|
|
338
|
+
|
|
257
339
|
### 🔗 Multiple Services with Custom Interceptors
|
|
258
340
|
|
|
259
341
|
PydanticRPC supports defining and running multiple services in a single server:
|
|
@@ -349,6 +431,17 @@ python core.py a_module.py aClass
|
|
|
349
431
|
|
|
350
432
|
Using this generated proto file and tools as `protoc`, `buf` and `BSR`, you could generate code for any desired language other than Python.
|
|
351
433
|
|
|
434
|
+
## 📖 Data Type Mapping
|
|
435
|
+
|
|
436
|
+
| Python Type | Protobuf Type |
|
|
437
|
+
|--------------------|-----------------|
|
|
438
|
+
| str | string |
|
|
439
|
+
| bool | bool |
|
|
440
|
+
| int | int32, int64 |
|
|
441
|
+
| float | float, double |
|
|
442
|
+
| list[T], tuple[T] | repeated T |
|
|
443
|
+
| dict[K, V] | map<K, V> |
|
|
444
|
+
|
|
352
445
|
|
|
353
446
|
## TODO
|
|
354
447
|
- [ ] Streaming Support
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 🚀 PydanticRPC
|
|
2
2
|
|
|
3
|
-
**PydanticRPC** is a Python library that enables you to rapidly expose [Pydantic](https://docs.pydantic.dev/) models via [gRPC](https://grpc.io/)/[
|
|
3
|
+
**PydanticRPC** is a Python library that enables you to rapidly expose [Pydantic](https://docs.pydantic.dev/) models via [gRPC](https://grpc.io/)/[Connect RPC](https://connectrpc.com/docs/protocol/) services without writing any protobuf files. Instead, it automatically generates protobuf files on the fly from the method signatures of your Python objects and the type signatures of your Pydantic models.
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
Below is an example of a simple gRPC service that exposes a [PydanticAI](https://ai.pydantic.dev/) agent:
|
|
@@ -40,7 +40,7 @@ if __name__ == "__main__":
|
|
|
40
40
|
loop.run_until_complete(s.run(OlympicsLocationAgent()))
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
And here is an example of a simple
|
|
43
|
+
And here is an example of a simple Connect RPC service that exposes the same agent as an ASGI application:
|
|
44
44
|
|
|
45
45
|
```python
|
|
46
46
|
import asyncio
|
|
@@ -240,6 +240,88 @@ When this variable is set to "true", PydanticRPC will load existing pre-generate
|
|
|
240
240
|
|
|
241
241
|
## 💎 Advanced Features
|
|
242
242
|
|
|
243
|
+
### 🌊 Response Streaming
|
|
244
|
+
PydanticRPC supports streaming for responses in asynchronous gRPC and gRPC-Web services only.
|
|
245
|
+
|
|
246
|
+
Please see the sample code below:
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
import asyncio
|
|
250
|
+
from typing import AsyncIterator
|
|
251
|
+
|
|
252
|
+
from pydantic import field_validator
|
|
253
|
+
from pydantic_ai import Agent
|
|
254
|
+
from pydantic_rpc import AsyncIOServer, Message
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
# `Message` is just a pydantic BaseModel alias
|
|
258
|
+
class CityLocation(Message):
|
|
259
|
+
city: str
|
|
260
|
+
country: str
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
class OlympicsQuery(Message):
|
|
264
|
+
year: int
|
|
265
|
+
|
|
266
|
+
def prompt(self):
|
|
267
|
+
return f"Where were the Olympics held in {self.year}?"
|
|
268
|
+
|
|
269
|
+
@field_validator("year")
|
|
270
|
+
def validate_year(cls, value):
|
|
271
|
+
if value < 1896:
|
|
272
|
+
raise ValueError("The first modern Olympics was held in 1896.")
|
|
273
|
+
|
|
274
|
+
return value
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
class OlympicsDurationQuery(Message):
|
|
278
|
+
start: int
|
|
279
|
+
end: int
|
|
280
|
+
|
|
281
|
+
def prompt(self):
|
|
282
|
+
return f"From {self.start} to {self.end}, how many Olympics were held? Please provide the list of countries and cities."
|
|
283
|
+
|
|
284
|
+
@field_validator("start")
|
|
285
|
+
def validate_start(cls, value):
|
|
286
|
+
if value < 1896:
|
|
287
|
+
raise ValueError("The first modern Olympics was held in 1896.")
|
|
288
|
+
|
|
289
|
+
return value
|
|
290
|
+
|
|
291
|
+
@field_validator("end")
|
|
292
|
+
def validate_end(cls, value):
|
|
293
|
+
if value < 1896:
|
|
294
|
+
raise ValueError("The first modern Olympics was held in 1896.")
|
|
295
|
+
|
|
296
|
+
return value
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
class StreamingResult(Message):
|
|
300
|
+
answer: str
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
class OlympicsAgent:
|
|
304
|
+
def __init__(self):
|
|
305
|
+
self._agent = Agent("ollama:llama3.2")
|
|
306
|
+
|
|
307
|
+
async def ask(self, req: OlympicsQuery) -> CityLocation:
|
|
308
|
+
result = await self._agent.run(req.prompt(), result_type=CityLocation)
|
|
309
|
+
return result.data
|
|
310
|
+
|
|
311
|
+
async def ask_stream(
|
|
312
|
+
self, req: OlympicsDurationQuery
|
|
313
|
+
) -> AsyncIterator[StreamingResult]:
|
|
314
|
+
async with self._agent.run_stream(req.prompt(), result_type=str) as result:
|
|
315
|
+
async for data in result.stream_text(delta=True):
|
|
316
|
+
yield StreamingResult(answer=data)
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
if __name__ == "__main__":
|
|
320
|
+
s = AsyncIOServer()
|
|
321
|
+
loop = asyncio.get_event_loop()
|
|
322
|
+
loop.run_until_complete(s.run(OlympicsAgent()))
|
|
323
|
+
```
|
|
324
|
+
|
|
243
325
|
### 🔗 Multiple Services with Custom Interceptors
|
|
244
326
|
|
|
245
327
|
PydanticRPC supports defining and running multiple services in a single server:
|
|
@@ -335,6 +417,17 @@ python core.py a_module.py aClass
|
|
|
335
417
|
|
|
336
418
|
Using this generated proto file and tools as `protoc`, `buf` and `BSR`, you could generate code for any desired language other than Python.
|
|
337
419
|
|
|
420
|
+
## 📖 Data Type Mapping
|
|
421
|
+
|
|
422
|
+
| Python Type | Protobuf Type |
|
|
423
|
+
|--------------------|-----------------|
|
|
424
|
+
| str | string |
|
|
425
|
+
| bool | bool |
|
|
426
|
+
| int | int32, int64 |
|
|
427
|
+
| float | float, double |
|
|
428
|
+
| list[T], tuple[T] | repeated T |
|
|
429
|
+
| dict[K, V] | map<K, V> |
|
|
430
|
+
|
|
338
431
|
|
|
339
432
|
## TODO
|
|
340
433
|
- [ ] Streaming Support
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from typing import AsyncIterator
|
|
3
|
+
|
|
4
|
+
from pydantic import field_validator
|
|
5
|
+
from pydantic_ai import Agent
|
|
6
|
+
from pydantic_rpc import AsyncIOServer, Message
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# `Message` is just a pydantic BaseModel alias
|
|
10
|
+
class CityLocation(Message):
|
|
11
|
+
city: str
|
|
12
|
+
country: str
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class OlympicsQuery(Message):
|
|
16
|
+
year: int
|
|
17
|
+
|
|
18
|
+
def prompt(self):
|
|
19
|
+
return f"Where were the Olympics held in {self.year}?"
|
|
20
|
+
|
|
21
|
+
@field_validator("year")
|
|
22
|
+
def validate_year(cls, value):
|
|
23
|
+
if value < 1896:
|
|
24
|
+
raise ValueError("The first modern Olympics was held in 1896.")
|
|
25
|
+
|
|
26
|
+
return value
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class OlympicsDurationQuery(Message):
|
|
30
|
+
start: int
|
|
31
|
+
end: int
|
|
32
|
+
|
|
33
|
+
def prompt(self):
|
|
34
|
+
return f"From {self.start} to {self.end}, how many Olympics were held? Please provide the list of countries and cities."
|
|
35
|
+
|
|
36
|
+
@field_validator("start")
|
|
37
|
+
def validate_start(cls, value):
|
|
38
|
+
if value < 1896:
|
|
39
|
+
raise ValueError("The first modern Olympics was held in 1896.")
|
|
40
|
+
|
|
41
|
+
return value
|
|
42
|
+
|
|
43
|
+
@field_validator("end")
|
|
44
|
+
def validate_end(cls, value):
|
|
45
|
+
if value < 1896:
|
|
46
|
+
raise ValueError("The first modern Olympics was held in 1896.")
|
|
47
|
+
|
|
48
|
+
return value
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class StreamingResult(Message):
|
|
52
|
+
answer: str
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class OlympicsAgent:
|
|
56
|
+
def __init__(self):
|
|
57
|
+
self._agent = Agent("ollama:llama3.2")
|
|
58
|
+
|
|
59
|
+
async def ask(self, req: OlympicsQuery) -> CityLocation:
|
|
60
|
+
result = await self._agent.run(req.prompt(), result_type=CityLocation)
|
|
61
|
+
return result.data
|
|
62
|
+
|
|
63
|
+
async def ask_stream(
|
|
64
|
+
self, req: OlympicsDurationQuery
|
|
65
|
+
) -> AsyncIterator[StreamingResult]:
|
|
66
|
+
async with self._agent.run_stream(req.prompt(), result_type=str) as result:
|
|
67
|
+
async for data in result.stream_text(delta=True):
|
|
68
|
+
yield StreamingResult(answer=data)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
s = AsyncIOServer()
|
|
73
|
+
loop = asyncio.get_event_loop()
|
|
74
|
+
loop.run_until_complete(s.run(OlympicsAgent()))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package foo.v1;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
service FooService {
|
|
7
|
+
rpc Foo (FooRequest) returns (FooResponse);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
message FooResponse {
|
|
11
|
+
string name = 1;
|
|
12
|
+
int32 age = 2;
|
|
13
|
+
map<string, string> d = 3;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
message FooRequest {
|
|
17
|
+
string name = 1;
|
|
18
|
+
int32 age = 2;
|
|
19
|
+
map<string, string> d = 3;
|
|
20
|
+
}
|
|
21
|
+
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package olympicsagent.v1;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
service OlympicsAgent {
|
|
7
|
+
rpc Ask (OlympicsQuery) returns (CityLocation);
|
|
8
|
+
rpc AskStream (OlympicsDurationQuery) returns (stream StreamingResult);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Usage docs: https://docs.pydantic.dev/2.10/concepts/models/
|
|
12
|
+
//
|
|
13
|
+
// A base class for creating Pydantic models.
|
|
14
|
+
//
|
|
15
|
+
// Attributes:
|
|
16
|
+
// __class_vars__: The names of the class variables defined on the model.
|
|
17
|
+
// __private_attributes__: Metadata about the private attributes of the model.
|
|
18
|
+
// __signature__: The synthesized `__init__` [`Signature`][inspect.Signature] of the model.
|
|
19
|
+
//
|
|
20
|
+
// __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
|
|
21
|
+
// __pydantic_core_schema__: The core schema of the model.
|
|
22
|
+
// __pydantic_custom_init__: Whether the model has a custom `__init__` function.
|
|
23
|
+
// __pydantic_decorators__: Metadata containing the decorators defined on the model.
|
|
24
|
+
// This replaces `Model.__validators__` and `Model.__root_validators__` from Pydantic V1.
|
|
25
|
+
// __pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to
|
|
26
|
+
// __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
|
|
27
|
+
// __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
|
|
28
|
+
// __pydantic_post_init__: The name of the post-init method for the model, if defined.
|
|
29
|
+
// __pydantic_root_model__: Whether the model is a [`RootModel`][pydantic.root_model.RootModel].
|
|
30
|
+
// __pydantic_serializer__: The `pydantic-core` `SchemaSerializer` used to dump instances of the model.
|
|
31
|
+
// __pydantic_validator__: The `pydantic-core` `SchemaValidator` used to validate instances of the model.
|
|
32
|
+
//
|
|
33
|
+
// __pydantic_fields__: A dictionary of field names and their corresponding [`FieldInfo`][pydantic.fields.FieldInfo] objects.
|
|
34
|
+
// __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [`ComputedFieldInfo`][pydantic.fields.ComputedFieldInfo] objects.
|
|
35
|
+
//
|
|
36
|
+
// __pydantic_extra__: A dictionary containing extra values, if [`extra`][pydantic.config.ConfigDict.extra]
|
|
37
|
+
// is set to `'allow'`.
|
|
38
|
+
// __pydantic_fields_set__: The names of fields explicitly set during instantiation.
|
|
39
|
+
// __pydantic_private__: Values of private attributes set on the model instance.
|
|
40
|
+
message CityLocation {
|
|
41
|
+
string city = 1;
|
|
42
|
+
string country = 2;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Usage docs: https://docs.pydantic.dev/2.10/concepts/models/
|
|
46
|
+
//
|
|
47
|
+
// A base class for creating Pydantic models.
|
|
48
|
+
//
|
|
49
|
+
// Attributes:
|
|
50
|
+
// __class_vars__: The names of the class variables defined on the model.
|
|
51
|
+
// __private_attributes__: Metadata about the private attributes of the model.
|
|
52
|
+
// __signature__: The synthesized `__init__` [`Signature`][inspect.Signature] of the model.
|
|
53
|
+
//
|
|
54
|
+
// __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
|
|
55
|
+
// __pydantic_core_schema__: The core schema of the model.
|
|
56
|
+
// __pydantic_custom_init__: Whether the model has a custom `__init__` function.
|
|
57
|
+
// __pydantic_decorators__: Metadata containing the decorators defined on the model.
|
|
58
|
+
// This replaces `Model.__validators__` and `Model.__root_validators__` from Pydantic V1.
|
|
59
|
+
// __pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to
|
|
60
|
+
// __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
|
|
61
|
+
// __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
|
|
62
|
+
// __pydantic_post_init__: The name of the post-init method for the model, if defined.
|
|
63
|
+
// __pydantic_root_model__: Whether the model is a [`RootModel`][pydantic.root_model.RootModel].
|
|
64
|
+
// __pydantic_serializer__: The `pydantic-core` `SchemaSerializer` used to dump instances of the model.
|
|
65
|
+
// __pydantic_validator__: The `pydantic-core` `SchemaValidator` used to validate instances of the model.
|
|
66
|
+
//
|
|
67
|
+
// __pydantic_fields__: A dictionary of field names and their corresponding [`FieldInfo`][pydantic.fields.FieldInfo] objects.
|
|
68
|
+
// __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [`ComputedFieldInfo`][pydantic.fields.ComputedFieldInfo] objects.
|
|
69
|
+
//
|
|
70
|
+
// __pydantic_extra__: A dictionary containing extra values, if [`extra`][pydantic.config.ConfigDict.extra]
|
|
71
|
+
// is set to `'allow'`.
|
|
72
|
+
// __pydantic_fields_set__: The names of fields explicitly set during instantiation.
|
|
73
|
+
// __pydantic_private__: Values of private attributes set on the model instance.
|
|
74
|
+
message OlympicsQuery {
|
|
75
|
+
int32 year = 1;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Usage docs: https://docs.pydantic.dev/2.10/concepts/models/
|
|
79
|
+
//
|
|
80
|
+
// A base class for creating Pydantic models.
|
|
81
|
+
//
|
|
82
|
+
// Attributes:
|
|
83
|
+
// __class_vars__: The names of the class variables defined on the model.
|
|
84
|
+
// __private_attributes__: Metadata about the private attributes of the model.
|
|
85
|
+
// __signature__: The synthesized `__init__` [`Signature`][inspect.Signature] of the model.
|
|
86
|
+
//
|
|
87
|
+
// __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
|
|
88
|
+
// __pydantic_core_schema__: The core schema of the model.
|
|
89
|
+
// __pydantic_custom_init__: Whether the model has a custom `__init__` function.
|
|
90
|
+
// __pydantic_decorators__: Metadata containing the decorators defined on the model.
|
|
91
|
+
// This replaces `Model.__validators__` and `Model.__root_validators__` from Pydantic V1.
|
|
92
|
+
// __pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to
|
|
93
|
+
// __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
|
|
94
|
+
// __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
|
|
95
|
+
// __pydantic_post_init__: The name of the post-init method for the model, if defined.
|
|
96
|
+
// __pydantic_root_model__: Whether the model is a [`RootModel`][pydantic.root_model.RootModel].
|
|
97
|
+
// __pydantic_serializer__: The `pydantic-core` `SchemaSerializer` used to dump instances of the model.
|
|
98
|
+
// __pydantic_validator__: The `pydantic-core` `SchemaValidator` used to validate instances of the model.
|
|
99
|
+
//
|
|
100
|
+
// __pydantic_fields__: A dictionary of field names and their corresponding [`FieldInfo`][pydantic.fields.FieldInfo] objects.
|
|
101
|
+
// __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [`ComputedFieldInfo`][pydantic.fields.ComputedFieldInfo] objects.
|
|
102
|
+
//
|
|
103
|
+
// __pydantic_extra__: A dictionary containing extra values, if [`extra`][pydantic.config.ConfigDict.extra]
|
|
104
|
+
// is set to `'allow'`.
|
|
105
|
+
// __pydantic_fields_set__: The names of fields explicitly set during instantiation.
|
|
106
|
+
// __pydantic_private__: Values of private attributes set on the model instance.
|
|
107
|
+
message StreamingResult {
|
|
108
|
+
string answer = 1;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Usage docs: https://docs.pydantic.dev/2.10/concepts/models/
|
|
112
|
+
//
|
|
113
|
+
// A base class for creating Pydantic models.
|
|
114
|
+
//
|
|
115
|
+
// Attributes:
|
|
116
|
+
// __class_vars__: The names of the class variables defined on the model.
|
|
117
|
+
// __private_attributes__: Metadata about the private attributes of the model.
|
|
118
|
+
// __signature__: The synthesized `__init__` [`Signature`][inspect.Signature] of the model.
|
|
119
|
+
//
|
|
120
|
+
// __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
|
|
121
|
+
// __pydantic_core_schema__: The core schema of the model.
|
|
122
|
+
// __pydantic_custom_init__: Whether the model has a custom `__init__` function.
|
|
123
|
+
// __pydantic_decorators__: Metadata containing the decorators defined on the model.
|
|
124
|
+
// This replaces `Model.__validators__` and `Model.__root_validators__` from Pydantic V1.
|
|
125
|
+
// __pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to
|
|
126
|
+
// __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
|
|
127
|
+
// __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
|
|
128
|
+
// __pydantic_post_init__: The name of the post-init method for the model, if defined.
|
|
129
|
+
// __pydantic_root_model__: Whether the model is a [`RootModel`][pydantic.root_model.RootModel].
|
|
130
|
+
// __pydantic_serializer__: The `pydantic-core` `SchemaSerializer` used to dump instances of the model.
|
|
131
|
+
// __pydantic_validator__: The `pydantic-core` `SchemaValidator` used to validate instances of the model.
|
|
132
|
+
//
|
|
133
|
+
// __pydantic_fields__: A dictionary of field names and their corresponding [`FieldInfo`][pydantic.fields.FieldInfo] objects.
|
|
134
|
+
// __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [`ComputedFieldInfo`][pydantic.fields.ComputedFieldInfo] objects.
|
|
135
|
+
//
|
|
136
|
+
// __pydantic_extra__: A dictionary containing extra values, if [`extra`][pydantic.config.ConfigDict.extra]
|
|
137
|
+
// is set to `'allow'`.
|
|
138
|
+
// __pydantic_fields_set__: The names of fields explicitly set during instantiation.
|
|
139
|
+
// __pydantic_private__: Values of private attributes set on the model instance.
|
|
140
|
+
message OlympicsDurationQuery {
|
|
141
|
+
int32 start = 1;
|
|
142
|
+
int32 end = 2;
|
|
143
|
+
}
|
|
144
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# source: olympicsagent.proto
|
|
4
|
+
"""Generated protocol buffer code."""
|
|
5
|
+
|
|
6
|
+
from google.protobuf import descriptor as _descriptor
|
|
7
|
+
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
8
|
+
from google.protobuf import symbol_database as _symbol_database
|
|
9
|
+
from google.protobuf.internal import builder as _builder
|
|
10
|
+
# @@protoc_insertion_point(imports)
|
|
11
|
+
|
|
12
|
+
_sym_db = _symbol_database.Default()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(
|
|
16
|
+
b'\n\x13olympicsagent.proto\x12\x10olympicsagent.v1"-\n\x0c\x43ityLocation\x12\x0c\n\x04\x63ity\x18\x01 \x01(\t\x12\x0f\n\x07\x63ountry\x18\x02 \x01(\t"\x1d\n\rOlympicsQuery\x12\x0c\n\x04year\x18\x01 \x01(\x05"!\n\x0fStreamingResult\x12\x0e\n\x06\x61nswer\x18\x01 \x01(\t"3\n\x15OlympicsDurationQuery\x12\r\n\x05start\x18\x01 \x01(\x05\x12\x0b\n\x03\x65nd\x18\x02 \x01(\x05\x32\xb2\x01\n\rOlympicsAgent\x12\x46\n\x03\x41sk\x12\x1f.olympicsagent.v1.OlympicsQuery\x1a\x1e.olympicsagent.v1.CityLocation\x12Y\n\tAskStream\x12\'.olympicsagent.v1.OlympicsDurationQuery\x1a!.olympicsagent.v1.StreamingResult0\x01\x62\x06proto3'
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
_globals = globals()
|
|
20
|
+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
|
21
|
+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "olympicsagent_pb2", _globals)
|
|
22
|
+
if _descriptor._USE_C_DESCRIPTORS == False:
|
|
23
|
+
DESCRIPTOR._options = None
|
|
24
|
+
_globals["_CITYLOCATION"]._serialized_start = 41
|
|
25
|
+
_globals["_CITYLOCATION"]._serialized_end = 86
|
|
26
|
+
_globals["_OLYMPICSQUERY"]._serialized_start = 88
|
|
27
|
+
_globals["_OLYMPICSQUERY"]._serialized_end = 117
|
|
28
|
+
_globals["_STREAMINGRESULT"]._serialized_start = 119
|
|
29
|
+
_globals["_STREAMINGRESULT"]._serialized_end = 152
|
|
30
|
+
_globals["_OLYMPICSDURATIONQUERY"]._serialized_start = 154
|
|
31
|
+
_globals["_OLYMPICSDURATIONQUERY"]._serialized_end = 205
|
|
32
|
+
_globals["_OLYMPICSAGENT"]._serialized_start = 208
|
|
33
|
+
_globals["_OLYMPICSAGENT"]._serialized_end = 386
|
|
34
|
+
# @@protoc_insertion_point(module_scope)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from google.protobuf import descriptor as _descriptor
|
|
2
|
+
from google.protobuf import message as _message
|
|
3
|
+
from typing import ClassVar as _ClassVar, Optional as _Optional
|
|
4
|
+
|
|
5
|
+
DESCRIPTOR: _descriptor.FileDescriptor
|
|
6
|
+
|
|
7
|
+
class CityLocation(_message.Message):
|
|
8
|
+
__slots__ = ["city", "country"]
|
|
9
|
+
CITY_FIELD_NUMBER: _ClassVar[int]
|
|
10
|
+
COUNTRY_FIELD_NUMBER: _ClassVar[int]
|
|
11
|
+
city: str
|
|
12
|
+
country: str
|
|
13
|
+
def __init__(
|
|
14
|
+
self, city: _Optional[str] = ..., country: _Optional[str] = ...
|
|
15
|
+
) -> None: ...
|
|
16
|
+
|
|
17
|
+
class OlympicsQuery(_message.Message):
|
|
18
|
+
__slots__ = ["year"]
|
|
19
|
+
YEAR_FIELD_NUMBER: _ClassVar[int]
|
|
20
|
+
year: int
|
|
21
|
+
def __init__(self, year: _Optional[int] = ...) -> None: ...
|
|
22
|
+
|
|
23
|
+
class StreamingResult(_message.Message):
|
|
24
|
+
__slots__ = ["answer"]
|
|
25
|
+
ANSWER_FIELD_NUMBER: _ClassVar[int]
|
|
26
|
+
answer: str
|
|
27
|
+
def __init__(self, answer: _Optional[str] = ...) -> None: ...
|
|
28
|
+
|
|
29
|
+
class OlympicsDurationQuery(_message.Message):
|
|
30
|
+
__slots__ = ["start", "end"]
|
|
31
|
+
START_FIELD_NUMBER: _ClassVar[int]
|
|
32
|
+
END_FIELD_NUMBER: _ClassVar[int]
|
|
33
|
+
start: int
|
|
34
|
+
end: int
|
|
35
|
+
def __init__(
|
|
36
|
+
self, start: _Optional[int] = ..., end: _Optional[int] = ...
|
|
37
|
+
) -> None: ...
|