| import os |
| import json |
| import itertools |
| from groq import Groq |
| from dotenv import load_dotenv |
| from pymongo import MongoClient |
| import random |
| import certifi |
| load_dotenv() |
|
|
|
|
| def get_random(): |
| lst = ["R1","R2","R3","S1","RD1"] |
| i = random.randint(0,4) |
| return lst[i] |
|
|
| some = get_random() |
| GROQ_API_KEY = os.getenv(f"GROQ_API_KEY{some}") |
|
|
|
|
|
|
| def get_mongo_collection(): |
| CONNECTION_STRING = os.getenv("CONNECTION_STRING") |
| DB_NAME = os.getenv("DB_NAME") |
| COLLECTION_NAME = os.getenv("COLLECTION_NAME") |
| try: |
| |
| client = MongoClient(CONNECTION_STRING, tlsCAFile=certifi.where()) |
| db = client[DB_NAME] |
| return db[COLLECTION_NAME] |
| except Exception as e: |
| print(f"Error connecting to Mongo: {e}") |
| return None |
| |
| def groq_calls(prompt): |
| client = Groq(api_key=GROQ_API_KEY) |
|
|
| groq_card = client.chat.completions.create( |
| |
| messages=[ |
| { |
| "role": "user", |
| "content": f"{prompt}", |
| }, |
| { |
| "role":"system", |
| "content":"You are a psychologist. Output JSON" |
| } |
| ], |
| model="openai/gpt-oss-20b", |
| response_format={"type": "json_object"} |
| ) |
|
|
| |
| return groq_card.choices[0].message.content |