Anshul Prasad commited on
Commit ·
229a4d5
1
Parent(s): 13f54fc
change model from openai to grok
Browse files- api/generate_response.py +3 -3
- config.py +3 -2
- pyproject.toml +1 -0
- uv.lock +22 -0
api/generate_response.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import logging
|
| 2 |
-
from
|
| 3 |
import tiktoken
|
| 4 |
|
| 5 |
from utils.token import count_tokens
|
| 6 |
-
from config import API_URL, MODEL,
|
| 7 |
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
|
@@ -14,7 +14,7 @@ except KeyError:
|
|
| 14 |
encoder = tiktoken.get_encoding("cl100k_base")
|
| 15 |
|
| 16 |
try:
|
| 17 |
-
client =
|
| 18 |
logging.info("OpenAI client initialized.")
|
| 19 |
except Exception as e:
|
| 20 |
logging.critical("Failed to initialize OpenAI client as %s", e)
|
|
|
|
| 1 |
import logging
|
| 2 |
+
from groq import Groq
|
| 3 |
import tiktoken
|
| 4 |
|
| 5 |
from utils.token import count_tokens
|
| 6 |
+
from config import API_URL, MODEL, GROQ_API_KEY, SYSTEM_PROMPT
|
| 7 |
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
|
|
|
| 14 |
encoder = tiktoken.get_encoding("cl100k_base")
|
| 15 |
|
| 16 |
try:
|
| 17 |
+
client = Groq(api_key=GROQ_API_KEY)
|
| 18 |
logging.info("OpenAI client initialized.")
|
| 19 |
except Exception as e:
|
| 20 |
logging.critical("Failed to initialize OpenAI client as %s", e)
|
config.py
CHANGED
|
@@ -17,8 +17,9 @@ COOKIES_FILE = Path("utils/youtube_cookies.txt")
|
|
| 17 |
API_URL = "https://models.github.ai/inference"
|
| 18 |
HF_API_TOKEN = os.environ.get("HF_API_TOKEN")
|
| 19 |
GH_API_TOKEN = os.environ.get("GITHUB_TOKEN")
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
SYSTEM_PROMPT = """
|
| 23 |
You are speaking as Acharya Prashant.
|
| 24 |
|
|
|
|
| 17 |
API_URL = "https://models.github.ai/inference"
|
| 18 |
HF_API_TOKEN = os.environ.get("HF_API_TOKEN")
|
| 19 |
GH_API_TOKEN = os.environ.get("GITHUB_TOKEN")
|
| 20 |
+
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
| 21 |
+
MODEL = "llama-3.1-8b-instant"
|
| 22 |
+
MAX_CONTEXT_TOKENS = 4500
|
| 23 |
SYSTEM_PROMPT = """
|
| 24 |
You are speaking as Acharya Prashant.
|
| 25 |
|
pyproject.toml
CHANGED
|
@@ -7,6 +7,7 @@ requires-python = ">=3.11"
|
|
| 7 |
dependencies = [
|
| 8 |
"faiss-cpu==1.9.0",
|
| 9 |
"fastapi==0.116.1",
|
|
|
|
| 10 |
"openai==2.8.1",
|
| 11 |
"pytz==2025.2",
|
| 12 |
"sentence-transformers==3.0.1",
|
|
|
|
| 7 |
dependencies = [
|
| 8 |
"faiss-cpu==1.9.0",
|
| 9 |
"fastapi==0.116.1",
|
| 10 |
+
"groq>=1.0.0",
|
| 11 |
"openai==2.8.1",
|
| 12 |
"pytz==2025.2",
|
| 13 |
"sentence-transformers==3.0.1",
|
uv.lock
CHANGED
|
@@ -15,6 +15,7 @@ source = { virtual = "." }
|
|
| 15 |
dependencies = [
|
| 16 |
{ name = "faiss-cpu" },
|
| 17 |
{ name = "fastapi" },
|
|
|
|
| 18 |
{ name = "openai" },
|
| 19 |
{ name = "pytz" },
|
| 20 |
{ name = "sentence-transformers" },
|
|
@@ -29,6 +30,7 @@ dependencies = [
|
|
| 29 |
requires-dist = [
|
| 30 |
{ name = "faiss-cpu", specifier = "==1.9.0" },
|
| 31 |
{ name = "fastapi", specifier = "==0.116.1" },
|
|
|
|
| 32 |
{ name = "openai", specifier = "==2.8.1" },
|
| 33 |
{ name = "pytz", specifier = "==2025.2" },
|
| 34 |
{ name = "sentence-transformers", specifier = "==3.0.1" },
|
|
@@ -225,6 +227,23 @@ wheels = [
|
|
| 225 |
{ url = "https://files.pythonhosted.org/packages/e6/ab/fb21f4c939bb440104cc2b396d3be1d9b7a9fd3c6c2a53d98c45b3d7c954/fsspec-2026.2.0-py3-none-any.whl", hash = "sha256:98de475b5cb3bd66bedd5c4679e87b4fdfe1a3bf4d707b151b3c07e58c9a2437", size = 202505, upload-time = "2026-02-05T21:50:51.819Z" },
|
| 226 |
]
|
| 227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
[[package]]
|
| 229 |
name = "h11"
|
| 230 |
version = "0.16.0"
|
|
@@ -1322,6 +1341,9 @@ wheels = [
|
|
| 1322 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-1-cp311-none-macosx_11_0_arm64.whl", hash = "sha256:0826ac8e409551e12b2360ac18b4161a838cbd111933e694752f351191331d09" },
|
| 1323 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-1-cp312-none-macosx_11_0_arm64.whl", hash = "sha256:7fbbf409143a4fe0812a40c0b46a436030a7e1d14fe8c5234dfbe44df47f617e" },
|
| 1324 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-1-cp313-none-macosx_11_0_arm64.whl", hash = "sha256:b39cafff7229699f9d6e172cac74d85fd71b568268e439e08d9c540e54732a3e" },
|
|
|
|
|
|
|
|
|
|
| 1325 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-cp311-none-macosx_11_0_arm64.whl", hash = "sha256:4584ab167995c0479f6821e3dceaf199c8166c811d3adbba5d8eedbbfa6764fd" },
|
| 1326 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-cp312-none-macosx_11_0_arm64.whl", hash = "sha256:45a1c5057629444aeb1c452c18298fa7f30f2f7aeadd4dc41f9d340980294407" },
|
| 1327 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-cp313-cp313t-macosx_14_0_arm64.whl", hash = "sha256:339e05502b6c839db40e88720cb700f5a3b50cda332284873e851772d41b2c1e" },
|
|
|
|
| 15 |
dependencies = [
|
| 16 |
{ name = "faiss-cpu" },
|
| 17 |
{ name = "fastapi" },
|
| 18 |
+
{ name = "groq" },
|
| 19 |
{ name = "openai" },
|
| 20 |
{ name = "pytz" },
|
| 21 |
{ name = "sentence-transformers" },
|
|
|
|
| 30 |
requires-dist = [
|
| 31 |
{ name = "faiss-cpu", specifier = "==1.9.0" },
|
| 32 |
{ name = "fastapi", specifier = "==0.116.1" },
|
| 33 |
+
{ name = "groq", specifier = ">=1.0.0" },
|
| 34 |
{ name = "openai", specifier = "==2.8.1" },
|
| 35 |
{ name = "pytz", specifier = "==2025.2" },
|
| 36 |
{ name = "sentence-transformers", specifier = "==3.0.1" },
|
|
|
|
| 227 |
{ url = "https://files.pythonhosted.org/packages/e6/ab/fb21f4c939bb440104cc2b396d3be1d9b7a9fd3c6c2a53d98c45b3d7c954/fsspec-2026.2.0-py3-none-any.whl", hash = "sha256:98de475b5cb3bd66bedd5c4679e87b4fdfe1a3bf4d707b151b3c07e58c9a2437", size = 202505, upload-time = "2026-02-05T21:50:51.819Z" },
|
| 228 |
]
|
| 229 |
|
| 230 |
+
[[package]]
|
| 231 |
+
name = "groq"
|
| 232 |
+
version = "1.0.0"
|
| 233 |
+
source = { registry = "https://pypi.org/simple" }
|
| 234 |
+
dependencies = [
|
| 235 |
+
{ name = "anyio" },
|
| 236 |
+
{ name = "distro" },
|
| 237 |
+
{ name = "httpx" },
|
| 238 |
+
{ name = "pydantic" },
|
| 239 |
+
{ name = "sniffio" },
|
| 240 |
+
{ name = "typing-extensions" },
|
| 241 |
+
]
|
| 242 |
+
sdist = { url = "https://files.pythonhosted.org/packages/3f/12/f4099a141677fcd2ed79dcc1fcec431e60c52e0e90c9c5d935f0ffaf8c0e/groq-1.0.0.tar.gz", hash = "sha256:66cb7bb729e6eb644daac7ce8efe945e99e4eb33657f733ee6f13059ef0c25a9", size = 146068, upload-time = "2025-12-17T23:34:23.115Z" }
|
| 243 |
+
wheels = [
|
| 244 |
+
{ url = "https://files.pythonhosted.org/packages/4a/88/3175759d2ef30406ea721f4d837bfa1ba4339fde3b81ba8c5640a96ed231/groq-1.0.0-py3-none-any.whl", hash = "sha256:6e22bf92ffad988f01d2d4df7729add66b8fd5dbfb2154b5bbf3af245b72c731", size = 138292, upload-time = "2025-12-17T23:34:21.957Z" },
|
| 245 |
+
]
|
| 246 |
+
|
| 247 |
[[package]]
|
| 248 |
name = "h11"
|
| 249 |
version = "0.16.0"
|
|
|
|
| 1341 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-1-cp311-none-macosx_11_0_arm64.whl", hash = "sha256:0826ac8e409551e12b2360ac18b4161a838cbd111933e694752f351191331d09" },
|
| 1342 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-1-cp312-none-macosx_11_0_arm64.whl", hash = "sha256:7fbbf409143a4fe0812a40c0b46a436030a7e1d14fe8c5234dfbe44df47f617e" },
|
| 1343 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-1-cp313-none-macosx_11_0_arm64.whl", hash = "sha256:b39cafff7229699f9d6e172cac74d85fd71b568268e439e08d9c540e54732a3e" },
|
| 1344 |
+
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-2-cp311-none-macosx_11_0_arm64.whl", hash = "sha256:90821a3194b8806d9fa9fdaa9308c1bc73df0c26808274b14129a97c99f35794" },
|
| 1345 |
+
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-2-cp312-none-macosx_11_0_arm64.whl", hash = "sha256:358bd7125cbec6e692d60618a5eec7f55a51b29e3652a849fd42af021d818023" },
|
| 1346 |
+
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-2-cp313-none-macosx_11_0_arm64.whl", hash = "sha256:470de4176007c2700735e003a830828a88d27129032a3add07291da07e2a94e8" },
|
| 1347 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-cp311-none-macosx_11_0_arm64.whl", hash = "sha256:4584ab167995c0479f6821e3dceaf199c8166c811d3adbba5d8eedbbfa6764fd" },
|
| 1348 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-cp312-none-macosx_11_0_arm64.whl", hash = "sha256:45a1c5057629444aeb1c452c18298fa7f30f2f7aeadd4dc41f9d340980294407" },
|
| 1349 |
{ url = "https://download.pytorch.org/whl/cpu/torch-2.10.0-cp313-cp313t-macosx_14_0_arm64.whl", hash = "sha256:339e05502b6c839db40e88720cb700f5a3b50cda332284873e851772d41b2c1e" },
|