#Summarize businesses with GPT

1 messages · Page 1 of 1 (latest)

worn dagger
#

Hello everyone, i am about to embark on a project with GPT, and i am hoping to get some help.

You see, the idea is to have a page where different companies can instert links (in the form of URLs) to their website or products. Then the goal is to have the AI read the contents of the website and generate a summary of the given company or product. Like who is the company? What is their mission? What do they do?

My initial idea was to create a webscraper using Python, in order to extract the text from the website. This text would then be prompted to a GPT assistant which would summarize the contents of the website.

Is this feasible? Would this be the most efficient way to do it? Are there other, more reliable ways to achieve this goal?

Thanks in advance 👋

ember imp
worn dagger
#

Hey Paillat. I've managed to create a script that extracts text from a given website. The text then gets summarized with GPT-3.5, then the summarized section of text gets passed to a GPT assistant, utilizing GPT-4-turbo to create a final report on a company.

Now my current task is to pull the answer created by the assistant, along with the formatting of its answer, and display it on a GUI. Could i retrieve the message from my assistant along with its formatting (e.g headers) and just save it in a variable?

worn dagger
#

i am having trouble with making my assistant export a JSON object with my answer. I have tried defining a function, that contains the relevant parameters for it to fill out. But when i use model_dump_json() it doesn't send back anything?

ember imp
worn dagger
#

ofcourse! Give me a second.

#

my python code is:

def create_campaign(self, summary):
    run_campaign = self.client.beta.threads.create_and_run(
        assistant_id=ASSISTANT_ID,
        thread={
            "messages": [
                {"role": "user", "content": summary}
            ]

        }
    )

    single_message = self.client.beta.threads.messages.retrieve(
        message_id=MESSAGE_ID,
        thread_id=THREAD_ID
    )

    json_data = run_campaign.model_dump_json()

    print(json_data)
#

and the accompanying function for my assistant is:

#

{
"name": "campaign_generated",
"parameters": {
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "The title of the generated campaign."
},
"company_name": {
"type": "string",
"description": "The name of the company, which you have generated the campaign for."
},
"campaign_description": {
"type": "string",
"description": "The campaign itself, include formatting such as headers."
}
},
"required": [
"title",
"company_name",
"campaign_description"
]
},
"description": "Convert the generated campaign into a JSON object"
}

#

i have tested my assistant about 6 times. So far it has only exported a JSON object once. And even then, i am having trouble accessing the aforementioned JSON object

#

also, the outputted JSON file, does not adhere to the structure i defined. Am i completely off track? 😅

ember imp
# worn dagger also, the outputted JSON file, does not adhere to the structure i defined. Am i ...

You should not use model_dump_json(). Instead use the content string of the response and load it with something like the json python library. Furthermore, if I were you I would not use assistants for this task. Rather what I would do is using normal chat with json mode, a good system prompt that explains the json formatting and the content in a message. Specifically, even if using assistants, I do no think a function is the best idea in this case.

Alternatively, you could still use functions, but make sure to specify clearly how to use your functions in the system prompt and not only in the function's description fields.

worn dagger
#

I will certainly take that up for consideration. However, my assistant is using several files through the "retrieve" option to generate its answers.

In regards to using the content string using a JSON library. Do you have any code examples of this?

worn dagger
#

Follow up question, when would assistants be a viable choice?

ember imp
# worn dagger I will certainly take that up for consideration. However, my assistant is using ...

Your situations is especially tricky since the assistants api does not support json mode, and retrieval is only available trough that api.

When using a functions with assistants, you will NOT be able to access messages like you did in your code, since, just after the assistant filled up the json, it will set its state to requires_action which will not create any message, just stop. The only case out of six when your assistant responded is likely the actual only time it behaved incorrectly . Once it is in that state, you will need to give a response to the action performed, in our case crating your campaign summary, for example summary created successfully. This will give you the json of the function for your further usage.

You can see an example on how doing this in python here.

ember imp
worn dagger
#

Allright, i have migrated from assistants to chat completions. My program actually works as intended! Amazing help Paillat, your assistance is very much appreciated. wowgummy

I have one more question though. In regards to speed. The rest of my script executes fairly fast (something like 2-3 seconds). Currently my biggest bottleneck, in regards to speed, is my chat completions. In total, my chat completions take around 29-30 seconds to complete their tasks.

So, my question is. Is there a way to speed up the chat completion processes? Or is that purely dependent on my prompt size, complexity of the task I've assigned to the AI and the OpenAI backend?