Upload 6 files
Browse files- 1.ipynb +0 -0
- 2.ipynb +0 -0
- 3.ipynb +0 -0
- fetch.ipynb +1 -0
- grok.ipynb +1 -0
- openai.ipynb +1 -0
1.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
2.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
3.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
fetch.ipynb
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import requests\nimport json\n\nurl = \"https://raw.githubusercontent.com/pratham19092006/ML-in-image/refs/heads/main/1.ipynb\" # 1 or 2 or 3\ncontent = requests.get(url).text\n\nnotebook = json.loads(content)\n\nall_code = \"\"\n\nfor cell in notebook[\"cells\"]:\n\n if cell[\"cell_type\"] == \"code\":\n\n code = \"\".join(cell[\"source\"])\n\n all_code += code + \"\\n\\n\"\n\nprint(all_code)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null}]}
|
grok.ipynb
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import requests\n\nAPI_KEY = \"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\"\n\nurl = \"https://api.groq.com/openai/v1/chat/completions\"\n\nheaders = {\n \"Authorization\": f\"Bearer {API_KEY}\",\n \"Content-Type\": \"application/json\"\n}\n\n# conversation memory\nmessages = []\n\ndef ask_llm(question):\n\n global messages\n\n # add user message\n messages.append({\n \"role\": \"user\",\n \"content\": question\n })\n\n data = {\n \"model\": \"llama-3.1-8b-instant\",\n\n \"messages\": messages,\n\n \"max_tokens\": 1000\n }\n\n response = requests.post(\n url,\n headers=headers,\n json=data\n )\n\n result = response.json()\n\n answer = result[\"choices\"][0][\"message\"][\"content\"]\n\n # save assistant response\n messages.append({\n \"role\": \"assistant\",\n \"content\": answer\n })\n\n print(\"Successful\")\n return answer","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\n ask_llm(\"\"\"\nhow are you\n\"\"\")\n)","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}
|
openai.ipynb
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import requests\n\nAPI_KEY = \"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\"\nMODEL = \"openrouter/auto\" # Automatically picks the best/cheapest model\n\ndef ask_llm(question, messages=[]):\n messages.append({\"role\": \"user\", \"content\": question})\n \n response = requests.post(\n url=\"https://openrouter.ai/api/v1/chat/completions\",\n headers={\"Authorization\": f\"Bearer {API_KEY}\"},\n json={\n \"model\": MODEL,\n \"messages\": messages[-10:] # Long memory: keeps last 10 exchanges\n }\n ).json()\n\n answer = response[\"choices\"][0][\"message\"][\"content\"]\n messages.append({\"role\": \"assistant\", \"content\": answer})\n return answer","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Usage\nhistory = []\nprint(ask_llm(\"\"\" \nhow\nare you\n\"\"\", history))","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}
|