(logger)
| 122 | |
| 123 | |
| 124 | def fetch_groq_models(logger): |
| 125 | logger.info("Fetching Groq models...") |
| 126 | r = requests.get( |
| 127 | "https://api.groq.com/openai/v1/models", |
| 128 | headers={ |
| 129 | "Authorization": f'Bearer {os.environ["GROQ_API_KEY"]}', |
| 130 | "Content-Type": "application/json", |
| 131 | }, |
| 132 | ) |
| 133 | r.raise_for_status() |
| 134 | models = r.json()["data"] |
| 135 | logger.debug(json.dumps(models, indent=4)) |
| 136 | ret_models = [] |
| 137 | with ThreadPoolExecutor() as executor: |
| 138 | futures = [] |
| 139 | for model in models: |
| 140 | future = executor.submit( |
| 141 | get_groq_limits_for_model, model["id"], script_dir, logger |
| 142 | ) |
| 143 | futures.append((model, future)) |
| 144 | |
| 145 | for model, future in futures: |
| 146 | limits = future.result() |
| 147 | if limits is None: |
| 148 | continue |
| 149 | ret_models.append( |
| 150 | { |
| 151 | "id": model["id"], |
| 152 | "name": get_model_name(model["id"]), |
| 153 | "limits": limits, |
| 154 | } |
| 155 | ) |
| 156 | ret_models = sorted(ret_models, key=lambda x: x["name"]) |
| 157 | return ret_models |
| 158 | |
| 159 | |
| 160 | def fetch_kluster_models(logger): |
no test coverage detected