Crates.io | copilot-rs |
lib.rs | copilot-rs |
version | 0.1.2 |
source | src |
created_at | 2024-11-15 09:21:40.709904 |
updated_at | 2024-11-16 04:09:48.411882 |
description | A Rust SDK for interacting with chat models, providing easy-to-use functions and tools. |
homepage | |
repository | https://github.com/ZhouXiaolin/copilot-rs.git |
max_upload_size | |
id | 1448928 |
size | 57,159 |
Copilot Rust SDK is a Rust library for interacting with the chat model. It provides integration with the chat API, support for custom function tools, and message handling.
ChatModel
structure.FunctionTool
and FunctiomImplTrait
.complete
macro.Add the following dependencies to your Cargo.toml
:
copilot-rs = "0.1.2"
To interact with the chat model, you need to create a ChatModel
instance with the necessary configuration.
normally, you can use the ChatModel::builder()
method to create a ChatModel
instance.
or you can use serde to deserialize a ChatModel
instance from a JSON string.
then use complete macro to inject paramaters and function tools into the chat function.
fn client() -> copilot_rs::ChatModel {
...
}
#[complete(client="client", temperature=0.6, max_tokens=1000, tools=["GetCurrentWeather","Add"])]
fn test(name: &str) -> String {
vec![format!("{}今天天气怎么样",name).user()].chat()
}
You can define your own function tool by implementing the FunctionTool
and FunctiomImplTrait
traits.
also, you need implement serde's Deserialize
and Serialize
traits. beacuse copilot-rs will use serde to deserialize the function tool from a JSON string.
#[derive(FunctionTool, Deserialize, Serialize)]
#[property(desc = "Get weather of an location, the user shoud supply a location first")]
struct GetCurrentWeather {
#[property(desc = "The city and state, e.g. San Francisco, CA")]
location: String,
}
impl FunctionImplTrait for GetCurrentWeather {
fn exec(&self) -> String {
"大暴雨,由于雨势太大,可能发生洪灾".to_string()
}
}
more detail, please see the example in the src/main.rs
file.
This project is still in the early stages of development. It is not yet ready for production use. if you have some issues with it, please feel free to open an issue or submit a pull request.