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

Added OpenSourceAI and conversational support in the extension#1206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
SilasMarvin merged 22 commits intomasterfromsilas-open-source-ai-better-rebase
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
22 commits
Select commitHold shift + click to select a range
3ff2f07
Added OpenSourceAI and conversational support in the extension
SilasMarvinNov 22, 2023
1ca5dc8
Clean up errors and guard rails around conversational api
SilasMarvinNov 22, 2023
b6b7ec6
Not great, pivoting to better solution after talking with Santi
SilasMarvinNov 28, 2023
be4788a
Working conversational everything
SilasMarvinNov 28, 2023
719fdc5
Fixed typo
SilasMarvinNov 28, 2023
23ef2a3
Working non streaming open source ai replacement
SilasMarvinNov 28, 2023
dedf434
Remove outdated comment
SilasMarvinNov 28, 2023
f3d8e1f
Working OpenSourceAI with both sync and async options
SilasMarvinNov 29, 2023
2969c89
Cleaned up and tested well
SilasMarvinNov 29, 2023
3b26743
Completely removed the GPTQ pipeline as it is no longer necessary
SilasMarvinNov 29, 2023
cf1afc6
Removed unnecessary python imports
SilasMarvinNov 29, 2023
accd159
Removed universal debugger output
SilasMarvinNov 30, 2023
e5eccec
Finalized models in SDK for open source ai
SilasMarvinDec 1, 2023
95e1e9a
Updated to work with hugging face tokens
SilasMarvinDec 1, 2023
c80817b
Finalized models in SDK for open source ai
SilasMarvinDec 1, 2023
9a3ca91
Removed unnecessary comment
SilasMarvinDec 1, 2023
4eb88f8
Put back the GGML pipeline and removed the GPTQ pipeline earlier comm…
SilasMarvinDec 1, 2023
93e7ffb
Changed some error messages
SilasMarvinDec 1, 2023
73ee33a
Added migration for 2.8.1
SilasMarvinDec 1, 2023
0201880
Working migration file
SilasMarvinDec 1, 2023
47c18d6
Really working migration file
SilasMarvinDec 1, 2023
fb3f7f7
Bumped version
SilasMarvinDec 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionpgml-extension/Cargo.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
[package]
name = "pgml"
version = "2.8.0"
version = "2.8.1"
edition = "2021"

[lib]
Expand Down
67 changes: 67 additions & 0 deletionspgml-extension/sql/pgml--2.8.0--2.8.1.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
-- pgml::api::transform_conversational_json
CREATE FUNCTION pgml."transform"(
"task" jsonb, /* pgrx::datum::json::JsonB */
"args" jsonb DEFAULT '{}', /* pgrx::datum::json::JsonB */
"inputs" jsonb[] DEFAULT ARRAY[]::JSONB[], /* Vec<pgrx::datum::json::JsonB> */
"cache" bool DEFAULT false /* bool */
) RETURNS jsonb /* alloc::string::String */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'transform_conversational_json_wrapper';

-- pgml::api::transform_conversational_string
CREATE FUNCTION pgml."transform"(
"task" TEXT, /* alloc::string::String */
"args" jsonb DEFAULT '{}', /* pgrx::datum::json::JsonB */
"inputs" jsonb[] DEFAULT ARRAY[]::JSONB[], /* Vec<pgrx::datum::json::JsonB> */
"cache" bool DEFAULT false /* bool */
) RETURNS jsonb /* alloc::string::String */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'transform_conversational_string_wrapper';

-- pgml::api::transform_stream_string
DROP FUNCTION IF EXISTS pgml."transform_stream"(text,jsonb,text,boolean);
CREATE FUNCTION pgml."transform_stream"(
"task" TEXT, /* alloc::string::String */
"args" jsonb DEFAULT '{}', /* pgrx::datum::json::JsonB */
"input" TEXT DEFAULT '', /* &str */
"cache" bool DEFAULT false /* bool */
) RETURNS SETOF jsonb /* pgrx::datum::json::JsonB */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'transform_stream_string_wrapper';

-- pgml::api::transform_stream_json
DROP FUNCTION IF EXISTS pgml."transform_stream"(jsonb,jsonb,text,boolean);
CREATE FUNCTION pgml."transform_stream"(
"task" jsonb, /* pgrx::datum::json::JsonB */
"args" jsonb DEFAULT '{}', /* pgrx::datum::json::JsonB */
"input" TEXT DEFAULT '', /* &str */
"cache" bool DEFAULT false /* bool */
) RETURNS SETOF jsonb /* pgrx::datum::json::JsonB */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'transform_stream_json_wrapper';

-- pgml::api::transform_stream_conversational_json
CREATE FUNCTION pgml."transform_stream"(
"task" TEXT, /* alloc::string::String */
"args" jsonb DEFAULT '{}', /* pgrx::datum::json::JsonB */
"inputs" jsonb[] DEFAULT ARRAY[]::JSONB[], /* Vec<pgrx::datum::json::JsonB> */
"cache" bool DEFAULT false /* bool */
) RETURNS SETOF jsonb /* pgrx::datum::json::JsonB */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'transform_stream_conversational_string_wrapper';

-- pgml::api::transform_stream_conversational_string
CREATE FUNCTION pgml."transform_stream"(
"task" jsonb, /* pgrx::datum::json::JsonB */
"args" jsonb DEFAULT '{}', /* pgrx::datum::json::JsonB */
"inputs" jsonb[] DEFAULT ARRAY[]::JSONB[], /* Vec<pgrx::datum::json::JsonB> */
"cache" bool DEFAULT false /* bool */
) RETURNS SETOF jsonb /* pgrx::datum::json::JsonB */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'transform_stream_conversational_json_wrapper';
96 changes: 94 additions & 2 deletionspgml-extension/src/api.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -632,6 +632,50 @@ pub fn transform_string(
}
}

#[cfg(all(feature = "python", not(feature = "use_as_lib")))]
#[pg_extern(immutable, parallel_safe, name = "transform")]
#[allow(unused_variables)] // cache is maintained for api compatibility
pub fn transform_conversational_json(
task: JsonB,
args: default!(JsonB, "'{}'"),
inputs: default!(Vec<JsonB>, "ARRAY[]::JSONB[]"),
cache: default!(bool, false),
) -> JsonB {
if !task.0["task"]
.as_str()
.is_some_and(|v| v == "conversational")
{
error!(
"ARRAY[]::JSONB inputs for transform should only be used with a conversational task"
);
}
match crate::bindings::transformers::transform(&task.0, &args.0, inputs) {
Ok(output) => JsonB(output),
Err(e) => error!("{e}"),
}
}

#[cfg(all(feature = "python", not(feature = "use_as_lib")))]
#[pg_extern(immutable, parallel_safe, name = "transform")]
#[allow(unused_variables)] // cache is maintained for api compatibility
pub fn transform_conversational_string(
task: String,
args: default!(JsonB, "'{}'"),
inputs: default!(Vec<JsonB>, "ARRAY[]::JSONB[]"),
cache: default!(bool, false),
) -> JsonB {
if task != "conversational" {
error!(
"ARRAY[]::JSONB inputs for transform should only be used with a conversational task"
);
}
let task_json = json!({ "task": task });
match crate::bindings::transformers::transform(&task_json, &args.0, inputs) {
Ok(output) => JsonB(output),
Err(e) => error!("{e}"),
}
}

#[cfg(all(feature = "python", not(feature = "use_as_lib")))]
#[pg_extern(immutable, parallel_safe, name = "transform_stream")]
#[allow(unused_variables)] // cache is maintained for api compatibility
Expand All@@ -640,7 +684,7 @@ pub fn transform_stream_json(
args: default!(JsonB, "'{}'"),
input: default!(&str, "''"),
cache: default!(bool, false),
) -> SetOfIterator<'static,String> {
) -> SetOfIterator<'static,JsonB> {
// We can unwrap this becuase if there is an error the current transaction is aborted in the map_err call
let python_iter =
crate::bindings::transformers::transform_stream_iterator(&task.0, &args.0, input)
Expand All@@ -657,7 +701,7 @@ pub fn transform_stream_string(
args: default!(JsonB, "'{}'"),
input: default!(&str, "''"),
cache: default!(bool, false),
) -> SetOfIterator<'static,String> {
) -> SetOfIterator<'static,JsonB> {
let task_json = json!({ "task": task });
// We can unwrap this becuase if there is an error the current transaction is aborted in the map_err call
let python_iter =
Expand All@@ -667,6 +711,54 @@ pub fn transform_stream_string(
SetOfIterator::new(python_iter)
}

#[cfg(all(feature = "python", not(feature = "use_as_lib")))]
#[pg_extern(immutable, parallel_safe, name = "transform_stream")]
#[allow(unused_variables)] // cache is maintained for api compatibility
pub fn transform_stream_conversational_json(
task: JsonB,
args: default!(JsonB, "'{}'"),
inputs: default!(Vec<JsonB>, "ARRAY[]::JSONB[]"),
cache: default!(bool, false),
) -> SetOfIterator<'static, JsonB> {
if !task.0["task"]
.as_str()
.is_some_and(|v| v == "conversational")
{
error!(
"ARRAY[]::JSONB inputs for transform_stream should only be used with a conversational task"
);
}
// We can unwrap this becuase if there is an error the current transaction is aborted in the map_err call
let python_iter =
crate::bindings::transformers::transform_stream_iterator(&task.0, &args.0, inputs)
.map_err(|e| error!("{e}"))
.unwrap();
SetOfIterator::new(python_iter)
}

#[cfg(all(feature = "python", not(feature = "use_as_lib")))]
#[pg_extern(immutable, parallel_safe, name = "transform_stream")]
#[allow(unused_variables)] // cache is maintained for api compatibility
pub fn transform_stream_conversational_string(
task: String,
args: default!(JsonB, "'{}'"),
inputs: default!(Vec<JsonB>, "ARRAY[]::JSONB[]"),
cache: default!(bool, false),
) -> SetOfIterator<'static, JsonB> {
if task != "conversational" {
error!(
"ARRAY::JSONB inputs for transform_stream should only be used with a conversational task"
);
}
let task_json = json!({ "task": task });
// We can unwrap this becuase if there is an error the current transaction is aborted in the map_err call
let python_iter =
crate::bindings::transformers::transform_stream_iterator(&task_json, &args.0, inputs)
.map_err(|e| error!("{e}"))
.unwrap();
SetOfIterator::new(python_iter)
}

#[cfg(feature = "python")]
#[pg_extern(immutable, parallel_safe, name = "generate")]
fn generate(project_name: &str, inputs: &str, config: default!(JsonB, "'{}'")) -> String {
Expand Down
24 changes: 12 additions & 12 deletionspgml-extension/src/bindings/transformers/transform.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,28 +23,28 @@ impl TransformStreamIterator {
}

impl Iterator for TransformStreamIterator {
type Item =String;
type Item =JsonB;
fn next(&mut self) -> Option<Self::Item> {
// We can unwrap this becuase if there is an error the current transaction is aborted in the map_err call
Python::with_gil(|py| -> Result<Option<String>, PyErr> {
Python::with_gil(|py| -> Result<Option<JsonB>, PyErr> {
let code = "next(python_iter)";
let res: &PyAny = py.eval(code, Some(self.locals.as_ref(py)), None)?;
if res.is_none() {
Ok(None)
} else {
let res: String = res.extract()?;
Ok(Some(res))
let res:Vec<String> = res.extract()?;
Ok(Some(JsonB(serde_json::to_value(res).unwrap())))
}
})
.map_err(|e| error!("{e}"))
.unwrap()
}
}

pub fn transform(
pub fn transform<T: serde::Serialize>(
task: &serde_json::Value,
args: &serde_json::Value,
inputs:Vec<&str>,
inputs:T,
) -> Result<serde_json::Value> {
crate::bindings::python::activate()?;
whitelist::verify_task(task)?;
Expand DownExpand Up@@ -74,17 +74,17 @@ pub fn transform(
Ok(serde_json::from_str(&results)?)
}

pub fn transform_stream(
pub fn transform_stream<T: serde::Serialize>(
task: &serde_json::Value,
args: &serde_json::Value,
input:&str,
input:T,
) -> Result<Py<PyAny>> {
crate::bindings::python::activate()?;
whitelist::verify_task(task)?;

let task = serde_json::to_string(task)?;
let args = serde_json::to_string(args)?;
letinputs = serde_json::to_string(&vec![input])?;
letinput = serde_json::to_string(&input)?;

Python::with_gil(|py| -> Result<Py<PyAny>> {
let transform: Py<PyAny> = get_module!(PY_MODULE)
Expand All@@ -99,7 +99,7 @@ pub fn transform_stream(
&[
task.into_py(py),
args.into_py(py),
inputs.into_py(py),
input.into_py(py),
true.into_py(py),
],
),
Expand All@@ -110,10 +110,10 @@ pub fn transform_stream(
})
}

pub fn transform_stream_iterator(
pub fn transform_stream_iterator<T: serde::Serialize>(
task: &serde_json::Value,
args: &serde_json::Value,
input:&str,
input:T,
) -> Result<TransformStreamIterator> {
let python_iter = transform_stream(task, args, input)
.map_err(|e| error!("{e}"))
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp