File size: 1,315 Bytes
a2ee974
 
 
 
5dd704c
 
e619c67
a2ee974
5dd704c
a2ee974
f65d23a
b5eb0e7
a2ee974
 
f65d23a
3d41135
a6bb63b
a2ee974
 
5dd704c
 
 
 
 
175dfae
 
5dd704c
175dfae
5dd704c
 
 
175dfae
 
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
# Created by Leandro Carneiro at 19/01/2024
# Description: 
# ------------------------------------------------
from langchain_openai import ChatOpenAI
from langchain_together import Together

import os

def invoke_llm(context, task, model):
    prompt = f"""You are an assistant of a newspaper. 
                 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}>
                 Answer here:
              """

    if model == 'openai':
        llm=ChatOpenAI(model_name="gpt-3.5-turbo",
                           temperature=0.3,
                           openai_api_key=os.environ['OPENAI_KEY'],
                           max_tokens=1000)
        result = llm.invoke(prompt)
        return result.content
    else:
        llm=Together(model="mistralai/Mixtral-8x7B-Instruct-v0.1",
                           temperature=0.3,
                           together_api_key=os.environ['TOGETHER_KEY'],
                           max_tokens=1000)
        result = llm.invoke(prompt)
        return result