@@ -11,48 +11,87 @@ A Rust SDK for interacting with the Microsoft Foundry Local service. This SDK al
1111
1212## Usage
1313
14+ ### Prerequisites
15+
16+ To use this SDK, ensure you have the following prerequisites:
17+
18+ - Foundry Local must be installed and available on the PATH
19+ - Rust 1.70.0 or later
20+
21+ ### Create a new Rust project:
22+
23+ ``` bash
24+ cargo new hello-foundry-local
25+ cd hello-foundry-local
26+ ```
27+
28+ ### Install crates
29+
30+ Install the following Rust crates using Cargo:
31+
32+ ``` bash
33+ cargo add foundry-local anyhow env_logger serde_json
34+ cargo add reqwest --features json
35+ cargo add tokio --features full
36+ ```
37+
38+ Alternatively, you can add these dependencies manually to your ` Cargo.toml ` file.
39+
40+ ``` toml
41+ [dependencies ]
42+ anyhow = " 1.0.98"
43+ env_logger = " 0.11.8"
44+ foundry-local = " 0.1.0"
45+ reqwest = { version = " 0.12.19" , features = [" json" ] }
46+ serde_json = " 1.0.140"
47+ tokio = { version = " 1.45.1" , features = [" full" ] }
48+ ```
49+
50+ ### Update the ` main.rs ` file
51+
52+ Replace the contents of ` src/main.rs ` with the following code to create a simple application that interacts with the Foundry Local service:
53+
1454``` rust
1555use foundry_local :: FoundryLocalManager ;
1656use anyhow :: Result ;
1757
1858#[tokio:: main]
1959async fn main () -> Result <()> {
2060 // Create a FoundryLocalManager instance with default options
21- let manager = FoundryLocalManager :: new (" phi-3.5-mini" , true ). await ? ;
61+ let mut manager = FoundryLocalManager :: builder ()
62+ . alias_or_model_id (" phi-3.5-mini" ) // Specify the model to use
63+ . bootstrap (true ) // Start the service if not running
64+ . build ()
65+ . await ? ;
2266
2367 // Use the OpenAI compatible API to interact with the model
2468 let client = reqwest :: Client :: new ();
25- let response = client . post (& format! (" {}/chat/completions" , manager . endpoint ()))
69+ let endpoint = manager . endpoint ()? ;
70+ let response = client . post (& format! (" {}/chat/completions" , endpoint ))
2671 . header (" Content-Type" , " application/json" )
2772 . header (" Authorization" , format! (" Bearer {}" , manager . api_key ()))
2873 . json (& serde_json :: json! ({
29- " model" : manager . get_model_info (" phi-3.5-mini" ). await ? . id,
74+ " model" : manager . get_model_info (" phi-3.5-mini" , true ). await ? . id,
3075 " messages" : [{" role" : " user" , " content" : " What is the golden ratio?" }],
3176 }))
3277 . send ()
3378 . await ? ;
34-
79+
3580 let result = response . json :: <serde_json :: Value >(). await ? ;
3681 println! (" {}" , result [" choices" ][0 ][" message" ][" content" ]);
3782
3883 Ok (())
3984}
4085```
4186
42- ## Installation
87+ ### Run the application
4388
44- Add the following to your ` Cargo.toml ` :
89+ To run the application, execute the following command in your terminal :
4590
46- ``` toml
47- [dependencies ]
48- foundry-local = " 0.1.0"
91+ ``` bash
92+ cargo run
4993```
5094
51- ## Requirements
52-
53- - Foundry Local must be installed and available on the PATH
54- - Rust 1.70.0 or later
55-
5695## License
5796
5897Licensed under the MIT License.
0 commit comments