Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -1,47 +1,47 @@
|
|
| 1 |
-
from langchain_core.prompts import ChatPromptTemplate
|
| 2 |
-
from langchain_groq import ChatGroq
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
-
from langchain.chains import ConversationChain
|
| 5 |
-
from langchain.memory import ConversationBufferWindowMemory
|
| 6 |
-
from langchain_core.prompts.prompt import PromptTemplate
|
| 7 |
-
import streamlit as st
|
| 8 |
-
import os
|
| 9 |
-
|
| 10 |
-
load_dotenv()
|
| 11 |
-
|
| 12 |
-
# setting up groq api key
|
| 13 |
-
os.environ["GROQ_API_KEY"] = st.secrets.
|
| 14 |
-
|
| 15 |
-
# chat set up
|
| 16 |
-
class DataScienceConsultant:
|
| 17 |
-
def __init__(self, temperature=0.5, model_name="llama3-8b-8192"):
|
| 18 |
-
self.chat = ChatGroq(temperature=temperature, model_name=model_name)
|
| 19 |
-
self.template = """You are a Data Science Consultant. You have over 20 years of experience in the field.
|
| 20 |
-
You are currently working with a client to create synthetic data for their product.
|
| 21 |
-
You don't know anything about the product yet, which is why you want to ask the client some questions to understand the data requirements.
|
| 22 |
-
This is the workflow you have been following:
|
| 23 |
-
1. Converse with the client to understand the data requirements.
|
| 24 |
-
2. Ask questions about the product the client is working on.
|
| 25 |
-
3. Ask for possible columns and the data types.
|
| 26 |
-
4. Ask for the number of rows and the distribution of the data.
|
| 27 |
-
5. Create a Python script that the client can work with to generate the data.
|
| 28 |
-
6. Review the generated code with the client requirements.
|
| 29 |
-
|
| 30 |
-
Return the code to the client for review.
|
| 31 |
-
|
| 32 |
-
Current conversation:
|
| 33 |
-
{history}
|
| 34 |
-
Human: {input}
|
| 35 |
-
AI Assistant:"""
|
| 36 |
-
self.prompt = PromptTemplate(input_variables=["history", "input"], template=self.template)
|
| 37 |
-
self.conversation = ConversationChain(
|
| 38 |
-
prompt=self.prompt,
|
| 39 |
-
llm=self.chat,
|
| 40 |
-
verbose=True,
|
| 41 |
-
memory=ConversationBufferWindowMemory(k=10, ai_prefix="AI Assistant"),
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
def predict(self, input_text):
|
| 45 |
-
return self.conversation.predict(input=input_text)
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 1 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 2 |
+
from langchain_groq import ChatGroq
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from langchain.chains import ConversationChain
|
| 5 |
+
from langchain.memory import ConversationBufferWindowMemory
|
| 6 |
+
from langchain_core.prompts.prompt import PromptTemplate
|
| 7 |
+
import streamlit as st
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
load_dotenv()
|
| 11 |
+
|
| 12 |
+
# setting up groq api key
|
| 13 |
+
os.environ["GROQ_API_KEY"] = st.secrets.groq_api_key
|
| 14 |
+
|
| 15 |
+
# chat set up
|
| 16 |
+
class DataScienceConsultant:
|
| 17 |
+
def __init__(self, temperature=0.5, model_name="llama3-8b-8192"):
|
| 18 |
+
self.chat = ChatGroq(temperature=temperature, model_name=model_name)
|
| 19 |
+
self.template = """You are a Data Science Consultant. You have over 20 years of experience in the field.
|
| 20 |
+
You are currently working with a client to create synthetic data for their product.
|
| 21 |
+
You don't know anything about the product yet, which is why you want to ask the client some questions to understand the data requirements.
|
| 22 |
+
This is the workflow you have been following:
|
| 23 |
+
1. Converse with the client to understand the data requirements.
|
| 24 |
+
2. Ask questions about the product the client is working on.
|
| 25 |
+
3. Ask for possible columns and the data types.
|
| 26 |
+
4. Ask for the number of rows and the distribution of the data.
|
| 27 |
+
5. Create a Python script that the client can work with to generate the data.
|
| 28 |
+
6. Review the generated code with the client requirements.
|
| 29 |
+
|
| 30 |
+
Return the code to the client for review.
|
| 31 |
+
|
| 32 |
+
Current conversation:
|
| 33 |
+
{history}
|
| 34 |
+
Human: {input}
|
| 35 |
+
AI Assistant:"""
|
| 36 |
+
self.prompt = PromptTemplate(input_variables=["history", "input"], template=self.template)
|
| 37 |
+
self.conversation = ConversationChain(
|
| 38 |
+
prompt=self.prompt,
|
| 39 |
+
llm=self.chat,
|
| 40 |
+
verbose=True,
|
| 41 |
+
memory=ConversationBufferWindowMemory(k=10, ai_prefix="AI Assistant"),
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
def predict(self, input_text):
|
| 45 |
+
return self.conversation.predict(input=input_text)
|
| 46 |
+
|
| 47 |
+
|