jina-ai / serve

☁️ Build multimodal AI applications with cloud-native stack
https://jina.ai/serve
Apache License 2.0
21.14k stars 2.22k forks source link

Topology graph Key Error (After Jina 3.21.0) #6084

Closed ZhihaoAIRobotic closed 1 year ago

ZhihaoAIRobotic commented 1 year ago

Bug Description There is a KeyError: 'type' in the File "/home/lzh/.conda/envs/DIMA/lib/python3.8/site-packages/jina/serve/runtimes/gateway/graph/topology_graph.py", line 90.

image

Solution I have printed the schema_1_properties[property_1], the result is as follows:

image

There is no key named 'type' for Env Info Here is the code for Env Info:

class EnvInfo(BaseDoc):
    env_memory: ShortTermMemory = ShortTermMemory()  # Interaction information of all agent
    history: str = ''
class ShortTermMemory(DocList[Info]):
    def add(self, info: Info):
        if info in self:
            return
        self.append(info)

    def add_batch(self, infos: DocList[Info]):
        for info in infos:
            self.add(info)

    def remember(self, k=0) -> DocList[Info]:
        """Return the most recent k memories, return all when k=0"""
        return self[-k:]

    def remember_news(self, observed: DocList[Info], k=0) -> DocList[Info]:
        """remember the most recent k memories from observed Messages, return all when k=0"""
        already_observed = self.remember(k)
        news = DocList[Info]()
        for i in observed:
            if i.id in already_observed.id:
                continue
            news.append(i)
        return news

    def remember_by_action(self, action: str) -> DocList[Info]:
        """Return all messages triggered by a specified Action"""
        storage_index = InMemoryExactNNIndex[Info]()
        storage_index.index(self)
        query = {'cause_by': {'$eq': action}}
        content = storage_index.filter(query)
        return content

    def remember_by_actions(self, actions: Iterable[str]) -> DocList[Info]:
        """Return all messages triggered by specified Actions"""
        contents = DocList[Info]()
        for action in actions:
            storage_index = InMemoryExactNNIndex[Info]()
            storage_index.index(self)
            query = {'cause_by': {'$eq': action}}
            contents = contents + storage_index.filter(query) # become a list after + operation
        return DocList[Info](contents)
class Info(BaseDoc):
    content: List = []
    instruction: str = ''
    agent_id: str = ''  # the profile of the agent
    role: str = 'user'  # system / user / assistant
    cause_by: str = ''

    @property
    def Info_str(self):
        # prefix = '-'.join([self.role, str(self.cause_by)])
        return f"{self.role}: {self.content}"

    def Info_str_repr(self):
        return self.Info_str()

    def to_dict(self) -> dict:
        return {
            "role": self.role,
            "content": self.content
        }

Environment Python 3.8 Jina>3.21.0

JoanFM commented 1 year ago

How are these Docs chained together? Can you share a Topology of Executors using them as Input and Outulput? you do not need to share what they actually do, just the endpoints and type annotations and the Flow structure.

JoanFM commented 1 year ago

What is the version of docarray and Pydantic in your system?

JoanFM commented 1 year ago

I found a way to reproduce, it should be fixed by #6085

ZhihaoAIRobotic commented 1 year ago

Ok, wait for good news, I will use Jina<3.21.0 temporarily.

JoanFM commented 1 year ago

@ZhihaoAIRobotic the patch has been releassd. Thanks for opening the issue