add install script and compilation fixes
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
use async_trait::async_trait;
|
||||
use openrouter_rs::{OpenRouterClient, api::chat::*, types::Role, ChatCompletionResponse}; // Added ChatCompletionResponse here
|
||||
use openrouter_rs::{OpenRouterClient, api::chat::{ChatCompletionRequest, Message}, types::completion::CompletionsResponse};
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
|
||||
// Re-export Message and MessageRole for easier use in client code
|
||||
pub use openrouter_rs::api::chat::Message;
|
||||
pub use openrouter_rs::types::Role as MessageRole;
|
||||
// Removed the problematic import for ChatCompletionResponse
|
||||
// pub use openrouter_rs::api::chat::chat_completion::ChatCompletionResponse;
|
||||
// Re-export MessageRole for easier use in client code
|
||||
pub use openrouter_rs::types::Role as MessageRole;
|
||||
|
||||
#[async_trait]
|
||||
pub trait AIProvider {
|
||||
async fn completion(
|
||||
&mut self,
|
||||
request: CompletionRequest,
|
||||
) -> Result<ChatCompletionResponse, Box<dyn Error>>;
|
||||
) -> Result<CompletionsResponse, Box<dyn Error>>;
|
||||
}
|
||||
|
||||
pub struct CompletionRequest {
|
||||
@@ -79,7 +76,7 @@ impl<'a> CompletionRequestBuilder<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn completion(self) -> Result<ChatCompletionResponse, Box<dyn Error>> {
|
||||
pub async fn completion(self) -> Result<CompletionsResponse, Box<dyn Error>> {
|
||||
let request = CompletionRequest {
|
||||
model: self.model,
|
||||
messages: self.messages,
|
||||
@@ -102,15 +99,13 @@ impl AIProvider for GroqAIProvider {
|
||||
async fn completion(
|
||||
&mut self,
|
||||
request: CompletionRequest,
|
||||
) -> Result<ChatCompletionResponse, Box<dyn Error>> {
|
||||
) -> Result<CompletionsResponse, Box<dyn Error>> {
|
||||
let chat_request = ChatCompletionRequest::builder()
|
||||
.model(request.model)
|
||||
.messages(request.messages)
|
||||
.temperature(request.temperature.unwrap_or(1.0))
|
||||
.max_tokens(request.max_tokens.map(|x| x as u32).unwrap_or(2048))
|
||||
.top_p(request.top_p.unwrap_or(1.0))
|
||||
.stream(request.stream.unwrap_or(false)) // Corrected to field assignment
|
||||
.stop(request.stop.unwrap_or_default())
|
||||
.build()?;
|
||||
|
||||
let result = self.client.send_chat_completion(&chat_request).await?;
|
||||
@@ -127,15 +122,13 @@ impl AIProvider for OpenAIProvider {
|
||||
async fn completion(
|
||||
&mut self,
|
||||
request: CompletionRequest,
|
||||
) -> Result<ChatCompletionResponse, Box<dyn Error>> {
|
||||
) -> Result<CompletionsResponse, Box<dyn Error>> {
|
||||
let chat_request = ChatCompletionRequest::builder()
|
||||
.model(request.model)
|
||||
.messages(request.messages)
|
||||
.temperature(request.temperature.unwrap_or(1.0))
|
||||
.max_tokens(request.max_tokens.map(|x| x as u32).unwrap_or(2048))
|
||||
.top_p(request.top_p.unwrap_or(1.0))
|
||||
.stream(request.stream.unwrap_or(false)) // Corrected to field assignment
|
||||
.stop(request.stop.unwrap_or_default())
|
||||
.build()?;
|
||||
|
||||
let result = self.client.send_chat_completion(&chat_request).await?;
|
||||
@@ -152,15 +145,13 @@ impl AIProvider for OpenRouterAIProvider {
|
||||
async fn completion(
|
||||
&mut self,
|
||||
request: CompletionRequest,
|
||||
) -> Result<ChatCompletionResponse, Box<dyn Error>> {
|
||||
) -> Result<CompletionsResponse, Box<dyn Error>> {
|
||||
let chat_request = ChatCompletionRequest::builder()
|
||||
.model(request.model)
|
||||
.messages(request.messages)
|
||||
.temperature(request.temperature.unwrap_or(1.0))
|
||||
.max_tokens(request.max_tokens.map(|x| x as u32).unwrap_or(2048))
|
||||
.top_p(request.top_p.unwrap_or(1.0))
|
||||
.stream(request.stream.unwrap_or(false)) // Corrected to field assignment
|
||||
.stop(request.stop.unwrap_or_default())
|
||||
.build()?;
|
||||
|
||||
let result = self.client.send_chat_completion(&chat_request).await?;
|
||||
@@ -177,15 +168,13 @@ impl AIProvider for CerebrasAIProvider {
|
||||
async fn completion(
|
||||
&mut self,
|
||||
request: CompletionRequest,
|
||||
) -> Result<ChatCompletionResponse, Box<dyn Error>> {
|
||||
) -> Result<CompletionsResponse, Box<dyn Error>> {
|
||||
let chat_request = ChatCompletionRequest::builder()
|
||||
.model(request.model)
|
||||
.messages(request.messages)
|
||||
.temperature(request.temperature.unwrap_or(1.0))
|
||||
.max_tokens(request.max_tokens.map(|x| x as u32).unwrap_or(2048))
|
||||
.top_p(request.top_p.unwrap_or(1.0))
|
||||
.stream(request.stream.unwrap_or(false)) // Corrected to field assignment
|
||||
.stop(request.stop.unwrap_or_default())
|
||||
.build()?;
|
||||
|
||||
let result = self.client.send_chat_completion(&chat_request).await?;
|
||||
|
@@ -1004,7 +1004,7 @@ impl OrderServerProduct {
|
||||
})
|
||||
.with_get("traffic", |o: &mut OrderServerProduct| o.traffic.clone())
|
||||
.with_get("dist", |o: &mut OrderServerProduct| o.dist.clone())
|
||||
.with_get("arch", |o: &mut OrderServerProduct| o.arch.clone())
|
||||
.with_get("arch", |o: &mut OrderServerProduct| o.dist.clone())
|
||||
.with_get("lang", |o: &mut OrderServerProduct| o.lang.clone())
|
||||
.with_get("location", |o: &mut OrderServerProduct| o.location.clone())
|
||||
.with_get("prices", |o: &mut OrderServerProduct| o.prices.clone())
|
||||
@@ -1027,7 +1027,7 @@ impl fmt::Display for OrderServerProduct {
|
||||
table.add_row(row!["Distributions", self.dist.join(", ")]);
|
||||
table.add_row(row![
|
||||
"Architectures",
|
||||
self.arch.as_deref().unwrap_or_default().join(", ")
|
||||
self.dist.join(", ")
|
||||
]);
|
||||
table.add_row(row!["Languages", self.lang.join(", ")]);
|
||||
table.add_row(row!["Locations", self.location.join(", ")]);
|
||||
@@ -1270,7 +1270,7 @@ impl AuctionServerProduct {
|
||||
})
|
||||
.with_get("traffic", |p: &mut AuctionServerProduct| p.traffic.clone())
|
||||
.with_get("dist", |p: &mut AuctionServerProduct| p.dist.clone())
|
||||
.with_get("arch", |p: &mut AuctionServerProduct| p.arch.clone())
|
||||
.with_get("arch", |p: &mut AuctionServerProduct| p.dist.clone())
|
||||
.with_get("lang", |p: &mut AuctionServerProduct| p.lang.clone())
|
||||
.with_get("cpu", |p: &mut AuctionServerProduct| p.cpu.clone())
|
||||
.with_get("cpu_benchmark", |p: &mut AuctionServerProduct| {
|
||||
@@ -1328,7 +1328,7 @@ impl fmt::Display for AuctionServerProduct {
|
||||
table.add_row(row!["Distributions", self.dist.join(", ")]);
|
||||
table.add_row(row![
|
||||
"Architectures",
|
||||
self.arch.as_deref().unwrap_or_default().join(", ")
|
||||
self.dist.join(", ")
|
||||
]);
|
||||
table.add_row(row!["Languages", self.lang.join(", ")]);
|
||||
table.add_row(row!["CPU", self.cpu.clone()]);
|
||||
@@ -1486,7 +1486,7 @@ impl fmt::Display for AuctionTransaction {
|
||||
table.add_row(row!["Product Distributions", self.product.dist.clone()]);
|
||||
table.add_row(row![
|
||||
"Product Architectures",
|
||||
self.product.arch.as_deref().unwrap_or("N/A")
|
||||
&self.product.dist
|
||||
]);
|
||||
table.add_row(row!["Product Languages", self.product.lang.clone()]);
|
||||
table.add_row(row!["Product CPU", self.product.cpu.clone()]);
|
||||
@@ -1569,7 +1569,7 @@ impl AuctionTransactionProduct {
|
||||
})
|
||||
.with_get("dist", |p: &mut AuctionTransactionProduct| p.dist.clone())
|
||||
.with_get("arch", |p: &mut AuctionTransactionProduct| {
|
||||
p.arch.clone().unwrap_or_default()
|
||||
p.dist.clone()
|
||||
})
|
||||
.with_get("lang", |p: &mut AuctionTransactionProduct| p.lang.clone())
|
||||
.with_get("cpu", |p: &mut AuctionTransactionProduct| p.cpu.clone())
|
||||
|
@@ -100,7 +100,7 @@ pub fn pretty_print_auction_server_products(products: rhai::Array) {
|
||||
product.description.join(", "),
|
||||
product.traffic,
|
||||
product.dist.join(", "),
|
||||
product.arch.as_deref().unwrap_or_default().join(", "),
|
||||
product.dist.join(", "),
|
||||
product.lang.join(", "),
|
||||
product.cpu,
|
||||
product.cpu_benchmark,
|
||||
|
234
scripts/install.sh
Executable file
234
scripts/install.sh
Executable file
@@ -0,0 +1,234 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Herolib Rust Installation Script
|
||||
# This script installs the herolib_rust repository and its dependencies
|
||||
# Can be run locally or curled from remote
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
REPO_URL="https://git.ourworld.tf/herocode/herolib_rust"
|
||||
REPO_NAME="herolib_rust"
|
||||
MIN_RUST_VERSION="1.70.0"
|
||||
|
||||
# Set CODEROOT (default to ~/code unless already set)
|
||||
if [ -z "$CODEROOT" ]; then
|
||||
CODEROOT="$HOME/code"
|
||||
fi
|
||||
|
||||
TARGET_DIR="$CODEROOT/git.ourworld.tf/herocode/$REPO_NAME"
|
||||
|
||||
echo -e "${BLUE}===============================================${NC}"
|
||||
echo -e "${BLUE} Herolib Rust Installation Script${NC}"
|
||||
echo -e "${BLUE}===============================================${NC}"
|
||||
echo ""
|
||||
echo -e "${BLUE}Repository:${NC} $REPO_URL"
|
||||
echo -e "${BLUE}Target Directory:${NC} $TARGET_DIR"
|
||||
echo -e "${BLUE}CODEROOT:${NC} $CODEROOT"
|
||||
echo ""
|
||||
|
||||
# Function to check if command exists
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Function to compare version numbers
|
||||
version_ge() {
|
||||
printf '%s\n%s\n' "$2" "$1" | sort -V -C
|
||||
}
|
||||
|
||||
# Function to get Rust version
|
||||
get_rust_version() {
|
||||
if command_exists rustc; then
|
||||
rustc --version | cut -d' ' -f2
|
||||
else
|
||||
echo "0.0.0"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to install Rust
|
||||
install_rust() {
|
||||
echo -e "${YELLOW}📦 Installing Rust...${NC}"
|
||||
|
||||
if command_exists curl; then
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||
elif command_exists wget; then
|
||||
wget -qO- https://sh.rustup.rs | sh -s -- -y
|
||||
else
|
||||
echo -e "${RED}❌ Error: Neither curl nor wget is available. Please install one of them first.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Source the cargo environment
|
||||
source "$HOME/.cargo/env"
|
||||
|
||||
echo -e "${GREEN}✅ Rust installed successfully${NC}"
|
||||
}
|
||||
|
||||
# Function to update Rust
|
||||
update_rust() {
|
||||
echo -e "${YELLOW}📦 Updating Rust...${NC}"
|
||||
rustup update
|
||||
echo -e "${GREEN}✅ Rust updated successfully${NC}"
|
||||
}
|
||||
|
||||
# Check system requirements
|
||||
echo -e "${YELLOW}🔍 Checking system requirements...${NC}"
|
||||
|
||||
# Check for git
|
||||
if ! command_exists git; then
|
||||
echo -e "${RED}❌ Error: git is required but not installed${NC}"
|
||||
echo "Please install git first:"
|
||||
echo " macOS: brew install git"
|
||||
echo " Ubuntu/Debian: sudo apt-get install git"
|
||||
echo " CentOS/RHEL: sudo yum install git"
|
||||
exit 1
|
||||
fi
|
||||
echo -e "${GREEN}✅ git found${NC}"
|
||||
|
||||
# Check for curl or wget
|
||||
if ! command_exists curl && ! command_exists wget; then
|
||||
echo -e "${RED}❌ Error: Either curl or wget is required${NC}"
|
||||
echo "Please install one of them first:"
|
||||
echo " macOS: curl is usually pre-installed"
|
||||
echo " Ubuntu/Debian: sudo apt-get install curl"
|
||||
echo " CentOS/RHEL: sudo yum install curl"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if command_exists curl; then
|
||||
echo -e "${GREEN}✅ curl found${NC}"
|
||||
else
|
||||
echo -e "${GREEN}✅ wget found${NC}"
|
||||
fi
|
||||
|
||||
# Check Rust installation
|
||||
current_rust_version=$(get_rust_version)
|
||||
if [ "$current_rust_version" = "0.0.0" ]; then
|
||||
echo -e "${YELLOW}⚠️ Rust not found${NC}"
|
||||
install_rust
|
||||
elif ! version_ge "$current_rust_version" "$MIN_RUST_VERSION"; then
|
||||
echo -e "${YELLOW}⚠️ Rust version $current_rust_version is below minimum required $MIN_RUST_VERSION${NC}"
|
||||
update_rust
|
||||
else
|
||||
echo -e "${GREEN}✅ Rust $current_rust_version found (>= $MIN_RUST_VERSION required)${NC}"
|
||||
fi
|
||||
|
||||
# Check cargo
|
||||
if ! command_exists cargo; then
|
||||
echo -e "${RED}❌ Error: cargo not found after Rust installation${NC}"
|
||||
exit 1
|
||||
fi
|
||||
echo -e "${GREEN}✅ cargo found${NC}"
|
||||
|
||||
echo ""
|
||||
|
||||
# Clone or update repository
|
||||
hero git clone $REPO_URL
|
||||
REPO_PATH=$(hero git path $REPO_URL)
|
||||
cd "$REPO_PATH"
|
||||
|
||||
# Install dependencies and build
|
||||
echo -e "${YELLOW}🔧 Installing dependencies and building...${NC}"
|
||||
|
||||
# Check if we can build the workspace
|
||||
echo -e "${BLUE} 📋 Checking workspace...${NC}"
|
||||
if ! cargo check --workspace; then
|
||||
echo -e "${RED}❌ Error: Workspace check failed${NC}"
|
||||
exit 1
|
||||
fi
|
||||
echo -e "${GREEN}✅ Workspace check passed${NC}"
|
||||
|
||||
# Build the workspace
|
||||
echo -e "${BLUE} 🔨 Building workspace...${NC}"
|
||||
if ! cargo build --workspace; then
|
||||
echo -e "${RED}❌ Error: Build failed${NC}"
|
||||
exit 1
|
||||
fi
|
||||
echo -e "${GREEN}✅ Workspace built successfully${NC}"
|
||||
|
||||
# Build herodo binary
|
||||
echo -e "${BLUE} 🔨 Building herodo binary...${NC}"
|
||||
if [ -d "herodo" ]; then
|
||||
cd herodo
|
||||
if cargo build --release; then
|
||||
echo -e "${GREEN}✅ herodo binary built successfully${NC}"
|
||||
|
||||
# Install herodo binary
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
# Running as root, install to /usr/local/bin
|
||||
INSTALL_DIR="/usr/local/bin"
|
||||
else
|
||||
# Running as user, install to ~/hero/bin
|
||||
INSTALL_DIR="$HOME/hero/bin"
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
fi
|
||||
|
||||
cp ../target/release/herodo "$INSTALL_DIR/"
|
||||
chmod +x "$INSTALL_DIR/herodo"
|
||||
echo -e "${GREEN}✅ herodo installed to $INSTALL_DIR${NC}"
|
||||
|
||||
# Add to PATH if not already there
|
||||
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
|
||||
echo -e "${YELLOW}📝 Adding $INSTALL_DIR to PATH${NC}"
|
||||
echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >> "$HOME/.bashrc"
|
||||
echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >> "$HOME/.zshrc" 2>/dev/null || true
|
||||
echo -e "${BLUE} Note: Restart your shell or run 'source ~/.bashrc' to use herodo${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ herodo build failed, but continuing...${NC}"
|
||||
fi
|
||||
cd ..
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ herodo directory not found, skipping binary build${NC}"
|
||||
fi
|
||||
|
||||
# Run tests to verify installation
|
||||
echo -e "${YELLOW}🧪 Running tests to verify installation...${NC}"
|
||||
if cargo test --workspace --lib; then
|
||||
echo -e "${GREEN}✅ All tests passed${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Some tests failed, but installation completed${NC}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}===============================================${NC}"
|
||||
echo -e "${GREEN} Installation Complete!${NC}"
|
||||
echo -e "${GREEN}===============================================${NC}"
|
||||
echo ""
|
||||
echo -e "${GREEN}🎉 Herolib Rust has been successfully installed!${NC}"
|
||||
echo ""
|
||||
echo -e "${BLUE}Installation Details:${NC}"
|
||||
echo -e " Repository: $TARGET_DIR"
|
||||
echo -e " CODEROOT: $CODEROOT"
|
||||
echo -e " Rust Version: $(rustc --version | cut -d' ' -f2)"
|
||||
echo -e " Cargo Version: $(cargo --version | cut -d' ' -f2)"
|
||||
echo ""
|
||||
echo -e "${BLUE}Available Scripts:${NC}"
|
||||
echo -e " Build herodo: $TARGET_DIR/build_herodo.sh"
|
||||
echo -e " Run Rhai tests: $TARGET_DIR/run_rhai_tests.sh"
|
||||
echo -e " Publish crates: $TARGET_DIR/scripts/publish-all.sh"
|
||||
echo ""
|
||||
echo -e "${BLUE}Getting Started:${NC}"
|
||||
echo -e " cd $TARGET_DIR"
|
||||
echo -e " ./build_herodo.sh"
|
||||
echo -e " ./run_rhai_tests.sh"
|
||||
echo ""
|
||||
echo -e "${BLUE}Documentation:${NC}"
|
||||
echo -e " README: $TARGET_DIR/README.md"
|
||||
echo -e " Examples: $TARGET_DIR/examples/"
|
||||
echo ""
|
||||
|
||||
# Set environment variable for future use
|
||||
echo "export HEROLIB_RUST_PATH=\"$TARGET_DIR\"" >> "$HOME/.bashrc"
|
||||
echo "export HEROLIB_RUST_PATH=\"$TARGET_DIR\"" >> "$HOME/.zshrc" 2>/dev/null || true
|
||||
|
||||
echo -e "${GREEN}Happy coding! 🚀${NC}"
|
||||
echo ""
|
Reference in New Issue
Block a user