langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
49.01k stars 7.01k forks source link

The Logs&Ann will lose some conservation. #1082

Closed jacksonwen001 closed 1 year ago

jacksonwen001 commented 1 year ago

Hi All, I integrated the official api in myself app. But I noticed it will lose some conservation in "Logs && Ann." and I already set the "Pre promo" in the web page(I definitely click the publish button). But it seems doesn't work. Did I miss something?

Below is the tech details:

Dify version: Cloud API: https://api.dify.ai/v1

crazywoola commented 1 year ago

Can you provide your curl command? and please do not send app secret in it.

jacksonwen001 commented 1 year ago

Actually I write it by using fastapi. here is my code:

 def replyByDify(self, customer_name: str, question: str) -> str:
        conversation_id = redis_client.get_value(customer_name)
        body = {
              "inputs": {},
              "query": question,
              "response_mode": "streaming",
              "conversation_id": conversation_id if conversation_id is not None else "",
              "user": customer_name,
         }

        try:
            print(body)
            answers = []
            url = "https://api.dify.ai/v1/chat-messages"
            headers = {
                'Authorization': 'Bearer <apikey>',
                'Content-Type': 'application/json'
            }

            with requests.post(url=url, headers=headers, data=json.dumps(body), stream=True) as response: # noqa
                for chunk in response.iter_lines():
                    if chunk:
                        try:
                            task = json.loads(chunk.decode().replace("data: ", ""))
                            answers.append(task['answer']) # noqa
                            conversation_id = task['conversation_id']
                        except Exception as e:
                            print(e)

            redis_client.set_value(customer_name, conversation_id) # noqa
            return ''.join(answers)
        except Exception as e:
            print(e)
jacksonwen001 commented 1 year ago

Maybe I got the point. since I use the same conservation_id. so I cannot see the logs in Logs&Ann since it archived to the old conservation_id. it will not add new item in list. but what problems with "pre-promo"? the "pre promo" no effect if I use the old conservation_id?

update

I did the testing. the answer is yes. if you always using the same conservation_id, it will no effect for pre-promo setting until you use the new one

It should be do some improve, right? image that if i have the customer using the channel to chat with me, and some day, I upgrade the backend(such as apply some promo). and it must renew the conservation_id and lost the memory otherwise it cannot apply the upgrade. it is strange.

takatost commented 1 year ago

So, here's the thing: every conversation follows the app's prompt engineering configuration version that was set when it was created. When you make changes to the prompt engineering configuration, it actually creates a new version. From then on, any new conversations will use the new configuration, while existing conversations will continue to use the old one.

jacksonwen001 commented 1 year ago

can we add the function, such like 'apply to all conservation' or "apply to new conservation"? there are many scenarios like that we want to upgrade bot and we don't want to lose the context with customer

crazywoola commented 1 year ago

can we add the function, such like 'apply to all conservation' or "apply to new conservation"? there are many scenarios like that we want to upgrade bot and we don't want to lose the context with customer

Not for now, but we will consider this in the future.