-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
69 lines (52 loc) · 2.31 KB
/
util.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from langchain.llms.ollama import Ollama
from pandasai.prompts import GeneratePythonCodePrompt
from llm.ais_erniebot import AIStudioErnieBot
import google.generativeai as genai
from langchain.llms.base import LLM
import pandas as pd
from pandasai.llm import OpenAI, LangchainLLM
def get_openai_model(api_key):
return OpenAI(api_token=api_key)
class GeminiLLM(LLM):
def __init__(self, model):
self.model = model
def query(self, prompt):
response = self.model.generate_content(prompt)
return response.text
def __init__(self, model):
self.model = model
self.type = "gemini" # Set type manually
def llm_type(self):
return LLM
def get_gemini_model(api_key):
genai.configure(api_key=api_key)
model = genai.GenerativeModel('gemini-pro')
return LangchainLLM(langchain_llm=model)
def get_openai_ai_model(api_key):
return OpenAI(api_token=api_key)
def get_ollama_model(model_key, base_url):
llm = Ollama(model=model_key, base_url=base_url, verbose=True)
return LangchainLLM(langchain_llm=llm)
def get_baidu_as_model(access_token):
llm_core = AIStudioErnieBot(access_token=access_token, verbose=True)
return LangchainLLM(llm_core)
def get_baidu_qianfan_model(client_id, client_secret):
llm_core = ErnieBotChat(
model_name="ERNIE-Bot",
temperature=0.1,
ernie_client_id=client_id,
ernie_client_secret=client_secret
)
return LangchainLLM(llm_core)
# Function to get a custom prompt template
def get_prompt_template():
instruction_template = """
Using the provided dataframes ('dfs'), analyze this data, and avoid calling dataframe set_index to sort the data during the process.
1. Preparation: If necessary, preprocess and clean the data.
2. Execution: Perform data analysis operations on the data (grouping, filtering, aggregating, etc.).
3. Analysis: Conduct actual analysis (if the user requests a plot chart, please add the following two lines of code in the script to set the font, save and display the result as an image file 'temp_chart.png').
plt.rcParams['font.sans-serif']
plt.rcParams['axes.unicode_minus']=False
"""
custom_template = GeneratePythonCodePrompt(custom_instructions=instruction_template)
return custom_template