{"id":16299860,"url":"https://github.com/koji/llm_api_template","last_synced_at":"2025-04-06T07:32:21.231Z","repository":{"id":205690252,"uuid":"714844781","full_name":"koji/llm_api_template","owner":"koji","description":"API template for LLM model with llama.cpp","archived":false,"fork":false,"pushed_at":"2023-11-06T01:06:02.000Z","size":10,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-21T19:04:15.737Z","etag":null,"topics":["googlecolab","llamacpp","llm","python"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koji.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-06T00:36:54.000Z","updated_at":"2024-06-22T02:24:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"79aa9dcb-ccca-4182-8c2f-9db920c5ca9e","html_url":"https://github.com/koji/llm_api_template","commit_stats":null,"previous_names":["koji/llm_api_template"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koji%2Fllm_api_template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koji%2Fllm_api_template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koji%2Fllm_api_template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koji%2Fllm_api_template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koji","download_url":"https://codeload.github.com/koji/llm_api_template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247450480,"owners_count":20940925,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["googlecolab","llamacpp","llm","python"],"created_at":"2024-10-10T20:49:37.779Z","updated_at":"2025-04-06T07:32:20.968Z","avatar_url":"https://github.com/koji.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LLM API Template\n\n## What is this?\nThis is a jupyter notebook that uses LLMs via endpoints. This is using [llama.cpp](https://github.com/ggerganov/llama.cpp), [ngrok](https://ngrok.com/), and a model from [TheBloke](https://huggingface.co/TheBloke)\nThe base jupyter notebook uses [zephyr-7b](https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF).\n\n## How to use\n[Requiremetns]  \n- Google account for Google colab https://colab.google/\n- ngrok account https://ngrok.com\n\n### step0. create the above accounts  \n### step1. Copy the jupyter notebook\n### step2. Create a secreat key\nThere is the key icon in Google colab's sidebar. You will need to add your token as a secret key. In the jupyter notebook, I named `NGROK`. You can change that into anything you want.    \n### step3. Run the jupyter notebook\nAfter setting a new secreat key, you can run the jupyter notebook to run the API server.\n### step4. Check the API server\nIf everything works properly, you can acces https://ngrok_address/docs and you will see something like 👇  \nYou can see the all available endpoints. \n![Screenshot 2023-11-05 193747](https://github.com/koji/llm_api_template/assets/474225/561830f6-f3a7-4c71-bc39-c857c8eb7ad9)\n\n**Do not run the last two lines**  \nThe first one is to kill FastAPI server and the second one is to kill ngrok.\n```shell\n!pkill uvicorn\n!pkill ngrok\n```\n\n### step5. Call the endpoint\nNow you can call the endpoint via any language you like. In this repo, I put a python code as a sample.  \nWhat you need to do is to change the url.  \n\n![Screenshot 2023-11-05 171110](https://github.com/koji/llm_api_template/assets/474225/240bd549-60c9-4332-8b69-f54802c60b7b)\n\n\n## How to use a different model?\nIf you want to use a different model such as llama2-7b, mistral-7b, etc, you will need to download the model from  https://huggingface.co/TheBloke and modify the jupyter notebook a little bit.\n\n```py\nfrom llama_cpp import Llama\nllm = Llama(model_path=\"zephyr-7b-alpha.Q5_K_M.gguf\") # 👈 you will need to change this model path.\noutput = llm(\"Q: can you write a python script for fizz buzz? A: \", max_tokens=2048, stop=[\"Q:\", \"\\n\"], echo=True)\nprint(output)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoji%2Fllm_api_template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoji%2Fllm_api_template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoji%2Fllm_api_template/lists"}