<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>LM Studio on Ash Tewari</title><link>https://www.tewari.info/tag/lmstudio/</link><description>Recent content in LM Studio on Ash Tewari</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Mon, 29 Apr 2024 00:25:55 +0000</lastBuildDate><atom:link href="https://www.tewari.info/tag/lmstudio/feed.xml" rel="self" type="application/rss+xml"/><item><title>AI Powered Bookshelf</title><link>https://www.tewari.info/2024/04/28/ai-powered-bookshelf/</link><pubDate>Mon, 29 Apr 2024 00:25:55 +0000</pubDate><guid>https://www.tewari.info/2024/04/28/ai-powered-bookshelf/</guid><description>&lt;p&gt;Bookshelf is a Generative AI application built as a rudimentary, but fairly capable, &lt;a class="link" href="https://docs.llamaindex.ai/en/stable/use_cases/q_and_a/" target="_blank" rel="noopener"&#10; &gt;RAG&lt;/a&gt; implementation written in &lt;a class="link" href="https://www.python.org/doc/" target="_blank" rel="noopener"&#10; &gt;python&lt;/a&gt;. It can use an open source LLM model (running locally or in the cloud) or a GPT model via OpenAI&amp;rsquo;s API.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;The application is created using &lt;a class="link" href="https://streamlit.io/" target="_blank" rel="noopener"&#10; &gt;streamlit&lt;/a&gt;.&lt;/li&gt;&#10;&lt;li&gt;I used &lt;a class="link" href="https://www.llamaindex.ai/" target="_blank" rel="noopener"&#10; &gt;llama-index&lt;/a&gt; for orchestrating the loading of documents into the &lt;a class="link" href="https://en.wikipedia.org/wiki/Vector_database" target="_blank" rel="noopener"&#10; &gt;vector database&lt;/a&gt;. Only TokenTextSplitter is currently used. It does not optimize for PDF, html and other formats.&lt;/li&gt;&#10;&lt;li&gt;&lt;a class="link" href="https://www.trychroma.com/" target="_blank" rel="noopener"&#10; &gt;ChromaDb&lt;/a&gt; is the vector database to store the embedding vectors and metadata of the document nodes.&lt;/li&gt;&#10;&lt;li&gt;You can use any open source embeddings model from &lt;a class="link" href="https://huggingface.co/models?other=embeddings" target="_blank" rel="noopener"&#10; &gt;HuggingFace&lt;/a&gt;.&lt;/li&gt;&#10;&lt;li&gt;Bookshelf will automatically use the GPU when creating local embeddings, if the GPU is available on your machine.&lt;/li&gt;&#10;&lt;li&gt;You can use &lt;a class="link" href="https://platform.openai.com/docs/guides/embeddings" target="_blank" rel="noopener"&#10; &gt;OpenAI embeddings&lt;/a&gt; as well. There is no way to use a specific OpenAI embedding model or configure the parameters yet.&lt;/li&gt;&#10;&lt;li&gt;Use OpenAI API or any OpenAI compatible LLM API (using &lt;a class="link" href="https://lmstudio.ai/" target="_blank" rel="noopener"&#10; &gt;LMStudio&lt;/a&gt;, &lt;a class="link" href="https://ollama.com/" target="_blank" rel="noopener"&#10; &gt;Ollama&lt;/a&gt; or &lt;a class="link" href="https://github.com/oobabooga/text-generation-webui" target="_blank" rel="noopener"&#10; &gt;text-generation-webui&lt;/a&gt;) of your choice.&lt;/li&gt;&#10;&lt;li&gt;There is a live demo on streamlit cloud - &lt;a class="link" href="https://bookshelf.streamlit.app/" target="_blank" rel="noopener"&#10; &gt;https://bookshelf.streamlit.app/&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;The demo allows only OpenAI integration. You can run it locally for accessing Open Source embedding models and LLMs.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;Live demo - &lt;a class="link" href="https://bookshelf.streamlit.app/" target="_blank" rel="noopener"&#10; &gt;https://bookshelf.streamlit.app/&lt;/a&gt;&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;p&gt;You will need your OpenAI api key for the demo.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-39.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;If you are running it locally, you will have the option of using an Open Source LLM instance via an API Url. In the screenshot, I am using an open source Embedding Model from HuggingFace (sentence-transformers/all-mpnet-base-v2) and The local LLM server at http://localhost:1234/v1&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-40.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;Collections tab shows all collections in the database. It also shows the names of all the files in the selected collection. You can inspect individual chunks for the metadata and text of each chunk. You can delete all contents of the collection &lt;strong&gt;(&lt;/strong&gt; &lt;strong&gt;there is no warning&lt;/strong&gt; &lt;strong&gt;)&lt;/strong&gt;.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-38.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;You can modify the collection name to create a new collection. Multiple files can be uploaded at the same time. You can specify if you want to extract metadata from the file contents. &lt;strong&gt;Enabling this option can add significant cost&lt;/strong&gt; because it employs Extractors which use LLM to generate title, summaries, keywords and questions for each document.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-41.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;On the Retrieve tab, you can query chunks which are semantically related to your query.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-43.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;On the Prompt tab, you can prompt your LLM. The context as well as the Prompt Template is editable.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-44.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;Here is an example of using the context retrieved from chunks in the Vector database to query the LLM.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-45.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;This inference was performed using &lt;a class="link" href="https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-gguf" target="_blank" rel="noopener"&#10; &gt;Phi3&lt;/a&gt; model running locally on LMStudio.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-46.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;Code is on Github - &lt;a class="link" href="https://github.com/ashtewari/bookshelf" target="_blank" rel="noopener"&#10; &gt;https://github.com/ashtewari/bookshelf&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;Have fun!&lt;/p&gt;&#10;</description></item></channel></rss>