Skip to content

Updated to use parking_lot and cleaned up tests #1221

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions pgml-sdks/pgml/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pgml-sdks/pgml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ is-terminal = "0.4"
colored = "2"
ctrlc = "3"
inquire = "0.6"
parking_lot = "0.12.1"

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion pgml-sdks/pgml/javascript/tests/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export default {
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
testTimeout: 30000,
testTimeout: 300000,
}
8 changes: 4 additions & 4 deletions pgml-sdks/pgml/javascript/tests/typescript-tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ it("can transformer pipeline stream", async () => {
it("can open source ai create", () => {
const client = pgml.newOpenSourceAI();
const results = client.chat_completions_create(
"mistralai/Mistral-7B-v0.1",
"HuggingFaceH4/zephyr-7b-beta",
[
{
role: "system",
Expand All @@ -328,7 +328,7 @@ it("can open source ai create", () => {
it("can open source ai create async", async () => {
const client = pgml.newOpenSourceAI();
const results = await client.chat_completions_create_async(
"mistralai/Mistral-7B-v0.1",
"HuggingFaceH4/zephyr-7b-beta",
[
{
role: "system",
Expand All @@ -347,7 +347,7 @@ it("can open source ai create async", async () => {
it("can open source ai create stream", () => {
const client = pgml.newOpenSourceAI();
const it = client.chat_completions_create_stream(
"mistralai/Mistral-7B-v0.1",
"HuggingFaceH4/zephyr-7b-beta",
[
{
role: "system",
Expand All @@ -369,7 +369,7 @@ it("can open source ai create stream", () => {
it("can open source ai create stream async", async () => {
const client = pgml.newOpenSourceAI();
const it = await client.chat_completions_create_stream_async(
"mistralai/Mistral-7B-v0.1",
"HuggingFaceH4/zephyr-7b-beta",
[
{
role: "system",
Expand Down
8 changes: 4 additions & 4 deletions pgml-sdks/pgml/python/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ async def test_transformer_pipeline_stream():
def test_open_source_ai_create():
client = pgml.OpenSourceAI()
results = client.chat_completions_create(
"mistralai/Mistral-7B-v0.1",
"HuggingFaceH4/zephyr-7b-beta",
[
{
"role": "system",
Expand All @@ -348,7 +348,7 @@ def test_open_source_ai_create():
async def test_open_source_ai_create_async():
client = pgml.OpenSourceAI()
results = await client.chat_completions_create_async(
"mistralai/Mistral-7B-v0.1",
"HuggingFaceH4/zephyr-7b-beta",
[
{
"role": "system",
Expand All @@ -367,7 +367,7 @@ async def test_open_source_ai_create_async():
def test_open_source_ai_create_stream():
client = pgml.OpenSourceAI()
results = client.chat_completions_create_stream(
"mistralai/Mistral-7B-v0.1",
"HuggingFaceH4/zephyr-7b-beta",
[
{
"role": "system",
Expand All @@ -389,7 +389,7 @@ def test_open_source_ai_create_stream():
async def test_open_source_ai_create_stream_async():
client = pgml.OpenSourceAI()
results = await client.chat_completions_create_stream_async(
"mistralai/Mistral-7B-v0.1",
"HuggingFaceH4/zephyr-7b-beta",
[
{
"role": "system",
Expand Down
7 changes: 2 additions & 5 deletions pgml-sdks/pgml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
//!
//! With this SDK, you can seamlessly manage various database tables related to documents, text chunks, text splitters, LLM (Language Model) models, and embeddings. By leveraging the SDK's capabilities, you can efficiently index LLM embeddings using PgVector for fast and accurate queries.

use parking_lot::RwLock;
use sqlx::{postgres::PgPoolOptions, PgPool};
use std::collections::HashMap;
use std::env;
use std::sync::RwLock;
use tokio::runtime::Runtime;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
Expand All @@ -34,7 +34,6 @@ mod utils;

// Re-export
pub use builtins::Builtins;
pub use cli::cli;
pub use collection::Collection;
pub use model::Model;
pub use open_source_ai::OpenSourceAI;
Expand All @@ -52,9 +51,7 @@ static DATABASE_POOLS: RwLock<Option<HashMap<String, PgPool>>> = RwLock::new(Non
// Even though this function does not use async anywhere, for whatever reason it must be async or
// sqlx's connect_lazy will throw an error
async fn get_or_initialize_pool(database_url: &Option<String>) -> anyhow::Result<PgPool> {
let mut pools = DATABASE_POOLS
.write()
.expect("Error getting DATABASE_POOLS for writing");
let mut pools = DATABASE_POOLS.write();
let pools = pools.get_or_insert_with(HashMap::new);
let environment_url = std::env::var("DATABASE_URL");
let environment_url = environment_url.as_deref();
Expand Down
8 changes: 4 additions & 4 deletions pgml-sdks/pgml/src/open_source_ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ mod tests {
#[test]
fn can_open_source_ai_create() -> anyhow::Result<()> {
let client = OpenSourceAI::new(None);
let results = client.chat_completions_create(Json::from_serializable("mistralai/Mistral-7B-v0.1"), vec![
let results = client.chat_completions_create(Json::from_serializable("HuggingFaceH4/zephyr-7b-beta"), vec![
serde_json::json!({"role": "system", "content": "You are a friendly chatbot who always responds in the style of a pirate"}).into(),
serde_json::json!({"role": "user", "content": "How many helicopters can a human eat in one sitting?"}).into(),
], Some(10), None, Some(3), None)?;
Expand All @@ -412,7 +412,7 @@ mod tests {
#[sqlx::test]
fn can_open_source_ai_create_async() -> anyhow::Result<()> {
let client = OpenSourceAI::new(None);
let results = client.chat_completions_create_async(Json::from_serializable("mistralai/Mistral-7B-v0.1"), vec![
let results = client.chat_completions_create_async(Json::from_serializable("HuggingFaceH4/zephyr-7b-beta"), vec![
serde_json::json!({"role": "system", "content": "You are a friendly chatbot who always responds in the style of a pirate"}).into(),
serde_json::json!({"role": "user", "content": "How many helicopters can a human eat in one sitting?"}).into(),
], Some(10), None, Some(3), None).await?;
Expand All @@ -423,7 +423,7 @@ mod tests {
#[sqlx::test]
fn can_open_source_ai_create_stream_async() -> anyhow::Result<()> {
let client = OpenSourceAI::new(None);
let mut stream = client.chat_completions_create_stream_async(Json::from_serializable("mistralai/Mistral-7B-v0.1"), vec![
let mut stream = client.chat_completions_create_stream_async(Json::from_serializable("HuggingFaceH4/zephyr-7b-beta"), vec![
serde_json::json!({"role": "system", "content": "You are a friendly chatbot who always responds in the style of a pirate"}).into(),
serde_json::json!({"role": "user", "content": "How many helicopters can a human eat in one sitting?"}).into(),
], Some(10), None, Some(3), None).await?;
Expand All @@ -436,7 +436,7 @@ mod tests {
#[test]
fn can_open_source_ai_create_stream() -> anyhow::Result<()> {
let client = OpenSourceAI::new(None);
let iterator = client.chat_completions_create_stream(Json::from_serializable("mistralai/Mistral-7B-v0.1"), vec![
let iterator = client.chat_completions_create_stream(Json::from_serializable("HuggingFaceH4/zephyr-7b-beta"), vec![
serde_json::json!({"role": "system", "content": "You are a friendly chatbot who always responds in the style of a pirate"}).into(),
serde_json::json!({"role": "user", "content": "How many helicopters can a human eat in one sitting?"}).into(),
], Some(10), None, Some(3), None)?;
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy