|
9 | 9 | from dotenv import find_dotenv, load_dotenv |
10 | 10 | from langchain.chat_models import ChatOpenAI |
11 | 11 | from langchain.embeddings import OpenAIEmbeddings |
12 | | - |
13 | | -# 1.) wrappers |
14 | 12 | from langchain.llms.openai import OpenAI |
15 | | - |
16 | | -# 3.) prompt templates |
17 | 13 | from langchain.prompts import PromptTemplate |
18 | | - |
19 | | -# 2.) models and messages |
20 | 14 | from langchain.schema import HumanMessage, SystemMessage # AIMessage (not used) |
21 | | - |
22 | | -# 6.) embeddings |
23 | 15 | from langchain.text_splitter import Document, RecursiveCharacterTextSplitter |
24 | | - |
25 | | -# 7.) pinecode client |
26 | 16 | from langchain.vectorstores.pinecone import Pinecone |
27 | 17 | from pydantic import BaseModel, ConfigDict, Field # ValidationError |
28 | 18 |
|
29 | 19 |
|
30 | | -# Load environment variables from .env file in all folders |
31 | 20 | # pylint: disable=duplicate-code |
32 | 21 | dotenv_path = find_dotenv() |
33 | 22 | if os.path.exists(dotenv_path): |
|
41 | 30 | raise FileNotFoundError("No .env file found in root directory of repository") |
42 | 31 |
|
43 | 32 | DEFAULT_MODEL_NAME = "text-davinci-003" |
44 | | -pinecone.init(api_key=PINECONE_API_KEY, environment=PINECONE_ENVIRONMENT) # minute 10:43 |
| 33 | +pinecone.init(api_key=PINECONE_API_KEY, environment=PINECONE_ENVIRONMENT) |
45 | 34 |
|
46 | 35 |
|
47 | 36 | class NetecPromptTemplates: |
48 | 37 | """Netec Prompt Templates.""" |
49 | 38 |
|
| 39 | + sales_role: str = """You are a helpful sales assistant at Netec who sells |
| 40 | + specialized training and exam preparation services to existing customers. |
| 41 | + You provide concise explanations of the services that Netec offers in 100 |
| 42 | + words or less.""" |
| 43 | + |
| 44 | + @classmethod |
| 45 | + def get_properties(cls): |
| 46 | + """return a list of properties of this class.""" |
| 47 | + return [attr for attr in dir(cls) if isinstance(getattr(cls, attr), property)] |
| 48 | + |
50 | 49 | @property |
51 | 50 | def training_services(self) -> PromptTemplate: |
52 | 51 | """Get prompt.""" |
53 | | - template = """ |
54 | | - You are a sales assistant at Netec who sells specialized training and exam prep services to existing customers. |
| 52 | + template = ( |
| 53 | + self.sales_role |
| 54 | + + """ |
55 | 55 | Explain the training services that Netec offers about {concept} |
56 | | - in no more than 100 words. |
57 | 56 | """ |
58 | | - prompt = PromptTemplate(input_variables=["concept"], template=template) |
59 | | - return prompt |
| 57 | + ) |
| 58 | + return PromptTemplate(input_variables=["concept"], template=template) |
| 59 | + |
| 60 | + @property |
| 61 | + def oracle_training_services(self) -> PromptTemplate: |
| 62 | + """Get prompt.""" |
| 63 | + template = ( |
| 64 | + self.sales_role |
| 65 | + + """ |
| 66 | + Note that Netec is the exclusive provide of Oracle training services |
| 67 | + for the 6 levels of Oracle Certification credentials: Oracle Certified Junior Associate (OCJA), |
| 68 | + Oracle Certified Associate (OCA), Oracle Certified Professional (OCP), |
| 69 | + Oracle Certified Master (OCM), Oracle Certified Expert (OCE) and |
| 70 | + Oracle Certified Specialist (OCS). |
| 71 | + Summarize their programs for {concept} |
| 72 | + """ |
| 73 | + ) |
| 74 | + return PromptTemplate(input_variables=["concept"], template=template) |
60 | 75 |
|
61 | 76 |
|
62 | 77 | class SalesSupportModel(BaseModel): |
@@ -98,10 +113,9 @@ def cached_chat_request(self, system_message: str, human_message: str) -> System |
98 | 113 | # pylint: disable=not-callable |
99 | 114 | return self.chat(messages) |
100 | 115 |
|
101 | | - def prompt_with_template(self, concept: str, model: str = DEFAULT_MODEL_NAME) -> str: |
| 116 | + def prompt_with_template(self, prompt: PromptTemplate, concept: str, model: str = DEFAULT_MODEL_NAME) -> str: |
102 | 117 | """Prompt with template.""" |
103 | 118 | llm = OpenAI(model=model) |
104 | | - prompt = NetecPromptTemplates().training_services |
105 | 119 | retval = llm(prompt.format(concept=concept)) |
106 | 120 | return retval |
107 | 121 |
|
|
0 commit comments