ChatGPT icon indicating copy to clipboard operation
ChatGPT copied to clipboard

API to get auto-generated titles

Open Jamminroot opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. Webapp provides nicely summarized conversations. It'd be great if API you provide could use them

Describe the solution you'd like Perfect (yet, likely impossible) solution would be to return title with ask() callm, but since it's probably a separate call which might happen later, other solution would be to add new method def get_title(id:str) -> str: or something like that.

Thanks for the nice library! And have a look at my other issue when possible (https://github.com/acheong08/ChatGPT/issues/418) :) Couldn't really resolve it myself since im not from the web\python world. Cheers o/

Jamminroot avatar Jan 07 '23 16:01 Jamminroot

Looking at how webapp works, it doesn't look too complicated, or even long to process the request. smth like

    def gen_title(self, id, message_id):
        url = BASE_URL + f"backend-api/conversation/gen_title/{id}"
        print(f"Request to '{url}")
        response = self.session.post(url, data=f'{{"message_id": {message_id}, "model": "text-davinci-002-render"}}')
        self.check_response(response)
        data = json.loads(response.text)
        return data
-def ask(self, prompt, conversation_id=None, parent_id=None):
+def ask(self, prompt, conversation_id=None, parent_id=None, gen_title = False):
...
+new_conv = data["conversation_id"] is None
...
- return {
-     "message": message,
-     "conversation_id": self.conversation_id,
-     "parent_id": self.parent_id,
- }
+ res = {
+         "message": message,
+         "conversation_id": self.conversation_id,
+         "parent_id": self.parent_id,
+ }
+ if gen_title and new_conv:
+     try:
+         res["title"] = self.gen_title(self.conversation_id, self.parent_id)
+     except:
+         res["title"] = prompt[:16] + ("..." if len(prompt)>16 else "")
+         
+ return res

Not opening a PR as I suppose my codestyle is off

Jamminroot avatar Jan 07 '23 17:01 Jamminroot

tbh when I was testing for the Dec15 update features I saw this call in the network log but I didnt think it was important enougn to add, but if you feel its important, go make a PR

DiamondDemon669 avatar Jan 07 '23 18:01 DiamondDemon669

Yeah, I'll arrange one - fixed an error initial sample code above had

Jamminroot avatar Jan 07 '23 18:01 Jamminroot

https://github.com/acheong08/ChatGPT/pull/431

Jamminroot avatar Jan 07 '23 19:01 Jamminroot