{"id":24519150,"url":"https://github.com/memduhg/langchain-fastapi-template","last_synced_at":"2026-01-08T09:08:57.697Z","repository":{"id":248256823,"uuid":"827975720","full_name":"MemduhG/langchain-fastapi-template","owner":"MemduhG","description":"RAG template using FastAPI and LangChain","archived":false,"fork":false,"pushed_at":"2024-08-01T17:58:28.000Z","size":27,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-06T12:05:35.250Z","etag":null,"topics":["docker","fastapi","langchain","python","rag","retrieval-augmented-generation"],"latest_commit_sha":null,"homepage":"","language":"Python","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/MemduhG.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-12T19:44:03.000Z","updated_at":"2024-09-10T16:24:09.000Z","dependencies_parsed_at":"2024-08-01T19:48:41.979Z","dependency_job_id":null,"html_url":"https://github.com/MemduhG/langchain-fastapi-template","commit_stats":null,"previous_names":["memduhg/langchain-fastapi-template"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MemduhG%2Flangchain-fastapi-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MemduhG%2Flangchain-fastapi-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MemduhG%2Flangchain-fastapi-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MemduhG%2Flangchain-fastapi-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MemduhG","download_url":"https://codeload.github.com/MemduhG/langchain-fastapi-template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246430876,"owners_count":20776103,"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":["docker","fastapi","langchain","python","rag","retrieval-augmented-generation"],"created_at":"2025-01-22T01:49:11.959Z","updated_at":"2026-01-08T09:08:57.645Z","avatar_url":"https://github.com/MemduhG.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# langchain-fastapi-template\nThis is a simple RAG API built with FastAPI and LangChain.\n\n## Run Locally\n\n### 1. Set the API Key\nThe easier way to do this is using the `.env`\nfile.\nThe `.env` file has a single environment variable to set,\ncurrently defined as `OPENAI_API_KEY=xxxx`. \nPlease change the `xxxx` value to your own OpenAI API key.\n\nAlternatively one can set the environment variable \n`OPENAI_API_KEY`to their key. The former method is provided \nfor the sake of user-friendliness. In either case please do \nnot commit your API key to a git repo.\n### 2. Install the python requirements\n```bash\npip install -r requirements.txt\n```\n\n### 3. Generate the Vector Store\nThe vector database is already provided as part of this repo,\nbut if the user prefers, it will be enough to run the command below to generate the vector\ndatabase.\n```bash\npython rag.py --repopulate\n```\nThe directories for the documents and where the vector database\nwill be saved can be specified, but the API currently assumes\nthey are in their default locations.\n\n### 4. Run and Query the API\nRun the API with \n```bash\nfastapi run main.py\n```\n\nIf we wanted to find out which countries the company can't sell to, we could \nquery the API this way:\n```bash\n$ curl -X POST localhost:8000/question -H \"Content-Type: application/json\" -d '{\"input\": \"Which countries are on our no sale list?\", \"detailed\": false}'\n```\nThis should give you something like the following output.\n```\n\"Spain, Italy, Germany, and Sweden are on the no sale list.\"%       \n```\nSet the field `detailed` to `true` instead of `false` to get more \ninformation like the document retrieved. Since we are only working with one\ndocument, this is probably not so important in our case.\n\nThis query along with two more can be found in the `sample.sh` \nfile. \nRunning this file should produce outputs like the following\n```\n$ bash sample.sh \n\"Sweden is not included in the list of countries where sales are not conducted due to ethical and environmental concerns. Some of the products do not meet Sweden's high environmental standards, and there are concerns raised about the ethical sourcing of materials used in the products. Until full compliance with Sweden's ethical and environmental standards can be ensured, sales will not be conducted in this market.\"\n\"You should contact the Compliance Department for information about sales restrictions.\"\n\"Spain, Italy, Germany, and Sweden are on the company's no sale list.\"%    \n```\n\n## Docker\n**Note: The OpenAI API key still needs to be set before using \nDocker. The following section assumes it is set in the `.env` file.**\n\n### Build\nThe provided dockerfile will create an image that will include\nvectors if generated, and generate them if not. Simply\nbuild the image with the following command.\n```bash\ndocker build . -t rag \n```\nIf the OpenAI key is set in your environment and not in the `.env`\nfile, build with the following command instead:\n```bash\ndocker build --build-arg=OPENAI_API_KEY . -t rag\n```\nIf it is neither in the environment variables or the `.env` file,\nan alternative is to simple provide it before running the build\ncommand, e.g.\n```bash\nOPENAI_API_KEY=xxxx docker build --build-arg=OPENAI_API_KEY . -t rag\n```\n\n### Run\nRun the image once it's built with the following, please do not\nomit the port option as it is necessary to send requests to the\ncontainer.\n```bash\ndocker run -p 8000:8000 rag\n```\n\nAfter building and running, sending requests as shown above will return \nthe desired results.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmemduhg%2Flangchain-fastapi-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmemduhg%2Flangchain-fastapi-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmemduhg%2Flangchain-fastapi-template/lists"}