2个版本
0.1.1 | 2023年8月29日 |
---|---|
0.1.0 | 2023年8月29日 |
#53 in #universal
用于 kagi-cli
29KB
444 行
kagi-api
用Rust编写的Kagi API库和CLI
使用kagi-api库
在库进入crates.io之前,您可以添加以下git依赖项
[dependencies]
kagi-api = { version = "0.1", git = "https://codeberg.org/synapse/kagi-api.git" }
use kagi_api::v0::FastGPT;
#[tokio::main]
async fn main() {
let config = kagi_api::KagiConfig::with_api_key("api key goes here");
let client = kagi_api::KagiClient::new(config);
let use_cache = true;
let answer = client
.fastgpt("How do I entertain my cat?", use_cache)
.await
.expect("A valid FastGPT search result");
// FIXME: Cannot `.render()` without kagi-cli: Remove `Render` trait's coupling from `Args`.
serde_json::to_writer_pretty(std::io::stdout(), &answer).unwrap();
}
请参阅kagi-api/examples
目录以获取更多示例。
FIXME:示例仍然不稳定,稳定后再将更多示例迁移到这里。
使用kagi-cli二进制文件
通过克隆此存储库、进入它并运行来安装
cargo install --path kagi-cli
安装自动完成,可能需要将zsh
替换为bash
、fish
、powershell
或elvish
source <(kagi-cli completion zsh)
设置包含您的API密钥的环境变量。
设置logdir是可选的,并启用记录和回放。
KAGI_API_KEY="api key goes here"
KAGI_API_LOGDIR="."
您现在可以查询
$ kagi-cli fast-gpt 'How do I entertain my cat?'
There are several ways to **entertain your cat**: **Provide toys for playing**, such as balls, feathers on strings or catnip toys. **Interactive play sessions** can also stimulate cats. [1][2] **Hide treats and food around the house in puzzle feeders** or new locations. This provides mental enrichment. [1][3][4] **Inexpensive items like cardboard boxes** or empty paper towel rolls can be entertaining for cats to bat around or hide in. [1][5][2] **Cats may enjoy watching fish tanks or nature documentaries on TV.** [6][7] - 1. Puzzle feeders 2. Hide the food in new locations 3. Put food in a kitty KONG 4. Put kibble or treats inside an egg carton 5. Teach your cat some tricks 6. Searching for food scent Games 7. Make a labyrinth out of boxes [1] - Toys that keep your indoor cat entertained. How to entertain indoor cats: Providing a wide variety of cat toys will ensure your feline is never bored. (Image credit: Getty) Most vets recommend a minimum of 15-30 minutes of play per day, which is for both exercise and bonding. [2] - 4. jan. 2021 ... 6 Ways to Keep Your Cat Entertained · 1. Add a Furry Friend. Cats are social creatures, and the majority enjoy having a companion. · 2. Prepare a... [3] - If your feline friend is food motivated, then treat based puzzles can be a fun, low maintenance way of keeping your cat entertained (and fed). [4] - To keep a bored indoor cat entertained while you're not at home, open up some of your blinds and curtains so your cat can look out the window. You can also try leaving your TV on with a nature show playing to give your cat something to watch. [5] - 3. jul. 2023 ... You don't need to fork out for expensive toys though, a simple cardboard box can keep a moggie thoroughly entertained. They also like to play... [6] - Many cats love catnip, so you can buy catnip-filled toys or give your cat loose catnip to make play time extra fun. Multi-tiered cat trees, which you can build yourself or buy at pet stores, can give your kitty something fun to romp around on when you're not home. [7] [1]: https://www.meowsnpaws.com/cat-entertainment/how-to-entertain-cat/ [2]: https://www.petsradar.com/advice/how-to-entertain-indoor-cats-and-keep-them-stimulated [3]: https://rufusandcoco.com.au/blogs/blog/6-ways-to-keep-your-cat-entertained [4]: https://www.petsecure.com.au/pet-care/10-ways-keep-cat-entertained-youre-house/ [5]: https://www.wikihow.com/Keep-a-Bored-Indoor-Cat-Entertained-While-You%27re-Not-at-Home [6]: https://www.petsradar.com/advice/is-your-cat-bored-10-tips-to-entertain-your-moggy [7]: https://www.wikihow.com/Have-Fun-with-Your-Cat
回放相同的请求-响应,但更改输出格式
$ kagi-cli --replay -f json fast-gpt 'How do I entertain my cat?'
{ "meta": { "id": "64872161-cae7-4ee0-a7b7-096f821bae75", "node": "europe-west4", "ms": 7512, "api_balance": 0.0 }, "data": { "output": "\nThere are several ways to **entertain your cat**:\n\n**Provide toys for playing**, such as balls, feathers on strings or catnip toys. **Interactive play sessions** can also stimulate cats. [1][2]\n\n**Hide treats and food around the house in puzzle feeders** or new locations. This provides mental enrichment. [1][3][4] \n\n**Inexpensive items like cardboard boxes** or empty paper towel rolls can be entertaining for cats to bat around or hide in. [1][5][2]\n\n**Cats may enjoy watching fish tanks or nature documentaries on TV.** [6][7]", "tokens": 5921, "references": [ { "title": "50 Ways to Entertain Your Cat (+ Free PDF Printable)", "snippet": "1. Puzzle feeders 2. Hide the food in new locations 3. Put food in a kitty KONG 4. Put kibble or treats inside an egg carton 5. Teach your cat some tricks 6. Searching for food scent Games 7. Make a labyrinth out of boxes", "url": "https://www.meowsnpaws.com/cat-entertainment/how-to-entertain-cat/" }, { "title": "How to entertain indoor cats | PetsRadar", "snippet": "Toys that keep your indoor cat entertained. How to entertain indoor cats: Providing a wide variety of cat toys will ensure your feline is never bored. (Image credit: Getty) Most vets recommend a minimum of 15-30 minutes of play per day, which is for both exercise and bonding.", "url": "https://www.petsradar.com/advice/how-to-entertain-indoor-cats-and-keep-them-stimulated" }, { "title": "6 Ways to Keep Your Cat Entertained – Rufus & Coco Australia", "snippet": "4. jan. 2021 ... 6 Ways to Keep Your Cat Entertained · 1. Add a Furry Friend. Cats are social creatures, and the majority enjoy having a companion. · 2. Prepare a...", "url": "https://rufusandcoco.com.au/blogs/blog/6-ways-to-keep-your-cat-entertained" }, { "title": "10 Ways to Keep Your Cat Entertained While You're Out of the House", "snippet": "If your feline friend is food motivated, then treat based puzzles can be a fun, low maintenance way of keeping your cat entertained (and fed).", "url": "https://www.petsecure.com.au/pet-care/10-ways-keep-cat-entertained-youre-house/" }, { "title": "3 Ways to Keep a Bored Indoor Cat Entertained While You're ... - wikiHow", "snippet": "To keep a bored indoor cat entertained while you're not at home, open up some of your blinds and curtains so your cat can look out the window. You can also try leaving your TV on with a nature show playing to give your cat something to watch.", "url": "https://www.wikihow.com/Keep-a-Bored-Indoor-Cat-Entertained-While-You%27re-Not-at-Home" }, { "title": "Is your cat bored? | PetsRadar", "snippet": "3. jul. 2023 ... You don't need to fork out for expensive toys though, a simple cardboard box can keep a moggie thoroughly entertained. They also like to play...", "url": "https://www.petsradar.com/advice/is-your-cat-bored-10-tips-to-entertain-your-moggy" }, { "title": "How to Have Fun with Your Cat (with Pictures) - wikiHow", "snippet": "Many cats love catnip, so you can buy catnip-filled toys or give your cat loose catnip to make play time extra fun. Multi-tiered cat trees, which you can build yourself or buy at pet stores, can give your kitty something fun to romp around on when you're not home.", "url": "https://www.wikihow.com/Have-Fun-with-Your-Cat" } ] } }
FIXME:当存储库位于crates.io时,改进cargo install kagi-cli
安装说明。
FIXME:提供示例作为Rustdoc并编程导出它们(一个源,可测试)。
贡献
要贡献,安装Rust工具链,例如使用rustup
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
叉库包含库和CLI代码的工作空间
git clone https://codeberg.org/synapse/kagi-api.git
依赖关系
~9–25MB
~346K SLoC