GithubHelp home page GithubHelp logo

logan-markewich / llama_index_starter_pack Goto Github PK

View Code? Open in Web Editor NEW
581.0 581.0 177.0 124.65 MB

This repository provides very basic flask, streamlit, and docker examples for the llama_index (fka gpt_index) package

License: MIT License

Dockerfile 1.46% Python 61.34% Shell 0.73% HTML 3.20% TypeScript 21.61% SCSS 10.98% CSS 0.68%

llama_index_starter_pack's People

Contributors

amarszowski avatar gaoyusong avatar leo4stone avatar logan-markewich avatar plpycoin avatar timconnorz avatar tylerjrichards avatar zhangbohan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

llama_index_starter_pack's Issues

llamaindex/llama_index_term_definition_demo Not working

I tried to access the demo on HF, got the error below:

image

I then downloaded the sample, configured it to run in my local docker environment, and got the same "JSONDecode" error.

did not expect this, and don't know how to fix it.

OSError: [WinError 10049] The requested address is not valid in its context

when I try to initialize a python folder flask_demo.py:
import os
from multiprocessing.managers import BaseManager
from flask import Flask, request, jsonify, make_response
from flask_cors import CORS
from werkzeug.utils import secure_filename

app = Flask(name)
CORS(app)

initialize manager connection

NOTE: you might want to handle the password in a less hardcoded way

manager = BaseManager(('', 5602), b'password')
manager.register('query_index')
manager.register('insert_into_index')
manager.register('get_documents_list')
manager.connect()

@app.route("/query", methods=["GET"])
def query_index():
global manager
query_text = request.args.get("text", None)
if query_text is None:
return "No text found, please include a ?text=blah parameter in the URL", 400

response = manager.query_index(query_text)._getvalue()
response_json = {
    "text": str(response),
    "sources": [{"text": str(x.source_text), 
                 "similarity": round(x.similarity, 2),
                 "doc_id": str(x.doc_id),
                 "start": x.node_info['start'],
                 "end": x.node_info['end']
                } for x in response.source_nodes]
}
return make_response(jsonify(response_json)), 200

@app.route("/uploadFile", methods=["POST"])
def upload_file():
global manager
if 'file' not in request.files:
return "Please send a POST request with a file", 400

filepath = None
try:
    uploaded_file = request.files["file"]
    filename = secure_filename(uploaded_file.filename)
    filepath = os.path.join('documents', os.path.basename(filename))
    uploaded_file.save(filepath)

    if request.form.get("filename_as_doc_id", None) is not None:
        manager.insert_into_index(filepath, doc_id=filename)
    else:
        manager.insert_into_index(filepath)
except Exception as e:
    # cleanup temp file
    if filepath is not None and os.path.exists(filepath):
        os.remove(filepath)
    return "Error: {}".format(str(e)), 500

# cleanup temp file
if filepath is not None and os.path.exists(filepath):
    os.remove(filepath)

return "File inserted!", 200

@app.route("/getDocuments", methods=["GET"])
def get_documents():
document_list = manager.get_documents_list()._getvalue()

return make_response(jsonify(document_list)), 200

@app.route("/")
def home():
return "Hello, World! Welcome to the llama_index docker image!"

if name == "main":
app.run(host="0.0.0.0", port=5601)

I get this error in the terminal:

python flask_demo.py
Traceback (most recent call last):
File "C:\Users\Tuindula\Desktop\flask_react\flask_demo.py", line 16, in
manager.connect()
File "C:\Users\Tuindula\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\managers.py", line 532, in connect
conn = Client(self._address, authkey=self._authkey)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Tuindula\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\connection.py", line 501, in Client
c = SocketClient(address)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Tuindula\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\connection.py", line 629, in SocketClient
s.connect(address)
OSError: [WinError 10049] The requested address is not valid in its context

can someone help me!

I have problem in streamlit_sql_sandbox

Here is my error message.

ValueError: Invalid context table names: {'violations', 'inspections', 'businesses'}

**File "C:\Users\dlehd\AppData\Roaming\Python\Python39\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
exec(code, module.dict)
File "C:\Users\dlehd\OneDrive\바탕 화면\project\llama_index_starter_pack\streamlit_sql_sandbox\streamlit_demo.py", line 95, in
st.session_state['llama_index'] = initialize_index(llm_name, model_temperature, table_context_dict if use_table_descrp else None, api_key)
File "C:\Users\dlehd\AppData\Roaming\Python\Python39\site-packages\streamlit\runtime\caching\cache_utils.py", line 178, in wrapper
return cached_func(*args, **kwargs)
File "C:\Users\dlehd\AppData\Roaming\Python\Python39\site-packages\streamlit\runtime\caching\cache_utils.py", line 207, in call
return self._get_or_create_cached_value(args, kwargs)
File "C:\Users\dlehd\AppData\Roaming\Python\Python39\site-packages\streamlit\runtime\caching\cache_utils.py", line 232, in _get_or_create_cached_value
return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
File "C:\Users\dlehd\AppData\Roaming\Python\Python39\site-packages\streamlit\runtime\caching\cache_utils.py", line 286, in _handle_cache_miss
computed_value = self._info.func(*func_args, func_kwargs)
File "C:\Users\dlehd\OneDrive\바탕 화면\project\llama_index_starter_pack\streamlit_sql_sandbox\streamlit_demo.py", line 33, in initialize_index
context_builder = SQLContextContainerBuilder(sql_database, context_dict=table_context_dict)
File "C:\Users\dlehd\AppData\Roaming\Python\Python39\site-packages\llama_index\indices\struct_store\container_builder.py", line 49, in init
raise ValueError(

I did setted requirements.txt and ran it with streamlit run. Do you know why? Thank you.

insert_into_index function only inserts the first page of PDF files

When using the insert_into_index function from index_server.py, it's observed that the LlamaIndex loads PDF files such that every page is treated as a separate document. Due to this behavior, the current implementation of the function, which takes only the first document returned from the load_data() method, results in only the first page of the PDF being inserted into the index. This leads to the exclusion of the subsequent pages of the PDF document from the index.

Relevant Code Snippet:

def insert_into_index(doc_file_path, doc_id=None):
    """Insert new document into global index."""
    global index, stored_docs
    document = SimpleDirectoryReader(input_files=[doc_file_path]).load_data()[0]

Expected Behavior:
All pages of the PDF document should be indexed, not just the first page.

Actual Behavior:
Only the first page of the PDF document gets indexed.

Suggested Fix:
Iterate over all documents returned by the load_data() method to ensure all pages of the PDF are indexed.

errors in flask_react method

I want to run the flask_react mode,when I run the launch_app.sh script,the error has happend:
(llama_index) ➜ flask_react git:(main) ✗ sh launch_app.sh
index_server running...
initializing index...
server started...

  • Serving Flask app 'flask_demo'
  • Debug mode: off
    WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
  • Running on all addresses (0.0.0.0)
  • Running on http://127.0.0.1:5601
  • Running on http://10.226.20.147:5601
    Press CTRL+C to quit

[email protected] build
react-scripts build

/home/wp/Desktop/llama_index_starter_pack/flask_react/node_modules/typescript/lib/typescript.js:139
for (let i = startIndex ?? 0; i < array.length; i++) {
^

SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at getModules (/home/wp/Desktop/llama_index_starter_pack/flask_react/node_modules/react-scripts/config/modules.js:119:16)
at Object. (/home/wp/Desktop/llama_index_starter_pack/flask_react/node_modules/react-scripts/config/modules.js:142:18)
at Module._compile (internal/modules/cjs/loader.js:999:30)

what does the solution about this? I'm not sure if this has anything to do with the npm version, my npm version is 8.5.1
and react-scripts version is 5.0.1

Install

Local Setup:

conda create --name llama_index python=3.11
pip install -r requirements.txt

Did nothing to put the starter kit on my local machine.

authenticaiton error...

When I run gpt-4, go to Query tab and clicked the initialize terms button.

I then run the standard ?, What is a bunnyhug and receive this error.

File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
exec(code, module.dict)
File "C:\Users\xxxx\Test\llama_index_starter_pack\streamlit_term_definition\streamlit_demo.py", line 227, in
.query(query_text)
^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\indices\query\base.py", line 23, in query
response = self._query(str_or_query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\query_engine\retriever_query_engine.py", line 149, in _query
response = self._response_synthesizer.synthesize(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\indices\query\response_synthesis.py", line 178, in synthesize
response_str = self._response_builder.get_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\indices\response\compact_and_refine.py", line 48, in get_response
response = super().get_response(
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\token_counter\token_counter.py", line 78, in wrapped_llm_predict
f_return_val = f(_self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\indices\response\refine.py", line 52, in get_response
response = self._give_response_single(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\indices\response\refine.py", line 86, in _give_response_single
) = self._service_context.llm_predictor.predict(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\llm_predictor\base.py", line 239, in predict
llm_prediction = self._predict(prompt, **prompt_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\llm_predictor\base.py", line 207, in _predict
llm_prediction = retry_on_exceptions_with_backoff(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\utils.py", line 178, in retry_on_exceptions_with_backoff
return lambda_fn()
^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\llm_predictor\base.py", line 208, in
lambda: llm_chain.predict(**full_prompt_args),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chains\llm.py", line 252, in predict
return self(kwargs, callbacks=callbacks)[self.output_key]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chains\base.py", line 166, in call
raise e
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chains\base.py", line 160, in call
self._call(inputs, run_manager=run_manager)
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chains\llm.py", line 92, in _call
response = self.generate([inputs], run_manager=run_manager)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chains\llm.py", line 102, in generate
return self.llm.generate_prompt(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chat_models\base.py", line 223, in generate_prompt
return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chat_models\base.py", line 121, in generate
raise e
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chat_models\base.py", line 111, in generate
self._generate_with_cache(
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chat_models\base.py", line 255, in _generate_with_cache
return self.generate(
^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chat_models\openai.py", line 359, in generate
response = self.completion_with_retry(messages=message_dicts, **params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chat_models\openai.py", line 307, in completion_with_retry
return completion_with_retry(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\tenacity_init
.py", line 289, in wrapped_f
return self(f, *args, **kw)
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\tenacity_init
.py", line 379, in call
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\tenacity_init
.py", line 314, in iter
return fut.result()
^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures_base.py", line 401, in __get_result
raise self.exception
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\tenacity_init
.py", line 382, in call
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain\chat_models\openai.py", line 305, in _completion_with_retry
return self.client.create(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\api_resources\chat_completion.py", line 25, in create
return super().create(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 153, in create
response, _, api_key = requestor.request(
^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\api_requestor.py", line 230, in request
resp, got_stream = self._interpret_response(result, stream)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\api_requestor.py", line 624, in _interpret_response
self._interpret_response_line(
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\api_requestor.py", line 687, in _interpret_response_line
raise self.handle_error_response(

There seems to be a cache during the Q&A process.

image

As shown in the picture, I uploaded a wiki on machine learning and asked a question. However, the reply I received was from my previously uploaded review.txt file, even though I had already deleted it and restarted the project.

API Key

For the life of me I can't figure out how to get the OpenAI API key working in react example. Whenever I upload a file it says:

INFO:openai:error_code=invalid_api_key error_message='Incorrect API key provided: your key*here. You can find your API key at https://platform.openai.com/account/api-keys.' error_param=None error_type=invalid_request_error message='OpenAI API error received' stream_error=False

I have supplied my api key as an environment variable. I can't even find the text "your key*here" anywhere in this repository so I have no idea where it's coming from.

Any ideas?

Running Project Problem: "Address already in use" Error

`
(llama_index) user@user:~/Desktop/llama_index_starter_pack/flask_react$ sh launch_app.sh
index_server running...
initializing index...
Traceback (most recent call last):
File "/home/user/Desktop/llama_index_starter_pack/flask_react/./index_server.py", line 82, in
server = manager.get_server()
^^^^^^^^^^^^^^^^^^^^
File "/home/user/anaconda3/envs/llama_index/lib/python3.11/multiprocessing/managers.py", line 524, in get_server
return Server(self._registry, self._address,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/anaconda3/envs/llama_index/lib/python3.11/multiprocessing/managers.py", line 156, in init
self.listener = Listener(address=address, backlog=16)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/anaconda3/envs/llama_index/lib/python3.11/multiprocessing/connection.py", line 447, in init
self._listener = SocketListener(address, family, backlog)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/anaconda3/envs/llama_index/lib/python3.11/multiprocessing/connection.py", line 590, in init
self._socket.bind(address)
OSError: [Errno 98] Address already in use

`
when i run flask_demo.py script i get the following error:

from .._internal import _plain_int ImportError: cannot import name '_plain_int' from 'werkzeug._internal' (/home/user/anaconda3/envs/llama_index/lib/python3.11/site-packages/werkzeug/_internal.py)

  1. i clone the repo.
  2. download the all requirements with "pip install -r requirements.txt" .
  3. when i write "sh launch_app.sh" to console, i get the first error

Please help me about this error. Thanks...

question in flask_react

In the folder of flask_react, the file "index_server.py" uses "GPTSimpleVectorIndex" to build indexes . why do not use "GPTVectorStoreIndex" instead? what are different between them?

and is it possible to update the repo with the latest version of llama (0.6.14)? Thanks.

Kind regards.
Kai

I can't run Flask backend.

!!! Help me !!!

I ran the commands in the readme to install all dependencies.

conda create --name llama_index python=3.11
pip install -r requirements.txt

But I can't run the index_server.py and that occurs these errors.
image
image
If you have experience with this, Help me Please!!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.