Giter Club home page Giter Club logo

Comments (5)

dosubot avatar dosubot commented on September 17, 2024 2

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.

logan-markewich avatar logan-markewich commented on September 17, 2024

@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.

logan-markewich avatar logan-markewich commented on September 17, 2024

@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 avatar Anindyadeep commented on September 17, 2024

@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.

Anindyadeep avatar Anindyadeep commented on September 17, 2024

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)

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.