File size: 740 Bytes
aacc1ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langchain import PromptTemplate, LLMChain
from langchain.llms import OpenAI
import openai
import os



template = """You are given following information and a question. Generate a python code with plotly to find the answer. Provide Text as comments only in code.

Information:
{main_question}
=============
Question:
{sub_question}
Answer:"""

prompt = PromptTemplate(template=template, input_variables=["main_question", "sub_question"])

def set_openai_api_key(api_key):
    openai.api_key = api_key

def generate_plot(main_question, sub_question):
    llm = OpenAI(temperature=0)
    llm_chain = LLMChain(prompt=prompt, llm=llm)
    response = llm_chain.run(main_question=main_question, sub_question=sub_question)
    return response