Skip to content

Commit 5fac60e

Browse files
authored
Merge pull request #4 from lpm0073/next
chore: add oracle example
2 parents fcf8abc + c072757 commit 5fac60e

File tree

8 files changed

+68
-28
lines changed

8 files changed

+68
-28
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repos:
77
hooks:
88
- id: codespell
99
args: ["--ignore-words=codespell.txt"]
10-
exclude: '\.svg$'
10+
exclude: 'codespell.txt|\.svg$'
1111
- repo: https://github.com/pre-commit/mirrors-prettier
1212
rev: v3.1.0
1313
hooks:

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# 1.0.0 (2023-11-30)
22

3-
43
### Features
54

6-
* first commit ([9fe5fbb](https://github.com/lpm0073/netec-llm/commit/9fe5fbbd03d278a90a7351a4d907a74783e48684))
5+
- first commit ([9fe5fbb](https://github.com/lpm0073/netec-llm/commit/9fe5fbbd03d278a90a7351a4d907a74783e48684))

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Netec Catalogue LLM
1+
# Netec Large Language Models
22

33
A Python [LangChain](https://www.langchain.com/) - [Pinecone](https://docs.pinecone.io/docs/python-client) proof of concept LLM to manage sales support inquiries on the Netec course catalogue.
44

55
## Installation
66

77
```console
8-
git clone https://github.com/lpm0073/langchain-workflows.git
9-
cd langchain-workflows
8+
git clone https://github.com/lpm0073/netec-llm.git
9+
cd netec-llm
1010
make init
1111
make activate
1212
```
@@ -25,6 +25,9 @@ python3 -m models.examples.prompt "You are an expert on businesses located in Me
2525

2626
# example 3 - prompted assistant
2727
python3 -m models.examples.training_services "Microsoft certified Azure AI engineer associate"
28+
29+
# example 4 - prompted assistant
30+
python3 -m models.examples.training_services_oracle "Oracle database administrator"
2831
```
2932

3033
## Requirements

codespell.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OCE

models/examples/training_services.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
"""Sales Support Model (SSM) for the LangChain project."""
33
import argparse
44

5-
from ..ssm import SalesSupportModel
5+
from ..ssm import NetecPromptTemplates, SalesSupportModel
66

77

88
ssm = SalesSupportModel()
9-
9+
templates = NetecPromptTemplates()
1010

1111
if __name__ == "__main__":
1212
parser = argparse.ArgumentParser(description="SSM examples")
1313
parser.add_argument("concept", type=str, help="A kind of training that Netec provides.")
1414
args = parser.parse_args()
1515

16-
result = ssm.prompt_with_template(concept=args.concept)
16+
prompt = templates.training_services
17+
result = ssm.prompt_with_template(prompt=prompt, concept=args.concept)
1718
print(result)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
"""Sales Support Model (SSM) for the LangChain project."""
3+
import argparse
4+
5+
from ..ssm import NetecPromptTemplates, SalesSupportModel
6+
7+
8+
ssm = SalesSupportModel()
9+
templates = NetecPromptTemplates()
10+
11+
if __name__ == "__main__":
12+
parser = argparse.ArgumentParser(description="SSM Oracle examples")
13+
parser.add_argument("concept", type=str, help="An Oracle certification exam prep")
14+
args = parser.parse_args()
15+
16+
prompt = templates.oracle_training_services
17+
result = ssm.prompt_with_template(prompt=prompt, concept=args.concept)
18+
print(result)

models/ssm.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,14 @@
99
from dotenv import find_dotenv, load_dotenv
1010
from langchain.chat_models import ChatOpenAI
1111
from langchain.embeddings import OpenAIEmbeddings
12-
13-
# 1.) wrappers
1412
from langchain.llms.openai import OpenAI
15-
16-
# 3.) prompt templates
1713
from langchain.prompts import PromptTemplate
18-
19-
# 2.) models and messages
2014
from langchain.schema import HumanMessage, SystemMessage # AIMessage (not used)
21-
22-
# 6.) embeddings
2315
from langchain.text_splitter import Document, RecursiveCharacterTextSplitter
24-
25-
# 7.) pinecode client
2616
from langchain.vectorstores.pinecone import Pinecone
2717
from pydantic import BaseModel, ConfigDict, Field # ValidationError
2818

2919

30-
# Load environment variables from .env file in all folders
3120
# pylint: disable=duplicate-code
3221
dotenv_path = find_dotenv()
3322
if os.path.exists(dotenv_path):
@@ -41,22 +30,48 @@
4130
raise FileNotFoundError("No .env file found in root directory of repository")
4231

4332
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)
4534

4635

4736
class NetecPromptTemplates:
4837
"""Netec Prompt Templates."""
4938

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+
5049
@property
5150
def training_services(self) -> PromptTemplate:
5251
"""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+
+ """
5555
Explain the training services that Netec offers about {concept}
56-
in no more than 100 words.
5756
"""
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)
6075

6176

6277
class SalesSupportModel(BaseModel):
@@ -98,10 +113,9 @@ def cached_chat_request(self, system_message: str, human_message: str) -> System
98113
# pylint: disable=not-callable
99114
return self.chat(messages)
100115

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:
102117
"""Prompt with template."""
103118
llm = OpenAI(model=model)
104-
prompt = NetecPromptTemplates().training_services
105119
retval = llm(prompt.format(concept=concept))
106120
return retval
107121

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ max-complexity = 10
3232
exclude = "venv"
3333
extend-exclude = "*__init__.py,*__version__.py,venv"
3434
select = "C101"
35+
36+
[tool.codespell]
37+
skip = '*.svg,models/ssm.py'
38+
ignore-words = 'codespell.txt'

0 commit comments

Comments
 (0)