Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

Tool calls last changes (#670)

Aleksandr Golokoz5ca7d2f26bfd
diff --git a/bindings/python/uzu/__init__.pyi b/bindings/python/uzu/__init__.pyi
index ca788b061..474cded19 100644
--- a/bindings/python/uzu/__init__.pyi
+++ b/bindings/python/uzu/__init__.pyi
@@ -423,6 +423,7 @@ class ChatSession:
def add_tools(self, tools: collections.abc.Sequence[UzuToolFunction[..., typing.Any]]) -> collections.abc.Awaitable[None]: ...
def state(self) -> collections.abc.Awaitable[ChatSessionState]: ...
def messages(self) -> collections.abc.Awaitable[builtins.list[ChatMessage]]: ...
+ def supports_tool_calls(self) -> collections.abc.Awaitable[builtins.bool]: ...
def reset(self) -> collections.abc.Awaitable[None]: ...
def reply(self, input: typing.Sequence[ChatMessage], config: ChatReplyConfig) -> collections.abc.Awaitable[builtins.list[ChatReply]]: ...
def reply_with_stream(self, input: typing.Sequence[ChatMessage], config: ChatReplyConfig) -> collections.abc.Awaitable[ChatSessionStream]: ...
diff --git a/bindings/swift/Sources/Uzu/Generated/uzu/nagare.swift b/bindings/swift/Sources/Uzu/Generated/uzu/nagare.swift
index 0320c5447..6e38ac40a 100644
--- a/bindings/swift/Sources/Uzu/Generated/uzu/nagare.swift
+++ b/bindings/swift/Sources/Uzu/Generated/uzu/nagare.swift
@@ -438,6 +438,30 @@ fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
}
}
+#if swift(>=5.8)
+@_documentation(visibility: private)
+#endif
+fileprivate struct FfiConverterBool : FfiConverter {
+ typealias FfiType = Int8
+ typealias SwiftType = Bool
+
+ public static func lift(_ value: Int8) throws -> Bool {
+ return value != 0
+ }
+
+ public static func lower(_ value: Bool) -> Int8 {
+ return value ? 1 : 0
+ }
+
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
+ return try lift(readInt(&buf))
+ }
+
+ public static func write(_ value: Bool, into buf: inout [UInt8]) {
+ writeInt(&buf, lower(value))
+ }
+}
+
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
@@ -498,6 +522,8 @@ public protocol ChatSessionProtocol: AnyObject, Sendable {
func state() async -> ChatSessionState
+ func supportsToolCalls() async -> Bool
+
}
open class ChatSession: ChatSessionProtocol, @unchecked Sendable {
fileprivate let handle: UInt64
@@ -674,6 +700,24 @@ open func state()async -> ChatSessionState {
)
}
+open func supportsToolCalls()async -> Bool {
+ return
+ try! await uniffiRustCallAsync(
+ rustFutureFunc: {
+ uniffi_nagare_fn_method_chatsession_supports_tool_calls(
+ self.uniffiCloneHandle()
+
+ )
+ },
+ pollFunc: ffi_nagare_rust_future_poll_i8,
+ completeFunc: ffi_nagare_rust_future_complete_i8,
+ freeFunc: ffi_nagare_rust_future_free_i8,
+ liftFunc: FfiConverterBool.lift,
+ errorHandler: nil
+
+ )
+}
+
}
@@ -2614,6 +2658,9 @@ private let initializationResult: InitializationResult = {
if (uniffi_nagare_checksum_method_chatsession_state() != 61854) {
return InitializationResult.apiChecksumMismatch
}
+ if (uniffi_nagare_checksum_method_chatsession_supports_tool_calls() != 55549) {
+ return InitializationResult.apiChecksumMismatch
+ }
if (uniffi_nagare_checksum_method_chatsessionstream_cancel_token() != 18598) {
return InitializationResult.apiChecksumMismatch
}
diff --git a/bindings/typescript/src/napi/index.d.mts b/bindings/typescript/src/napi/index.d.mts
index a81b20e34..92c454e14 100644
--- a/bindings/typescript/src/napi/index.d.mts
+++ b/bindings/typescript/src/napi/index.d.mts
@@ -5,6 +5,7 @@ export declare class ChatSession {
addTools(tools: Array<NativeTool>): Promise<undefined>
get state(): Promise<ChatSessionState>
get messages(): Promise<Array<ChatMessage>>
+ get supportsToolCalls(): Promise<boolean>
reset(): Promise<void>
reply(input: Array<ChatMessage>, config: ChatReplyConfig): Promise<Array<ChatReply>>
replyWithStream(input: Array<ChatMessage>, config: ChatReplyConfig): Promise<ChatSessionStream>
diff --git a/bindings/typescript/src/napi/index.d.ts b/bindings/typescript/src/napi/index.d.ts
index a81b20e34..92c454e14 100644
--- a/bindings/typescript/src/napi/index.d.ts
+++ b/bindings/typescript/src/napi/index.d.ts
@@ -5,6 +5,7 @@ export declare class ChatSession {
addTools(tools: Array<NativeTool>): Promise<undefined>
get state(): Promise<ChatSessionState>
get messages(): Promise<Array<ChatMessage>>
+ get supportsToolCalls(): Promise<boolean>
reset(): Promise<void>
reply(input: Array<ChatMessage>, config: ChatReplyConfig): Promise<Array<ChatReply>>
replyWithStream(input: Array<ChatMessage>, config: ChatReplyConfig): Promise<ChatSessionStream>
diff --git a/crates/nagare/src/chat/mod.rs b/crates/nagare/src/chat/mod.rs
index 7d0c6e878..c58761699 100644
--- a/crates/nagare/src/chat/mod.rs
+++ b/crates/nagare/src/chat/mod.rs
@@ -539,6 +539,11 @@ impl ChatSession {
self.messages.lock().await.clone()
}
+ #[bindings::export(Method(Getter))]
+ pub async fn supports_tool_calls(&self) -> bool {
+ self.tool_registry.is_some()
+ }
+
#[bindings::export(Method)]
pub async fn reset(&self) -> Result<(), ChatSessionError> {
{
diff --git a/crates/uzu/Cargo.toml b/crates/uzu/Cargo.toml
index 1d8d4a96f..465dda032 100644
--- a/crates/uzu/Cargo.toml
+++ b/crates/uzu/Cargo.toml
@@ -105,6 +105,7 @@ async-openai.workspace = true
fancy-regex.workspace = true
confy.workspace = true
keyring-core.workspace = true
+chrono.workspace = true
[target.'cfg(target_vendor = "apple")'.dependencies]
objc2.workspace = true
@@ -123,7 +124,6 @@ apple-native-keyring-store = { workspace = true, features = ["protected"] }
[dev-dependencies]
tracing-subscriber.workspace = true
tracing-appender.workspace = true
-chrono.workspace = true
tempfile.workspace = true
indicatif.workspace = true
dotenvy.workspace = true
diff --git a/crates/uzu/src/cli/sessions/chat.rs b/crates/uzu/src/cli/sessions/chat.rs
index d1ed11b74..b1b482a9f 100644
--- a/crates/uzu/src/cli/sessions/chat.rs
+++ b/crates/uzu/src/cli/sessions/chat.rs
@@ -1,7 +1,11 @@
use std::any::Any;
+use chrono::Local;
use iocraft::prelude::*;
-use nagare::chat::{ChatSession, ChatSessionStreamChunk};
+use nagare::{
+ chat::{ChatSession, ChatSessionStreamChunk},
+ tool::uzu_tool_function,
+};
use shoji::types::{
basic::CancelToken,
model::Model,
@@ -106,7 +110,15 @@ pub async fn ensure_session(
}
let engine = state.read().engine.clone();
- let session = match engine.chat(model.clone(), ChatConfig::default()).await {
+ let session = match async {
+ let mut session = engine.chat(model.clone(), ChatConfig::default()).await?;
+ if session.supports_tool_calls().await {
+ session.add_tool(get_current_date_time).await?;
+ }
+ Ok::<_, anyhow::Error>(session)
+ }
+ .await
+ {
Ok(session) => session,
Err(error) => {
let mut state = state.write();
@@ -222,3 +234,9 @@ fn chat_state_mut(state: &mut ApplicationState) -> Option<&mut ChatSessionState>
.and_then(|model_state| model_state.session_state.as_deref_mut())
.and_then(|session_state| session_state.as_any_mut().downcast_mut::<ChatSessionState>())
}
+
+/// Returns current date and time in RFC 3339 format: YYYY-MM-DDTHH:MM:SSZ
+#[uzu_tool_function]
+fn get_current_date_time() -> String {
+ Local::now().to_rfc3339()
+}
diff --git a/crates/uzu/tests/tool/calls.rs b/crates/uzu/tests/tool/calls.rs
index b33a94481..652435582 100644
--- a/crates/uzu/tests/tool/calls.rs
+++ b/crates/uzu/tests/tool/calls.rs
@@ -193,7 +193,6 @@ async fn run_tool_calls_test(
}
}
-#[ignore]
#[tokio::test]
async fn functiongemma_270m_it() {
// FunctionGemma 270M only handles single-step tool calls out of the box:
@@ -203,25 +202,21 @@ async fn functiongemma_270m_it() {
run_tool_calls_test("google/functiongemma-270m-it", false, true, &TEST_CASES[..1]).await;
}
-#[ignore]
#[tokio::test]
async fn gpt_oss_20b() {
run_tool_calls_test("openai/gpt-oss-20b", true, false, TEST_CASES).await;
}
-#[ignore]
#[tokio::test]
async fn lfm2_350m() {
run_tool_calls_test("LiquidAI/LFM2-350M", true, false, &TEST_CASES[..1]).await;
}
-#[ignore]
#[tokio::test]
async fn lfm2_5_350m() {
run_tool_calls_test("LiquidAI/LFM2.5-350M", true, false, &TEST_CASES[..1]).await;
}
-#[ignore]
#[tokio::test]
async fn llama_3_2_1b_instruct() {
// Like FunctionGemma, Llama 3.2 1B only handles single-step tool calls: for the prompts that
@@ -230,13 +225,11 @@ async fn llama_3_2_1b_instruct() {
run_tool_calls_test("meta-llama/Llama-3.2-1B-Instruct", true, false, &TEST_CASES[..1]).await;
}
-#[ignore]
#[tokio::test]
async fn qwen3_1_7b() {
run_tool_calls_test("Qwen/Qwen3-1.7B", true, false, TEST_CASES).await;
}
-#[ignore]
#[tokio::test]
async fn qwen3_5_0_8b() {
run_tool_calls_test("Qwen/Qwen3.5-0.8B", true, false, TEST_CASES).await;