Skip to content

Commit

Permalink
feat: added openrouter support (#146)
Browse files Browse the repository at this point in the history
* added openrouter

* smol update

* added blacklisting on wrong protocol
  • Loading branch information
erhant authored Nov 19, 2024
1 parent 89075e9 commit d6ff15d
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ OPENAI_API_KEY=
## Gemini (if used, required) ##
GEMINI_API_KEY=

## Open Router (if used, required) ##
OPENROUTER_API_KEY=

## Ollama (if used, optional) ##
# do not change this, it is used by Docker
OLLAMA_HOST=http://host.docker.internal
Expand Down
113 changes: 54 additions & 59 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default-members = ["compute"]

[workspace.package]
edition = "2021"
version = "0.2.21"
version = "0.2.22"
license = "Apache-2.0"
readme = "README.md"

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM rust:1.75 as builder
FROM --platform=$BUILDPLATFORM rust:1.75 AS builder

# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
#
Expand Down
6 changes: 6 additions & 0 deletions compute/src/utils/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub struct DKNMessage {
///
/// NOTE: This can be obtained via Identify protocol version
pub(crate) version: String,
/// Identity protocol string of the Dria Compute Node
#[serde(default)]
pub(crate) identity: String,
/// The timestamp of the message, in nanoseconds
///
/// NOTE: This can be obtained via DataTransform in GossipSub
Expand All @@ -46,6 +49,9 @@ impl DKNMessage {
payload: BASE64_STANDARD.encode(data),
topic: topic.to_string(),
version: DRIA_COMPUTE_NODE_VERSION.to_string(),
identity: dkn_p2p::P2P_IDENTITY_PREFIX
.trim_end_matches('/')
.to_string(),
timestamp: get_current_time_nanos(),
}
}
Expand Down
8 changes: 8 additions & 0 deletions p2p/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ impl DriaP2PClient {
log::warn!("Local node is listening on {}", address);
}
SwarmEvent::ExternalAddrConfirmed { address } => {
// this is usually the external address via relay
log::info!("External address confirmed: {}", address);
}
event => log::trace!("Unhandled Swarm Event: {:?}", event),
Expand All @@ -275,6 +276,13 @@ impl DriaP2PClient {
info.protocol_version,
self.identity_protocol
);

// blacklist peers with different protocol
self.swarm
.behaviour_mut()
.gossipsub
.blacklist_peer(&peer_id);

return;
}

Expand Down
4 changes: 2 additions & 2 deletions p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ mod client;
pub use client::DriaP2PClient;

/// Prefix for Kademlia protocol, must start with `/`!
pub(crate) const P2P_KADEMLIA_PREFIX: &str = "/dria/kad/";
pub const P2P_KADEMLIA_PREFIX: &str = "/dria/kad/";

/// Prefix for Identity protocol string.
pub(crate) const P2P_IDENTITY_PREFIX: &str = "dria/";
pub const P2P_IDENTITY_PREFIX: &str = "dria/";

// re-exports
pub use libp2p;
Expand Down
Loading

0 comments on commit d6ff15d

Please sign in to comment.