> ## Documentation Index
> Fetch the complete documentation index at: https://docs.honeyhive.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Groq

> Learn how to integrate Groq with HoneyHive

export const integrationType_1 = "Groq"

export const integrationType_0 = "Groq"

Groq delivers fast inference through its custom-designed ASIC chip and optimized software that leverages parallel processing, model pruning, and quantization to reduce inference times and increase throughput. Its software also uses just-in-time compilation, low-level optimization, and memory optimization to minimize latency and maximize performance.

With HoneyHive, you can trace all your {integrationType_0} operations using a single line of code. Find a list of all supported integrations [here](/introduction/troubleshooting#latest-package-versions-tested).

## HoneyHive Setup

Follow the [HoneyHive Installation Guide](/integrations/integration-prereqs) to get your API key and initialize the tracer.

## Groq Setup

Go to the [Groq Cloud Console](https://console.groq.com/keys) to get your Groq API key.

## Example

Here is an example of how to trace your {integrationType_1} code in HoneyHive.

<CodeGroup>
  ```python Python theme={null}
  from groq import Groq
  import json

  from honeyhive import HoneyHiveTracer, trace

  HoneyHiveTracer.init(
      api_key="MY_HONEYHIVE_API_KEY",
      project="MY_HONEYHIVE_PROJECT_NAME",
  )

  client = Groq(
      api_key="MY_GROQ_API_KEY",
  )

  def evaluate_post(post: str) -> dict:
      evaluation_prompt = f"""
      Evaluate the following blog post based on these criteria (rate each from 1-5):
      1. Engagement: How well does it capture and maintain reader interest?
      2. Clarity: How clear and well-structured is the content?
      3. Value: How informative and valuable is the content?
      
      Blog post:
      {post}
      
      Respond in this exact JSON format:
      {{
          "engagement": <score>,
          "clarity": <score>,
          "value": <score>,
          "total": <sum of scores>
      }}
      """
      
      response = client.chat.completions.create(
          messages=[{"role": "user", "content": evaluation_prompt}],
          model="llama3-8b-8192",
          response_format={"type": "json_object"}
      )
      
      # Parse the response as a dictionary
      return json.loads(response.choices[0].message.content)

  @trace
  def generate_blog_post(topic: str) -> dict:
      prompt = f"Write a compelling blog post about {topic}. Make it engaging and informative."
      
      response = client.chat.completions.create(
          messages=[{"role": "user", "content": prompt}],
          model="llama3-8b-8192",
      )
      # Evaluate the generated post right away
      post = response.choices[0].message.content
      evaluation = evaluate_post(post)
      return {
          "content": post,
          "evaluation": evaluation
      }

  def main():
      # Topics for blog posts
      topics = [
          "The Future of AI in Healthcare",
          "Sustainable Living in 2024",
          "Digital Privacy in the Modern Age",
          "The Rise of Remote Work",
          "Mindfulness and Technology Balance"
      ]
      
      # Generate blog posts
      print("Generating blog posts...")
      posts = [generate_blog_post(topic) for topic in topics]
      
      # Find the highest-rated post
      best_post_index = max(range(len(posts)), key=lambda i: posts[i]['evaluation']['total'])
      
      print("\nEvaluation Results:")
      for i, post in enumerate(posts):
          print(f"\nPost {i+1}: {topics[i]}")
          print(f"Engagement: {post['evaluation']['engagement']}")
          print(f"Clarity: {post['evaluation']['clarity']}")
          print(f"Value: {post['evaluation']['value']}")
          print(f"Total Score: {post['evaluation']['total']}")
      
      print("\n=== Best Rated Blog Post ===")
      print(f"Topic: {topics[best_post_index]}")
      print(posts[best_post_index]['content'])
      print(posts[best_post_index]['evaluation'])

  main()
  ```

  ```typescript TypeScript theme={null}

  import { HoneyHiveTracer } from 'honeyhive';
  import Groq from "groq-sdk";

  const tracer = await HoneyHiveTracer.init({
      apiKey: "MY_HONEYHIVE_API_KEY",
      project: "MY_HONEYHIVE_PROJECT_NAME",
      sessionName: 'test',
  });

  const groq = new Groq({ apiKey: "MY_GROQ_API_KEY" });

  interface BlogEvaluation {
      engagement: number;
      clarity: number;
      value: number;
      total: number;
  }

  interface BlogPost {
      content: string;
      evaluation: BlogEvaluation;
  }

  async function evaluateBlogPost(post: string): Promise<BlogEvaluation> {
      const evaluationPrompt = `
          Evaluate the following blog post based on these criteria (rate each from 1-5):
          1. Engagement: How well does it capture and maintain reader interest?
          2. Clarity: How clear and well-structured is the content?
          3. Value: How informative and valuable is the content?
          
          Blog post:
          ${post}
          
          Respond in this exact JSON format:
          {
              "engagement": <score>,
              "clarity": <score>,
              "value": <score>,
              "total": <sum of scores>
          }
      `;

      const response = await groq.chat.completions.create({
          messages: [{ role: "user", content: evaluationPrompt }],
          model: "llama3-8b-8192",
          response_format: { type: "json_object" }
      });

      return JSON.parse(response.choices[0].message.content);
  }

  async function generateBlogPost(topic: string): Promise<BlogPost> {
      const prompt = `Write a compelling blog post about ${topic}. Make it engaging and informative.`;
      
      const response = await groq.chat.completions.create({
          messages: [{ role: "user", content: prompt }],
          model: "llama3-8b-8192"
      });

      const post = response.choices[0].message.content;
      const evaluation = await evaluateBlogPost(post);

      return {
          content: post,
          evaluation: evaluation
      };
  }

  const tracedGenerateBlogPost = tracer.traceFunction()(generateBlogPost);

  async function main(): Promise<void> {
      // Topics for blog posts
      const topics: string[] = [
          "The Future of AI in Healthcare",
          "Sustainable Living in 2024",
          "Digital Privacy in the Modern Age",
          "The Rise of Remote Work",
          "Mindfulness and Technology Balance"
      ];
      
      // Generate blog posts
      console.log("Generating blog posts...");
      const posts: BlogPost[] = await Promise.all(topics.map(async (topic) => {
          const blogPost = `Write a compelling blog post about ${topic}.`;
          return await tracedGenerateBlogPost(blogPost);
      }));

      // Find the highest-rated post
      const bestPostIndex = posts.findIndex(post => 
          post.evaluation.total === Math.max(...posts.map(p => p.evaluation.total))
      );

      console.log("\nEvaluation Results:");
      posts.forEach((post, index) => {
          console.log(`\nPost ${index + 1}: ${topics[index]}`);
          console.log(`Engagement: ${post.evaluation.engagement}`);
          console.log(`Clarity: ${post.evaluation.clarity}`);
          console.log(`Value: ${post.evaluation.value}`);
          console.log(`Total Score: ${post.evaluation.total}`);
      });

      console.log("\n=== Best Rated Blog Post ===");
      console.log(`Topic: ${topics[bestPostIndex]}`);
      console.log(posts[bestPostIndex].content);
      console.log(posts[bestPostIndex].evaluation);
  }

  await main();
  ```
</CodeGroup>

## View your Traces

Once you run your code, you can view your execution trace in the HoneyHive UI by clicking the `Log Store` tab on the left sidebar.
