Skip to content

Commit bc4322c

Browse files
committed
update readme
1 parent ba59bed commit bc4322c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

async-openai/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ directory to learn more.
151151

152152
## Dynamic Dispatch for OpenAI-compatible Providers
153153

154+
This allows you to use same code (say a `fn`) to call APIs on different OpenAI-compatible providers.
155+
154156
For any struct that implements `Config` trait, wrap it in a smart pointer and cast the pointer to `dyn Config`
155157
trait object, then create a client with `Box` or `Arc` wrapped configuration.
156158

@@ -161,9 +163,14 @@ use async_openai::{Client, config::{Config, OpenAIConfig}};
161163

162164
// Use `Box` or `std::sync::Arc` to wrap the config
163165
let config = Box::new(OpenAIConfig::default()) as Box<dyn Config>;
166+
// create client
167+
let client: Client<Box<dyn Config>> = Client::with_config(config);
168+
164169
// A function can now accept a `&Client<Box<dyn Config>>` parameter
165170
// which can invoke any openai compatible api
166-
let client: Client<Box<dyn Config>> = Client::with_config(config);
171+
fn chat_completion(client: &Client<Box<dyn Config>>) {
172+
todo!()
173+
}
167174
```
168175

169176
## Contributing

0 commit comments

Comments
 (0)