Find answers from the community

Home
Members
Killian_
K
Killian_
Offline, last seen 2 weeks ago
Joined September 25, 2024
Hello, i'm facing a little issue with code that i use to index documents in my database. it returns the following error:
Traceback (most recent call last):
File "c:\Projets\test IA in DB\local index\LocalIndex.py", line 11, in <module>
from llama_index.llms.azure_openai import AzureOpenAI
File "C:\Users\sxd-i\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\llama_index\llms\azure_openai__init__.py", line 1, in <module>
from llama_index.llms.azure_openai.base import (
File "C:\Users\sxd-i\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\llama_index\llms\azure_openai\base.py", line 5, in <module>
from llama_index.core.bridge.pydantic import Field, PrivateAttr, root_validator
ImportError: cannot import name 'root_validator' from 'llama_index.core.bridge.pydantic' (C:\Users\sxd-i\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\llama_index\core\bridge\pydantic.py)

here is the code :
Plain Text
import os
import pymongo
import ModelDef
from llama_index.core import VectorStoreIndex, StorageContext, SimpleDirectoryReader, set_global_service_context
from llama_index.llms.azure_openai import AzureOpenAI
from llama_index.embeddings.azure_openai import AzureOpenAIEmbedding
from llama_index.core.indices.vector_store.base import VectorStoreIndex
from llama_index.vector_stores.mongodb import MongoDBAtlasVectorSearch
from llama_index.core import Settings
from llama_index.core.indices.vector_store import VectorStoreIndex
import os
import pymongo
import json
import ModelDef
from flask import Flask, request

# ---------------------------
# Constantes de l'application
# ---------------------------

# Définition des models de déploiement AI

_modelGPT4o = ModelDef.ModelGPT("gpt-4o", "gpt-4o", "2024-10-21")
_modelAda2 = ModelDef.ModelGPT("ada2", "text-embedding-ada-002", "2024-10-21")

_server4o = ModelDef.ServerGPT("gpt4o", "https://.azure.com", "26f3ea90247b1a9286057d53c2539", "c59f1006a64015a7b083ed29", "eastus2", _modelGPT4o, _modelAda2)

_models = [ _server4o]
_model = _models[0]

# Constants

_index = "LeJourSeLeveIFC"
_directory = "C:\\Projets\\ifcdoctest"
_mongoURI = os.environ["MONGO_URI"] = "url of mongo data base"

# ----------------------
# Démarrage du programme
# ----------------------

# Initialisation OpenAI

print("Initialisation OpenAI...")

llm = AzureOpenAI(
    #model=_model.ChatModel.Model,
    #deployment_name=_model.ChatModel.Name,
    api_key=_model.Key1,
    azure_endpoint=_model.Server,
    api_version=_model.ChatModel.ApiVersion,
)

embed_model = AzureOpenAIEmbedding(
    model=_model.LearningModel.Model,
    deployment_name=_model.LearningModel.Name,
    api_key=_model.Key1,
    azure_endpoint=_model.Server,
    api_version=_model.LearningModel.ApiVersion,
)
#Settings.llm = AzureOpenAI(model=llm)
#Settings.embed_model = AzureOpenAIEmbedding(model=_modelAda2)
#service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)
#set_global_service_context(service_context)
# Initialisation des paramètres pour les requètes sur MongoDB Atlas
print("Initialisation MongoDB...")

mongodb_client = pymongo.MongoClient(_mongoURI)
store = MongoDBAtlasVectorSearch(mongodb_client, db_name=_index)
storage_context = StorageContext.from_defaults(vector_store=store)

# On parcours chaque fichier
print("Démarrage de l'importation...")

reader = SimpleDirectoryReader(_directory, recursive=True, encoding="latin-1", required_exts=[".pdf", ".docx", ".pptx", ".csv", ".txt"])

for docs in reader.iter_data():
        print("F > " + docs[0].metadata['file_name'])
        VectorStoreIndex.from_documents(docs, storage_context=storage_context)
# Fin du programme

print("Terminée.")
6 comments
L
K
Hello, I'm posting again because I still have a problem with my vector store which doesn't retrieve the document from my index (stored in my mongo database), Whitefang try to help me last week on this subject but it doesn't resolved the problem. My vector store still retrieve an empty response. Here is my code, I hope somone can suggest me something else, here is my code :
28 comments
W
K
Hello guys, I'm facing an issue on mu chatbot. It's being a long time i didn't run my chatbot because i was training my GPT AI, I updated my python package and run my query fonctions and after my query returns "empty response". It did never return this message. Can you help me ? here is the code of my query:
Plain Text
        # Récupération info model

        model = GetModel(requestDTO.Model)

        # Initialisation OpenAI

        llm = AzureOpenAI(
            model=model.ChatModel.Model,
            deployment_name=model.ChatModel.Name,
            temperature=requestDTO.Temperature,
            api_key=model.Key1,
            azure_endpoint=model.Server,
            api_version=model.ChatModel.ApiVersion,
        )

        embed_model = AzureOpenAIEmbedding(
            model=model.LearningModel.Model,
            deployment_name=model.LearningModel.Name,
            api_key=model.Key1,
            azure_endpoint=model.Server,
            api_version=model.LearningModel.ApiVersion,
        )

        Settings.llm = llm
        Settings.embed_model = embed_model
        Settings.context_window = _contextWindow
        Settings.num_output = _numOutput

         # Génération de l'historique

        messages = []

        if (requestDTO.History != None):
            for item in requestDTO.History:
                messages.append(ChatMessage(role=item.Type.lower(), content=item.Prompt))
      
        # Initialisation des paramètres pour les requètes sur MongoDB Atlas

        mongodb_client = pymongo.MongoClient(_mongoURI)
        store = MongoDBAtlasVectorSearch(mongodb_client, db_name=requestDTO.Index)

        # Initialisation de l'index via les index sur MongoDB Atlas
        # Et inversement, commenter/décommenter si on veut juste query l'index existant
        # build index
        
        vector_index = VectorStoreIndex.from_vector_store(store)

        # configure retriever
        
        retriever = VectorIndexRetriever(index=vector_index, similarity_top_k=requestDTO.LinkNumber)
        
        # configure response synthesizer, ici on peut chosir le mode réponse pour la query(ici on peut influer sur la maniere dont le contexte et le prompt sont itéré sur la query)
        
        response_synthesizer = get_response_synthesizer(response_mode=GetResponseMode(requestDTO.Mode), text_qa_template=qa_template)
        
        # assemble query engine, o recupere l'index grace au retriver et aussi le mode de reponse du "ResponseMode.TREE_SUMMARIZE" via response_synthesizer 
        
        query_retreiver = RetrieverQueryEngine(retriever=retriever, response_synthesizer=response_synthesizer)

        # Partie permettant de créer la réponse

        #query_engine = vector_index.as_query_engine(text_qa_template=qa_template)
        #gpt_result = query_engine.query(requestDTO.Prompt)

        gpt_result = query_retreiver.query(requestDTO.Prompt)

        resultDTO = ServiceQueryResponse.ServiceQueryResponseResultDTO(gpt_result.response, [])
        
        for item in gpt_result.source_nodes:
            node = ServiceQueryResponse.ServiceQueryResponseNodeDTO(item.node.extra_info.get("file_name"), item.node.extra_info.get("page_label"), item.node.text, item.score)
            resultDTO.Nodes.append(node)

        # Construction de la réponse

        responseDTO = ServiceQueryResponse.ServiceQueryResponseDTO(False, None, resultDTO)

        # Terminée, on envoi la réponse définitive

        return GenerateQueryResponse(requestDTO, responseDTO), 200
    
    except Exception as error:

        return str(error), 400
17 comments
W
K
Hello, this time i'm not facing an issue, i need to do rag with this query but i don't really understand how it works in the docs. Can you help me doing rag? Here is my query :

Plain Text
        mongodb_client = pymongo.MongoClient(_mongoURI)
        store = MongoDBAtlasVectorSearch(mongodb_client, db_name=indexName)

        # Initialisation de l'index via les index sur MongoDB Atlas
        # Et inversement, commenter/décommenter si on veut juste query l'index existant
        # build index
        index = VectorStoreIndex.from_vector_store(store)


        # configure retriever
        retriever = VectorIndexRetriever(
            index=index,
        )
        # configure response synthesizer
        response_synthesizer = get_response_synthesizer(
            response_mode= ResponseMode.TREE_SUMMARIZE,
        )
        # Template obligatoire du system prompt définissant le comprtement du LLM)

        qa_template = Prompt(requestDTO.get_system_template())
        
        if not qa_template or qa_template == "" or qa_template == None:
            responseDTO = ServiceQueryResponse.ServiceQueryResponseDTO(True, "Un historique de type 'System' est obligatoire.", None)        
            return GenerateQueryResponse(requestDTO, responseDTO), 400
        
        # assemble query engine
        query_engine = RetrieverQueryEngine(
            retriever=retriever,
            response_synthesizer=response_synthesizer,
        )

        #query_engine = query_engine.query(similarity_top_k=requestDTO.LinkNumber,text_qa_template=qa_template)


        # Partie permettant de créer la réponse

        query_engine = index.as_query_engine(similarity_top_k=requestDTO.LinkNumber,text_qa_template=qa_template)
        query_text = requestDTO.Prompt
        gpt_result = query_engine.query(query_text)



        resultDTO = ServiceQueryResponse.ServiceQueryResponseResultDTO(gpt_result.response, answer.message.content, [])
        
        for item in gpt_result.source_nodes:
            node = ServiceQueryResponse.ServiceQueryResponseNodeDTO(item.node.extra_info.get("file_name"), item.node.extra_info.get("page_label"), item.node.text, item.score)
            resultDTO.Nodes.append(node)



        # Construction de la réponse
        responseDTO = ServiceQueryResponse.ServiceQueryResponseDTO(False, None, resultDTO)
        # Terminée, on envoi la réponse définitive

        return GenerateQueryResponse(requestDTO, responseDTO), 200
1 comment
W
Hello everyone, when i was working on my program two days ago, I faced an issue that is the code i made doesn't work with the new azure instance of GPT-4o. Can you tell me if my query is good? I need to know if it can works with "gpt-4o" or not. And if you can help me update maybe the query if my version too far from the latest^^

Here is my code :
13 comments
K
W
K
Killian_
·

hello,

hello,

I came back with a little error that i don't really understand:

i didn't find any anwser about this error in llamaindex docs, and i'm not using "Docx" document so why should i use "DocxReader", can someone help me understand?
9 comments
L
K
W
hello, i'm facing an issue, i want to index something like 150 document in a row but this take too long (about 1h or more or never end), is there a way to make the code down here index one document return the status(200) and restart with the following document until all document are indexed?


dossier = requestDTO.Index

# Initialisation des paramètres pour les requètes sur MongoDB Atlas

mongodb_client = pymongo.MongoClient(_mongoURI)
db_name = f"{dossier}"
store = MongoDBAtlasVectorSearch(mongodb_client, db_name=db_name)

storage_context = StorageContext.from_defaults(vector_store=store)

# Création ou mise à jour d'un index à partir de documents dans le dossier 'Sources'1
set_global_service_context(service_context)
documents = SimpleDirectoryReader("./Sources/Zephyr").load_data()
#index = VectorStoreIndex.from_documents(documents, service_context=service_context, storage_context=storage_context)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)

#while documents:
# index.add_documents([documents], storage_context=storage_context)


responseDTO = IndexCreationResponse.IndexCreationResponseDTO(False, None, "L'index à bien été créé ou a été mis à jour.")

# Terminée, on envoi la réponse définitive

return GenerateIndexResponse(requestDTO, responseDTO), 200
4 comments
K
L
heelo, I'm coding a script who that store my index in a mongo database, i'm using flask mongodb openai llama_index and langchain. when i excecute the code i get this error "StorageContext has no attribute callback manager", how can i fix this ?

here's the code that don't work :
mongodb_client = pymongo.MongoClient(_mongoURI)
db_name = f"{dossier}"
store = MongoDBAtlasVectorSearch(mongodb_client, db_name=db_name)

storage_context = StorageContext.from_defaults(vector_store=store)

# Création ou mise à jour d'un index à partir de documents dans le dossier 'Sources'

documents = SimpleDirectoryReader("./Sources/5-1-placement.pdf").load_data()
index = VectorStoreIndex.from_documents(documents, service_context=storage_context)

responseDTO = IndexCreationResponse.IndexCreationResponseDTO(False, None, "L'index à bien été créé ou a été mis à jour.")
28 comments
K
W
Hello, I'm facing an issue while indexing txt files into my mongodb database. When i store my documents in the database the encoding change and i don't know why. I check my files and they're all enbcoded in "utf-8".
Here is my code :

print("Initialisation OpenAI...")

llm = AzureOpenAI(
model=_model.ChatModel.Model,
deployment_name=_model.ChatModel.Name,
api_key=_model.Key1,
azure_endpoint=_model.Server,
api_version=_model.ChatModel.ApiVersion,
)


embed_model = AzureOpenAIEmbedding(
model=_model.LearningModel.Model,
deployment_name=_model.LearningModel.Name,
api_key=_model.Key1,
azure_endpoint=_model.Server,
api_version=_model.LearningModel.ApiVersion,
)


Settings.llm = llm
Settings.embed_model = embed_model
Settings.context_window = _contextWindow
Settings.num_output = _numOutput

//Initialisation des paramètres pour les requètes sur MongoDB Atlas

print("Initialisation MongoDB...")

mongodb_client = pymongo.MongoClient(_mongoURI)
store = MongoDBAtlasVectorSearch(mongodb_client, db_name=_index)

storage_context = StorageContext.from_defaults(vector_store=store)

//On parcours chaque fichier

print("Démarrage de l'importation...")


reader = SimpleDirectoryReader(_directory, recursive=True, encoding="utf-8", required_exts=[".pdf", ".docx", ".pptx", ".csv", ".txt", ".xml", ".dng"])

for docs in reader.iter_data():
print("F > " + docs[0].get_text() )
VectorStoreIndex.from_documents(docs, storage_context=storage_context)


It seems like it's the variable "VectorStoreIndex" which change the encoding, so my question is : Can i force "VectorStoreIndex" to encode in utf-8 ? If yes, How can i do taht?
1 comment
L
My question is : Is text-ebedding-3-large is working with llama_index and AzureOpenai ?
39 comments
K
W
hello, i'm facing an issue when it comes to install all the library for my app running, i don't understand how to instal those library :
34 comments
W
K