swiftide_integrations/groq/mod.rs
1//! This module provides integration with `Groq`'s API, enabling the use of language models within
2//! the Swiftide project. It includes the `Groq` struct for managing API clients and default options
3//! for prompt models. The module is conditionally compiled based on the "groq" feature flag.
4
5use crate::openai;
6
7use self::config::GroqConfig;
8
9mod config;
10
11/// The `Groq` struct encapsulates a `Groq` client that implements [`swiftide_core::SimplePrompt`]
12///
13/// There is also a builder available.
14///
15/// By default it will look for a `GROQ_API_KEY` environment variable. Note that a model
16/// always needs to be set, either with [`Groq::with_default_prompt_model`] or via the builder.
17/// You can find available models in the Groq documentation.
18///
19/// Under the hood it uses [`async_openai`], with the Groq openai mapping. This means
20/// some features might not work as expected. See the Groq documentation for details.
21pub type Groq = openai::GenericOpenAI<GroqConfig>;
22
23impl Groq {
24 pub fn builder() -> GroqBuilder {
25 GroqBuilder::default()
26 }
27}
28
29impl Groq {
30 #[deprecated(since = "0.21.2", note = "Use Groq::builder instead")]
31 pub fn with_default_prompt_model(&mut self, model: impl Into<String>) -> &mut Self {
32 self.default_options = openai::Options {
33 prompt_model: Some(model.into()),
34 ..self.default_options.clone()
35 };
36 self
37 }
38}
39
40impl Default for Groq {
41 fn default() -> Self {
42 Self::builder().build().unwrap()
43 }
44}
45
46pub type GroqBuilder = openai::GenericOpenAIBuilder<GroqConfig>;