File size: 1,747 Bytes
a2ee974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Created by Leandro Carneiro at 19/01/2024
# Description: 
# ------------------------------------------------
from langchain_openai import ChatOpenAI

import api_key

def invoke_llm(context, task):
    prompt = f"""You are an assistant of a newspaper. 
                 Do not make up any information, execute the task just based on the given context.
                 The task is delimited by ### and the context is delimited by $$$
                 Write in a formal language and in portuguese language.
                 Execute the task just based on the given context.
                 Your task is: ###{task}###
                 The context is: $$${context}$$$
              """

    llm=ChatOpenAI(model_name="gpt-3.5-turbo",
                       temperature=0,
                       openai_api_key=api_key.OPENAI_KEY,
                       max_tokens=1000)
    result = llm.invoke(prompt)
    return result.content




# def generate_topics(text):
#     prompt = f"""You are an assistant of a newspaper.
#                  Your task is to extract relevant topics of a news and build a concise road map.
#                  Do not make up any information, create the road map just based on the given information.
#                  The road map should be written in a formal language and in portuguese language.
#                  Answer just the information, do not put any title.
#                  The road map should be about the following context: {text}
#               """
#
#     llm=ChatOpenAI(model_name="gpt-3.5-turbo",
#                        temperature=0,
#                        openai_api_key=api_key.OPENAI_KEY,
#                        max_tokens=1000)
#     result = llm.invoke(prompt)
#     return result.content