Comments (5)
The error "value is not a valid dict (type=type_error.dict)" typically occurs when a function or method expects a dictionary but receives a different type. In the context of the PremAI
client from the llama_index
library, this error might be related to the fields in the PremAI
class, which uses Pydantic for data validation.
To resolve this error, ensure that any input expected to be a dictionary is indeed a dictionary. For example, the repositories
and additional_kwargs
fields in the PremAI
class are expected to be dictionaries:
repositories: Optional[dict] = Field(
description="Add valid repository ids. This will be overriding existing connected repositories (if any) and will use RAG with the connected repos."
)
additional_kwargs: Optional[dict] = Field(
description="Add any additional kwargs. This may override your existing settings."
)
If you are initializing or updating these fields, make sure the values are dictionaries. Here is an example of how to correctly initialize a PremAI
instance:
premai_instance = PremAI(
project_id=123,
premai_api_key="your_api_key",
model="your_model",
system_prompt="your_system_prompt",
max_tokens=128,
temperature=0.1,
max_retries=1,
repositories={"repo_id": "repo_value"}, # Ensure this is a dictionary
additional_kwargs={"key": "value"} # Ensure this is a dictionary
)
If you are passing data to a method that expects a dictionary, ensure the data is correctly formatted. For example:
premai_instance.repositories = {"repo_id": "repo_value"} # Correctly formatted dictionary
premai_instance.additional_kwargs = {"key": "value"} # Correctly formatted dictionary
In your specific case, the error occurs when calling the chat
method. The LLMChatEndEvent
class expects the response
field to be of type Optional[ChatResponse]
, not a dictionary. Ensure that the response
being passed is of the correct type:
class LLMChatEndEvent(BaseEvent):
"""LLMChatEndEvent.
Args:
messages (List[ChatMessage]): List of chat messages.
response (Optional[ChatResponse]): Last chat response.
"""
messages: List[ChatMessage]
response: Optional[ChatResponse]
@classmethod
def class_name(cls):
"""Class name."""
return "LLMChatEndEvent"
The ChatResponse
class is defined as follows:
class ChatResponse(BaseModel):
"""Chat response."""
message: ChatMessage
raw: Optional[dict] = None
delta: Optional[str] = None
logprobs: Optional[List[List[LogProb]]] = None
additional_kwargs: dict = Field(default_factory=dict)
def __str__(self) -> str:
return str(self.message)
Ensure that the response
being passed to LLMChatEndEvent
is an instance of ChatResponse
and not a dictionary [1][2].
To continue talking to Dosu, mention @dosu.
from llama_index.
@Anindyadeep for whatever reason, prem-ai is returning a list of messages instead of a single message.
I have no idea why this logic was added, seems I missed this in #13836
from llama_index.
@Anindyadeep ah, you also made that PR, perfect 😅
We can only return a single ChatResponse from llm.chat()
, but here we are returning a list. Thus, premai is not following the return type
from llama_index.
@Anindyadeep ah, you also made that PR, perfect 😅
We can only return a single ChatResponse from
llm.chat()
, but here we are returning a list. Thus, premai is not following the return type
I see, let me make that changes in a PR, thanks for pointing it out
from llama_index.
Hey @logan-markewich, I added a fix, and it is working from my side, hopefully it should fix things.
from llama_index.
Related Issues (20)
- [Bug]: LanceDB get_nodes() method always only returns 10 nodes HOT 1
- [Feature Request]: add store to connect searxng as RAG source
- [Bug]: TypeError: RESTfulChatModelHandle.chat() got an unexpected keyword argument 'prompt' HOT 3
- [Bug]: HuggingFaceEmbedding和OpenLLM依赖的llama-index-core版本不一样,同时使用两个类,必有一个报错 HOT 3
- [Question]: how to use SimpleChatEngine.astream_chat HOT 2
- [Question]: what is the mean of the concept of community? HOT 4
- [Question]: How to get all the nodes from the local Neo4jPropertyGraphStore? HOT 1
- [Question]: Does SimpleDirectoryReader intentionally not support Path for the input_dir arguement? HOT 1
- [Question]: VectorIndexRetriever only by determined metadata field HOT 6
- [Bug]: Neo4J PropertyGraphIndex.from_documents: RuntimeError: Event loop is closed HOT 6
- [Question]: Evaluating RAG retrieval HOT 12
- [Bug]: Unnecessary warning in Huggingface LLM when tokenizer is passed as a function argument HOT 1
- [Question]: Workflows/Agents Equivalent to LangGraph Checkpoints? HOT 1
- [Question]: llama-parse + GoogleDriveReader HOT 1
- [Question]: indexing nodes with qdrant throws error “list object has no attribute _id” HOT 1
- [Question]:AttributeError: 'AzureOpenAI' object has no attribute 'generate' HOT 2
- [Question]: Is it possible to filter ObjectIndex by additional metadata? HOT 7
- [Bug]: AttributeError: 'SQLDatabase' object has no attribute 'get_single_table_info' HOT 6
- Use new sparse embeddings class in vector stores that support sparse
- [Bug]: predict_and_call fails with Ollama Mistral on Python 3.10.11 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llama_index.