Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39695fb

Browse files
committed
Some updates to text
1 parentb88ef63 commit39695fb

File tree

7 files changed

+33
-145
lines changed

7 files changed

+33
-145
lines changed

‎pgml-sdks/rust/pgml/README.md‎

Lines changed: 8 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,14 @@
11
#Open Source Alternative for Building End-to-End Vector Search Applications without OpenAI & Pinecone
2-
#How to use this crate
32

4-
Here is a brief outline of how to use this crate and specifically add new Python classes.
3+
#Suported Languages
54

6-
There are three main macros to know about:
7-
-`custom_derive`
8-
-`custom_methods`
9-
-`custom_into_py`
5+
We support a number of different languages:
6+
-[Python](/)
7+
-[JavaScript](/)
8+
-Rust
109

11-
##custom_derive
12-
`custom_derive` is used when defining a new struct that you want to be available as a Python class. This macro automatically creates a wrapper for the struct postfixing the name with`Python`. For example, the following code:
13-
```
14-
#[derive(custom_derive, Debug, Clone)]
15-
pub struct TestStruct {
16-
pub name: String
17-
}
18-
```
10+
Our SDK is written completely in Rust and translated by Rust to our other supported languages. See each individual language for an overview and specification on how to use the SDK.
1911

20-
Creates another struct:
12+
#Rust
2113

22-
```
23-
pub struct TestStructPython {
24-
pub wrapped: TestStruct
25-
}
26-
```
27-
28-
You must currently implement`Debug` and`Clone` on the structs you use`custom_derive` on.
29-
30-
##custom_methods
31-
`custom_methods` is used on the impl block for a struct you want to be available as a Python class. This macro automatically creates methods that work seamlessly with pyO3. For example, the following code:
32-
```
33-
#[custom_methods(new, get_name)]
34-
impl TestStruct {
35-
pub fn new(name: String) -> Self {
36-
Self { name }
37-
}
38-
pub fn get_name(&self) -> String {
39-
self.name.clone()
40-
}
41-
}
42-
```
43-
44-
Produces similar code to the following:
45-
```
46-
impl TestStruct {
47-
pub fn new(name: String) -> Self {
48-
Self { name }
49-
}
50-
pub fn get_name(&self) -> String {
51-
self.name.clone()
52-
}
53-
}
54-
55-
impl TestStructPython {
56-
pub fn new<'a>(name: String, py: Python<'a>) -> PyResult<Self> {
57-
let x = TestStruct::new(name);
58-
Ok(TestStructPython::from(x))
59-
}
60-
pub fn get_name<'a>(&self, py: Python<'a>) -> PyResult<String> {
61-
let x = self.wrapped.get_name();
62-
Ok(x)
63-
}
64-
}
65-
```
66-
67-
Note that the macro only works on methods marked with`pub`;
68-
69-
##custom_into_py
70-
`custom_into_py` is used when we want to seamlessly return Rust structs as Python dictionaries. For example, let's say we have the following code:
71-
```
72-
#[derive(custom_into_py, FromRow, Debug, Clone)]
73-
pub struct Splitter {
74-
pub id: i64,
75-
pub created_at: DateTime<Utc>,
76-
pub name: String,
77-
pub parameters: Json<HashMap<String, String>>,
78-
}
79-
80-
pub async fn get_text_splitters(&self) -> anyhow::Result<Vec<Splitter>> {
81-
Ok(sqlx::query_as(&query_builder!(
82-
"SELECT * from %s",
83-
self.splitters_table_name
84-
))
85-
.fetch_all(self.pool.borrow())
86-
.await?)
87-
}
88-
89-
```
90-
91-
The`custom_into_py` macro automatically generates the following code for us:
92-
```
93-
impl IntoPy<PyObject> for Splitter {
94-
fn into_py(self, py: Python<'_>) -> PyObject {
95-
let dict = PyDict::new(py);
96-
dict.set_item("id", self.id)
97-
.expect("Error setting python value in custom_into_py proc_macro");
98-
dict.set_item("created_at", self.created_at.timestamp())
99-
.expect("Error setting python value in custom_into_py proc_macro");
100-
dict.set_item("name", self.name)
101-
.expect("Error setting python value in custom_into_py proc_macro");
102-
dict.set_item("parameters", self.parameters.0)
103-
.expect("Error setting python value in custom_into_py proc_macro");
104-
dict.into()
105-
}
106-
}
107-
```
108-
109-
Implementing`IntoPy` allows pyo3 to seamlessly convert between Rust and python. Note that Python users calling`get_text_splitters` will receive a list of dictionaries.
110-
111-
##Other Noteworthy Things
112-
113-
Be aware that the only pyo3 specific code in this crate is the`pymodule` invocation in`lib.rs`. Everything else is handled by`pgml-macros`. If you want to expose a Python Class directly on the Python module you have to add it in the`pymodule` invocation. For example, if you wanted to expose`TestStruct` so Python module users could access it directly on`pgml`, you could do the following:
114-
```
115-
#[pymodule]
116-
fn pgml(_py: Python, m: &PyModule) -> PyResult<()> {
117-
m.add_class::<TestStructPython>()?;
118-
Ok(())
119-
}
120-
```
121-
122-
Now Python users can access it like so:
123-
```
124-
import pgml
125-
126-
t = pgml.TestStruct("test")
127-
print(t.get_name())
128-
129-
```
130-
131-
For local development, install[maturin](https://github.com/PyO3/maturin) and run:
132-
```
133-
maturin develop
134-
```
135-
136-
You can now run the tests in`python/test.py`.
14+
More information about our methodologies and Rust SDK coming soon.

‎pgml-sdks/rust/pgml/src/builtins.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use pgml_macros::{custom_derive, custom_methods};
22
use sqlx::Row;
33
use tracing::instrument;
44

5+
/// Provides access to builtin database methods
56
#[derive(custom_derive,Debug,Clone)]
67
pubstructBuiltins{
78
pubdatabase_url:Option<String>,

‎pgml-sdks/rust/pgml/src/lib.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ async fn get_or_initialize_pool(database_url: &Option<String>) -> anyhow::Result
5959
}
6060
}
6161

62-
pubenumLogFormat{
63-
JSON,
62+
enumLogFormat{
63+
Json,
6464
Pretty,
6565
}
6666

6767
implFrom<&str>forLogFormat{
6868
fnfrom(s:&str) ->Self{
6969
match s{
70-
"JSON" =>LogFormat::JSON,
70+
"Json" =>LogFormat::Json,
7171
_ =>LogFormat::Pretty,
7272
}
7373
}
@@ -87,7 +87,7 @@ fn init_logger(level: Option<String>, format: Option<String>) -> anyhow::Result<
8787
let format = format.unwrap_or_else(|| env::var("LOG_FORMAT").unwrap_or("".to_string()));
8888

8989
match format.as_str().into(){
90-
LogFormat::JSON =>FmtSubscriber::builder()
90+
LogFormat::Json =>FmtSubscriber::builder()
9191
.json()
9292
.with_max_level(level)
9393
.try_init()

‎pgml-sdks/rust/pgml/src/model.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub(crate) struct ModelDatabaseData {
5454
pubcreated_at:DateTime,
5555
}
5656

57+
/// A model used for embedding, inference, etc...
5758
#[derive(custom_derive,Debug,Clone)]
5859
pubstructModel{
5960
pubname:String,

‎pgml-sdks/rust/pgml/src/models.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use sqlx::FromRow;
55

66
usecrate::types::{DateTime,Json};
77

8-
/// A pipeline
8+
// A pipeline
99
#[enum_def]
1010
#[derive(FromRow)]
1111
pubstructPipeline{
@@ -18,7 +18,7 @@ pub struct Pipeline {
1818
pubparameters:Json,
1919
}
2020

21-
/// A model used to perform some task
21+
// A model used to perform some task
2222
#[enum_def]
2323
#[derive(FromRow)]
2424
pubstructModel{
@@ -28,7 +28,7 @@ pub struct Model {
2828
pubhyperparams:Json,
2929
}
3030

31-
/// A text splitter
31+
// A text splitter
3232
#[enum_def]
3333
#[derive(FromRow)]
3434
pubstructSplitter{
@@ -38,7 +38,7 @@ pub struct Splitter {
3838
pubparameters:Json,
3939
}
4040

41-
/// A pipeline with its model and splitter
41+
// A pipeline with its model and splitter
4242
#[derive(FromRow,Clone)]
4343
pubstructPipelineWithModelAndSplitter{
4444
pubpipeline_id:i64,
@@ -56,7 +56,7 @@ pub struct PipelineWithModelAndSplitter {
5656
pubsplitter_parameters:Json,
5757
}
5858

59-
/// A document
59+
// A document
6060
#[enum_def]
6161
#[derive(FromRow,Serialize)]
6262
pubstructDocument{
@@ -69,7 +69,7 @@ pub struct Document {
6969
pubtext:String,
7070
}
7171

72-
/// A collection of documents
72+
// A collection of documents
7373
#[enum_def]
7474
#[derive(FromRow)]
7575
pubstructCollection{
@@ -80,7 +80,7 @@ pub struct Collection {
8080
pubproject_id:i64,
8181
}
8282

83-
/// An embedding
83+
// An embedding
8484
#[enum_def]
8585
#[derive(FromRow)]
8686
pubstructEmbedding{
@@ -90,7 +90,7 @@ pub struct Embedding {
9090
pubembedding:Vec<f32>,
9191
}
9292

93-
/// A chunk of split text
93+
// A chunk of split text
9494
#[derive(FromRow)]
9595
pubstructChunk{
9696
pubid:i64,

‎pgml-sdks/rust/pgml/src/pipeline.rs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ impl From<InvividualSyncStatus> for Json {
4747
implFrom<Json>forInvividualSyncStatus{
4848
fnfrom(value:Json) ->Self{
4949
Self{
50-
synced: value["synced"].as_i64().expect("The synced field is not an integer"),
51-
not_synced: value["not_synced"].as_i64().expect("The not_synced field is not an integer"),
52-
total: value["total"].as_i64().expect("The total field is not an integer"),
50+
synced: value["synced"]
51+
.as_i64()
52+
.expect("The synced field is not an integer"),
53+
not_synced: value["not_synced"]
54+
.as_i64()
55+
.expect("The not_synced field is not an integer"),
56+
total: value["total"]
57+
.as_i64()
58+
.expect("The total field is not an integer"),
5359
}
5460
}
5561
}
@@ -90,6 +96,7 @@ pub struct PipelineDatabaseData {
9096
pubsplitter_id:i64,
9197
}
9298

99+
/// A pipeline that processes documents
93100
#[derive(custom_derive,Debug,Clone)]
94101
pubstructPipeline{
95102
pubname:String,

‎pgml-sdks/rust/pgml/src/splitter.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub(crate) struct SplitterDatabaseData {
2121
pubcreated_at:DateTime,
2222
}
2323

24+
/// A text splitter
2425
#[derive(custom_derive,Debug,Clone)]
2526
pubstructSplitter{
2627
pubname:String,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp