chatgpt_manager module

class chatgpt_manager.ChatGptManager(openai_token, model='gpt-3.5-turbo', temperature=0.5, max_tokens_messages=300, max_token_summary=500)

Bases: object

from_tuple_to_gpt_input(tuples, role_index, context_index)

Helper method to generate a list of dict from tuples. This method can be used to transform the result of a query on PostgreSQL into a input for ChatGPT

Tuples:

list of Tuples

Role_index:

index where to find the role in each tuple

Context_index:

index where to find the context in each tuple

Returns:

list of dictionaries describying a conversation, e.g. [ {“role”: “system”, “content”: “INITIAL PROMPT”}, {“role”: “assistant”, “content”: “hello message”}, {“role”: “user”, “content”: “Hello Assistan, I Have this problem”} ]

Return type:

list

generate_initial_message(name)

Helper method to generate a first message for system prompt of chatgpt. The method also setup a custom name for the user if INIT_CHATBOT_PROMPT is correctly initialize-

Name:

custom name for the user talking to the chatbot

Returns:

list of dictionaries containing the first message of a conversation with chatGPT, e.g. [ {“role”: “system”, “content”: “INITIAL PROMPT SETTED UP”} ]

Return type:

list

get_chatgpt_response(messages)

Send messages to chatGpt and get answer back

Messages:

List of dictionaries describying a conversation, e.g. [ {“role”: “system”, “content”: “INITIAL PROMPT”}, {“role”: “assistant”, “content”: “hello message”}, {“role”: “user”, “content”: “Hello Assistan, I Have this problem”} ]

Returns:

Subsequent message generated by ChatGPT for the conversation in input, e.g. “This is the solution for your problem

Return type:

str

get_conversation_transcript(conversation, username, botname, role_index, context_index, num_messages)

Helper method to generate a string containing an entire conversation, from a tuple input This can be used to create a correct input for the summerize function

Conversation:

list of tuples containing a conversation

Username:

the name of the user

Botname:

the name of the assistant

Role_index:

index where to find the role in each tuple

Context_index:

index where to find the context in each tuple

Returns:

A string transcript of the conversation

Return type:

str

summarize(conversation)

This method takes as input a conversation transcript and generate a report based on the content

Conversation:

A String containing the entire conversation, e.g. ASSISTAN: questo è un messaggio USER: questa una risposta ASSISTANT: questa è una rispota… Use the helper method get_conversation_transcript to create this input format

Returns:

A summarization of the conversation based on requestes setted up into SUMMARY PROMPT constant

Return type:

str