Skip to content

Commit 5f1b31f

Browse files
committed
Making some tweaks
1 parent 28767b3 commit 5f1b31f

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Labs/app/backend/cosmic_works/cosmic_works_ai_agent.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
load_dotenv("../../.env")
2121
DB_CONNECTION_STRING = os.environ.get("DB_CONNECTION_STRING")
22+
AOAI_ENDPOINT = os.environ.get("AOAI_ENDPOINT")
23+
AOAI_KEY = os.environ.get("AOAI_KEY")
24+
AOAI_API_VERSION = "2023-09-01-preview"
25+
COMPLETIONS_DEPLOYMENT = "completions"
26+
EMBEDDINGS_DEPLOYMENT = "embeddings"
2227
db = pymongo.MongoClient(DB_CONNECTION_STRING).cosmic_works
2328

2429
class CosmicWorksAIAgent:
@@ -30,16 +35,16 @@ class CosmicWorksAIAgent:
3035
def __init__(self, session_id: str):
3136
llm = AzureChatOpenAI(
3237
temperature = 0,
33-
openai_api_version = "2023-09-01-preview",
38+
openai_api_version = AOAI_API_VERSION,
3439
azure_endpoint = os.environ.get("AOAI_ENDPOINT"),
3540
openai_api_key = os.environ.get("AOAI_KEY"),
36-
azure_deployment = "completions"
41+
azure_deployment = COMPLETIONS_DEPLOYMENT
3742
)
3843
self.embedding_model = AzureOpenAIEmbeddings(
39-
openai_api_version = "2023-09-01-preview",
44+
openai_api_version = AOAI_API_VERSION,
4045
azure_endpoint = os.environ.get("AOAI_ENDPOINT"),
4146
openai_api_key = os.environ.get("AOAI_KEY"),
42-
azure_deployment = "embeddings",
47+
azure_deployment = EMBEDDINGS_DEPLOYMENT,
4348
chunk_size=10
4449
)
4550
system_message = SystemMessage(
@@ -53,6 +58,11 @@ def __init__(self, session_id: str):
5358
the customers that buy them, and the sales orders that are placed by customers.
5459
5560
If you don't know the answer to a question, respond with "I don't know."
61+
62+
Only answer questions related to Cosmic Works products, customers, and sales orders.
63+
64+
If a question is not related to Cosmic Works products, customers, or sales orders,
65+
respond with "I only answer questions about Cosmic Works"
5666
"""
5767
)
5868
self.agent_executor = create_conversational_retrieval_agent(

Labs/app/backend/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
app = FastAPI()
1010
# Agent pool keyed by session_id to retain memories/history in-memory.
11+
# Note: the context is lost every time the service is restarted.
1112
agent_pool = {}
1213

1314
@app.get("/")

Labs/lab_4_langchain.ipynb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@
141141
"\n",
142142
"If you are asked a question that is not in the list, respond with \"I don't know.\"\n",
143143
"\n",
144+
"Only answer questions related to Cosmic Works products, customers, and sales orders.\n",
145+
"\n",
146+
"If a question is not related to Cosmic Works products, customers, or sales orders,\n",
147+
"respond with \"I only answer questions about Cosmic Works\"\n",
148+
"\n",
144149
"List of products:\n",
145150
"{products}\n",
146151
"\n",
@@ -374,6 +379,11 @@
374379
" You are designed to answer questions about the products that Cosmic Works sells, the customers that buy them, and the sales orders that are placed by customers.\n",
375380
"\n",
376381
" If you don't know the answer to a question, respond with \"I don't know.\"\n",
382+
" \n",
383+
" Only answer questions related to Cosmic Works products, customers, and sales orders.\n",
384+
" \n",
385+
" If a question is not related to Cosmic Works products, customers, or sales orders,\n",
386+
" respond with \"I only answer questions about Cosmic Works\"\n",
377387
" \"\"\" \n",
378388
")\n",
379389
"agent_executor = create_conversational_retrieval_agent(llm, tools, system_message = system_message, verbose=True)"

0 commit comments

Comments
 (0)