Giter VIP home page Giter VIP logo

rusty-groq's Introduction

Groq Rust Library

A Rust library for interacting with the Groq API. This library provides a convenient Rust interface for using the LLM model from the Groq API. The model is configurable and not limited to mixtral-8x7B.

Note that the majority of this codebase is provided by Groq and Mistral with a little human intervention.

Usage

To use the library in your project, add the following to your Cargo.toml:

[dependencies]
rusty-groq = "0.1.0"

Then, in your code:

use groq::{GroqClient, GroqError};

#[tokio::main]
async fn main() -> Result<(), GroqError> {
    let base_url = "https://api.groq.com/openai/v1".to_string();
    let api_key = std::env::var("GROQ_API_KEY").expect("GROQ_API_KEY must be set");
    let groq_client = GroqClient::new(base_url, api_key);

    let message = "Explain the importance of low latency LLMs";
    let model = "mixtral-8x7b-32768"; // replace with your desired model

    let response = groq_client.send_request(message, model).await?;

    println!("Response: {}", response);

    Ok(())
}

Note that you need to set the GROQ_API_KEY environment variable to your Groq API key.

Developing

To run the library's tests, use cargo test.

To run the library's benchmarks, use cargo bench.

License

Licensed under the MIT license.

Contribution

Alright, here's the plan: we're putting Groq in charge, and it's going to create everything for Groq under the MIT license. That means contributors can use and adapt the work freely. It's like inventing a boomerang that throws itself โ€“ sounds crazy, but it's going to be epic! We'll kick back, enjoy the show, and ponder life's mysteries, like why a bathroom's called "the loo" when there's no loo in sight. Our goal: 100% Groq-made, and contributors should use the MIT license. Let's do this!

rusty-groq's People

Contributors

s4idev avatar

Stargazers

Augustinas K avatar Yihao Wang avatar Qyrx avatar

Watchers

 avatar

rusty-groq's Issues

GroqResponse structs

Groq respones aren't actually the llm responses. You still need to define the rust types to extract the content of the llm response. Might as welll include these types in the lib itself for user convenience.

#[derive(Debug, Deserialize)]
struct GroqMessage {
    role: String,
    content: String,
}

#[derive(Debug, Deserialize)]
struct GroqChoice {
    message: GroqMessage,
}

#[derive(Debug, Deserialize)]
struct GroqResponse {
    choices: Vec<GroqChoice>,
}

impl GroqResponse {
    pub fn content(&self) -> Result<String, LlmError> {
        Ok(self
            .choices
            .get(0)
            .ok_or_else(|| LlmError::GroqError("Groq answered without choices".to_string()))?
            .message
            .content
            .clone())
    }
}

ClientBuilder for GroqClient

What's the point for an end user to have the option to change the groq api url anyways?

Ergonomics could be slightly improved it if was the default under the builder pattern.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.