feat: enhance argument parsing and add API key generation
The changes improve the robustness of command-line argument parsing in the Llama model server by replacing direct index access with safe iteration methods. A new generate_api_key function was added to handle API key generation securely. The sessionId parameter was standardized to match the renamed property in the client code.
This commit is contained in:
parent
6679debf72
commit
5d61062b0e
@ -491,7 +491,7 @@ export default class llamacpp_extension extends AIEngine {
|
|||||||
try {
|
try {
|
||||||
// Pass the PID as the session_id
|
// Pass the PID as the session_id
|
||||||
const result = await invoke<unloadResult>('unload_llama_model', {
|
const result = await invoke<unloadResult>('unload_llama_model', {
|
||||||
session_id: sessionId, // Using PID as session ID
|
sessionId, // Using PID as session ID
|
||||||
})
|
})
|
||||||
|
|
||||||
// If successful, remove from active sessions
|
// If successful, remove from active sessions
|
||||||
|
|||||||
@ -84,13 +84,29 @@ pub async fn load_llama_model(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let port = 8080; // Default port
|
let port = 8080; // Default port
|
||||||
|
let modelPath = args
|
||||||
|
.iter()
|
||||||
|
.position(|arg| arg == "-m")
|
||||||
|
.and_then(|i| args.get(i + 1))
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let apiKey = args
|
||||||
|
.iter()
|
||||||
|
.position(|arg| arg == "--api-key")
|
||||||
|
.and_then(|i| args.get(i + 1))
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let modelId = args
|
||||||
|
.iter()
|
||||||
|
.position(|arg| arg == "-a")
|
||||||
|
.and_then(|i| args.get(i + 1))
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
// Configure the command to run the server
|
// Configure the command to run the server
|
||||||
let mut command = Command::new(backend_path);
|
let mut command = Command::new(backend_path);
|
||||||
|
|
||||||
let modelPath = args[2].replace("-m", "");
|
|
||||||
let apiKey = args[1].replace("--api-key", "");
|
|
||||||
let modelId = args[3].replace("-a", "");
|
|
||||||
command.args(args);
|
command.args(args);
|
||||||
|
|
||||||
// Optional: Redirect stdio if needed (e.g., for logging within Jan)
|
// Optional: Redirect stdio if needed (e.g., for logging within Jan)
|
||||||
@ -192,7 +208,6 @@ pub async fn unload_llama_model(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// crypto
|
// crypto
|
||||||
#[allow(clippy::camel_case_variables)]
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn generate_api_key(modelId: String, apiSecret: String) -> Result<String, String> {
|
pub fn generate_api_key(modelId: String, apiSecret: String) -> Result<String, String> {
|
||||||
let mut mac = HmacSha256::new_from_slice(apiSecret.as_bytes())
|
let mut mac = HmacSha256::new_from_slice(apiSecret.as_bytes())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user