Package: llm-app
LLM AppPathway'sLLM (Large Language Model) Appis a Python library that helps you create and launch AI-powered applications based on the most up-to-date knowledge available in your data sources. You can use it to answer natural language queries asked by your users, or to run data transformation pipelines with LLM's.Quick links- 👀Why LLM App?🚀Watch it in action📚How it works🌟Examples🏁Get Started💼Showcases🛠️Troubleshooting👥Contributing💡Need help?Why LLM App?Simplicity- Simplifies your AI pipeline by consolidating capabilities into one platform. No need to integrate and maintain separate modules for your Gen AI app:Vector Database (e.g. Pinecone/Weaviate/Qdrant) + Framework for LLM chaining + Cache (e.g. Redis) + API Framework (e.g. Fast API).Real-time data syncing- Syncs both structured and unstructured data from diverse sources, enabling real-time Retrieval Augmented Generation (RAG).Easy alert setup- Configure alerts for key business events with simple configurations. Ask a question, and get updated when new info is available.Scalability- Handles heavy data loads and usage without degradation in performance. Metrics help track usage and scalability. Learn more about the performance of the underlyingPathway data processing framework.Monitoring- Provide visibility into model behavior via monitoring, tracing errors, anomaly detection, and replay for debugging. Helps with response quality.Security- Designed for the enterprise with capabilities like Personally Identifiable Information (PII) detection, content moderation, permissions, and version control. Run this in your private cloud with local LLMs.Unification- You can cover multiple aspects of your choice with a unified application logic: back-end, embedding, retrieval, LLM tech stack.Watch it in actionEffortlessly extract and organize unstructured data from PDFs, docs, and more into SQL tables - in real-time.Analysis of live documents streams.(See:unstructured-to-sqlexample.)Automated real-time knowledge mining and alerting.Monitor streams of changing documents, get real-time alerts when answers change.Using incremental vector search, only the most relevant context is automatically passed into the LLM for analysis, minimizing token use - even when thousands of documents change every minute. This is real-time RAG taken to a new level 😊.For the code, see thedrive_alertexample. You can find more details in ablog post on alerting with LLM-App.How it worksThe defaultcontextfultemplate launches an application that connects to a source folder with documents, stored inAWS S3or locally on your computer. The app isalways in syncwith updates to your documents, building in real-time a "vector index" using the Pathway package. It waits for user queries that come as HTTP REST requests, then uses the index to find relevant documents and responds usingOpenAI APIorHugging Facein natural language. This way, it provides answers that are always best on the freshest and most accuratereal-time data.This application template can also be combined with streams of fresh data, such as news feeds or status reports, either through REST or a technology like Kafka. It can also be combined with extra static data sources and user-specific contexts, to provide more relevant answers and reduce LLM hallucination.Read more about the implementation details and how to extend this application inour blog article.Instructional videos▶️Building an LLM Application without a vector database- byJan Chorowski▶️Let's build a real-world LLM app in 11 minutes- byPau Labarta BajoAdvanced FeaturesApplications built using LLM App can include the following capabilities:Local Machine Learning models- LLM App can be configured to run with local LLMs and embedding models, without making API calls outside of the User's Organization.Multiple live data sources- LLM App can be used to handle live data sources (news feeds, APIs, data streams in Kafka),Extensible enterprise logic- user permissions, user session handling, and a data security layer can all be embedded in your application logic by integrating with your enterprise SSO, AD Domains, LDAP, etc.To learn more about advanced features see:Features for Organizations.ExamplesPick one that is closest to your needs.Example app (template)DescriptioncontextlessThis simple example calls OpenAI ChatGPT API but does not use an index when processing queries. It relies solely on the given user query. We recommend it to start your Pathway LLM journey.contextfulThis default example of the app will index the jsonlines documents located in thedata/pathway-docsdirectory. These indexed documents are then taken into account when processing queries. The pathway pipeline running in this mode is located atexamples/pipelines/contextful/app.py.contextful-s3This example operates similarly to the contextful mode. The main difference is that the documents are stored and indexed from an S3 bucket, allowing the handling of a larger volume of documents. This can be more suitable for production environments.unstructuredProcess unstructured documents such as PDF, HTML, DOCX, PPTX, and more. Visitunstructured-iofor the full list of supported formats.localThis example runs the application using Huggingface Transformers, which eliminates the need for the data to leave the machine. It provides a convenient way to use state-of-the-art NLP models locally.unstructured-to-sqlThis example extracts the data from unstructured files and stores it into a PostgreSQL table. It also transforms the user query into an SQL query which is then executed on the PostgreSQL table.alertAsk questions, get alerted whenever response changes. Pathway is always listening for changes, whenever new relevant information is added to the stream (local files in this example), LLM decides if there is a substantial difference in response and notifies the user with a Slack message.drive-alertThealertexample on steroids. Whenever relevant information on Google Docs is modified or added, get real-time alerts via Slack. See thetutorial.Get StartedPrerequisitesMake sure thatPython3.10 or above installed on your machine.Download and InstallPipto manage project packages.[Optional if you use OpenAI models]. Create anOpenAIaccount and generate a new API Key: To access the OpenAI API, you will need to create an API Key. You can do this by logging into theOpenAI websiteand navigating to the API Key management page.[Important if you use Windows OS]. The examples only support Unix-like systems (such as Linux, macOS, and BSD). If you are a Windows user, we highly recommend leveragingWindows Subsystem for Linux (WSL)or Dockerize the app to run as a container.[Optional if you use Docker to run samples]. Download and installdocker.Now, follow the steps to install andget started with one of the provided examples. You can pick any example that you find interesting - if not sure, pickcontextful.Alternatively, you can also take a look at theapplication showcases.Step 1: Clone the repositoryThis is done with thegit clonecommand followed by the URL of the repository:gitclonehttps://github.com/pathwaycom/llm-app.gitNext, navigate to the repository:cdllm-appStep 2: Set environment variablesCreate an .env file in the root directory and add the following environment variables, adjusting their values according to your specific requirements and setup.Environment VariableDescriptionAPP_VARIANTDetermines which pipeline to run in your application. Available modes are [contextful,contextful-s3,contextless,local,unstructured-to-sql,alert,drive-alert]. By default, the mode is set tocontextful.PATHWAY_REST_CONNECTOR_HOSTSpecifies the host IP for the REST connector in Pathway. For the dockerized version, set it to0.0.0.0Natively, you can use127.0.0.1PATHWAY_REST_CONNECTOR_PORTSpecifies the port number on which the REST connector service of the Pathway should listen. Here, it is set to 8080.OPENAI_API_KEYThe API token for accessing OpenAI services. If you are not running the local version, please remember to replace it with your API token, which you can generate from your account onopenai.com.PATHWAY_CACHE_DIRSpecifies the directory where the cache is stored. You could use /tmpcache.For example:APP_VARIANT=contextfulPATHWAY_REST_CONNECTOR_HOST=0.0.0.0PATHWAY_REST_CONNECTOR_PORT=8080OPENAI_API_KEY=<YourToken>PATHWAY_CACHE_DIR=/tmp/cacheStep 3: Build and run the appYou can install and run the LLM App in two different ways.Using DockerDocker is a tool designed to make it easier to create, deploy, and run applications by using containers. Here is how to use Docker to build and run the LLM App:dockercomposerun--build--rm-p8080:8080llm-app-examplesIf you have set a different port inPATHWAY_REST_CONNECTOR_PORT, replace the second8080with this port in the command above.When the process is complete, the App will be up and running inside a Docker container and accessible at0.0.0.0:8080. From there, you can proceed to the "Usage" section of the documentation for information on how to interact with the application.Native ApproachInstall poetry:pipinstallpoetryInstall llm_app and dependencies:poetryinstall--withexamples--extraslocalYou can omit--extras localpart if you're not going to run local example.Run the examples:You can start the example with the command:poetryrun./run_examples.pycontextfulStep 4: Start to use itSend REST queries(in a separate terminal window): These are examples of how to interact with the application once it's running.curlis a command-line tool used to send data using various network protocols. Here, it's being used to send HTTP requests to the application.curl--data'{"user": "user", "query": "How to connect to Kafka in Pathway?"}'http://localhost:8080/

curl--data'{"user": "user", "query": "How to use LLMs in Pathway?"}'http://localhost:8080/If you are on windows CMD, then the query would rather look like thiscurl --data "{\"user\": \"user\", \"query\": \"How to use LLMs in Pathway?\"}" http://localhost:8080/Test reactivity by adding a new file:This shows how to test the application's ability to react to changes in data by adding a new file and sending a query.cp./data/documents_extra.jsonl./data/pathway-docs/Or if using docker compose:dockercomposeexecllm-app-examplesmv/app/examples/data/documents_extra.jsonl/app/examples/data/pathway-docs/Let's query again:curl--data'{"user": "user", "query": "How to use LLMs in Pathway?"}'http://localhost:8080/Step 5: Launch the User Interface:Go to theexamples/ui/directory (orexamples/pipelines/unstructured/uiif you are running the unstructured version.) and executestreamlit run server.py. Then, access the URL displayed in the terminal to engage with the LLM App using a chat interface.Bonus: Build your own Pathway-powered LLM AppWant to learn more about building your own app? See step-by-step guideBuilding a llm-app tutorialOr,Simply addllm-appto your project's dependencies and copy one of theexamplesto get started!ShowcasesPython sales- Find real-time sales with AI-powered Python API using ChatGPT and LLM (Large Language Model) App.Dropbox Data Observability- See how to get started with chatting with your Dropbox and having data observability.TroubleshootingPlease check out ourQ&Ato get solutions for common installation problems and other issues.Raise an issueTo provide feedback or report a bug, pleaseraise an issue on our issue tracker.ContributingAnyone who wishes to contribute to this project, whether documentation, features, bug fixes, code cleanup, testing, or code reviews, is very much encouraged to do so.To join, just raise your hand on thePathway Discord server(#get-help) or the GitHubdiscussionboard.If you are unfamiliar with how to contribute to GitHub projects, here is aGet Started Guide. A full set of contribution guidelines, along with templates, are in progress.Coming SoonTemplates for retrieving context via graph walks.Easy setup for model drift monitoring.Templates for model A/B testing.Real-time OpenAI API observability.Need help?Interested in using LLM App with your data source, stack, and custom use cases? Connect with us to get help with:Connecting your own live data sources to your LLM application (e.g. Google or Microsoft Drive documents, Kafka, databases, API's, ...).Explore how you can get your LLM application up and running in popular cloud platforms such as Azure and AWS.End-to-end solution implementation.Reach us atcontact@pathway.comor viaPathway's website.Supported and maintained by