Skip to content

Commit

Permalink
add send sync for CF worker
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldslc committed Dec 31, 2024
1 parent 8e6f197 commit 204b2d5
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ target/
.DS_Store
.idea/
.vscode/
.devcontainer/
97 changes: 97 additions & 0 deletions Cargo.lock

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

12 changes: 7 additions & 5 deletions rig-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ rig-derive = { version = "0.1.0", path = "./rig-core-derive", optional = true }
glob = "0.3.1"
lopdf = { version = "0.34.0", optional = true }
rayon = { version = "1.10.0", optional = true}
worker = { version = "0.5", optional = true }

[dev-dependencies]
anyhow = "1.0.75"
Expand All @@ -40,27 +41,28 @@ all = ["derive", "pdf", "rayon"]
derive = ["dep:rig-derive"]
pdf = ["dep:lopdf"]
rayon = ["dep:rayon"]
worker = ["dep:worker"]

[[test]]
name = "embed_macro"
required-features = ["derive"]

[[example]]
name = "rag"
required-features = ["derive"]
required-features = ["derive"]

[[example]]
name = "vector_search"
required-features = ["derive"]
required-features = ["derive"]

[[example]]
name = "vector_search_cohere"
required-features = ["derive"]
required-features = ["derive"]

[[example]]
name = "gemini_embeddings"
required-features = ["derive"]
required-features = ["derive"]

[[example]]
name = "xai_embeddings"
required-features = ["derive"]
required-features = ["derive"]
1 change: 1 addition & 0 deletions rig-core/src/providers/anthropic/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ enum ToolChoice {
impl completion::CompletionModel for CompletionModel {
type Response = CompletionResponse;

#[cfg_attr(feature = "worker", worker::send)]
async fn completion(
&self,
completion_request: completion::CompletionRequest,
Expand Down
2 changes: 2 additions & 0 deletions rig-core/src/providers/cohere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ impl embeddings::EmbeddingModel for EmbeddingModel {
self.ndims
}

#[cfg_attr(feature = "worker", worker::send)]
async fn embed_texts(
&self,
documents: impl IntoIterator<Item = String>,
Expand Down Expand Up @@ -512,6 +513,7 @@ impl CompletionModel {
impl completion::CompletionModel for CompletionModel {
type Response = CompletionResponse;

#[cfg_attr(feature = "worker", worker::send)]
async fn completion(
&self,
completion_request: completion::CompletionRequest,
Expand Down
1 change: 1 addition & 0 deletions rig-core/src/providers/gemini/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl CompletionModel {
impl completion::CompletionModel for CompletionModel {
type Response = GenerateContentResponse;

#[cfg_attr(feature = "worker", worker::send)]
async fn completion(
&self,
mut completion_request: CompletionRequest,
Expand Down
1 change: 1 addition & 0 deletions rig-core/src/providers/gemini/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl embeddings::EmbeddingModel for EmbeddingModel {
}
}

#[cfg_attr(feature = "worker", worker::send)]
async fn embed_texts(
&self,
documents: impl IntoIterator<Item = String> + Send,
Expand Down
2 changes: 2 additions & 0 deletions rig-core/src/providers/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ impl embeddings::EmbeddingModel for EmbeddingModel {
self.ndims
}

#[cfg_attr(feature = "worker", worker::send)]
async fn embed_texts(
&self,
documents: impl IntoIterator<Item = String>,
Expand Down Expand Up @@ -475,6 +476,7 @@ impl CompletionModel {
impl completion::CompletionModel for CompletionModel {
type Response = CompletionResponse;

#[cfg_attr(feature = "worker", worker::send)]
async fn completion(
&self,
mut completion_request: CompletionRequest,
Expand Down
1 change: 1 addition & 0 deletions rig-core/src/providers/perplexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ impl CompletionModel {
impl completion::CompletionModel for CompletionModel {
type Response = CompletionResponse;

#[cfg_attr(feature = "worker", worker::send)]
async fn completion(
&self,
completion_request: completion::CompletionRequest,
Expand Down
1 change: 1 addition & 0 deletions rig-core/src/providers/xai/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl CompletionModel {
impl completion::CompletionModel for CompletionModel {
type Response = CompletionResponse;

#[cfg_attr(feature = "worker", worker::send)]
async fn completion(
&self,
mut completion_request: completion::CompletionRequest,
Expand Down
1 change: 1 addition & 0 deletions rig-core/src/providers/xai/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl embeddings::EmbeddingModel for EmbeddingModel {
self.ndims
}

#[cfg_attr(feature = "worker", worker::send)]
async fn embed_texts(
&self,
documents: impl IntoIterator<Item = String>,
Expand Down

0 comments on commit 204b2d5

Please sign in to comment.