File size: 1,331 Bytes
a45b607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
import os
from groq import Groq
#from dotenv import load_dotenv
#load_dotenv()
GROQ_API_KEY = "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"
client = Groq(api_key="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",)
#client = Groq(
#    api_key=os.environ.get('GROQ_API_KEY'),
#)


def fetch_models():
    exclude_models = ['distil-whisper-large-v3-en', 'whisper-large-v3','whisper-large-v3-turbo', "llama3-groq-8b-8192-tool-use-preview", "llama3-groq-70b-8192-tool-use-preview"]
    url = "https://api.groq.com/openai/v1/models"
    api_key = GROQ_API_KEY#os.environ.get('GROQ_API_KEY')
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    response = requests.get(url, headers=headers).json()['data']
    if len(response) != 0:
         return [model['id'] for model in response if model['id'] not in exclude_models]
    else:
        print("Error in fetching models!")
        return []
    
print("selected_model", "<===>","prompt")
def generate_content(selected_model, prompt):
    chat_completion = client.chat.completions.create(
                        messages=[{"role": "user", "content":prompt }],
                        model=selected_model,
                        )
    return chat_completion.choices[0].message.content