.
├── Makefile
├── lib
│ ├── __init__.py
│ └── gitbook-to-rag-converter <<<<< Clone here
├── config.json
├── logs
├── requirments.txt
└── main.py <<<< We gonna work on this file
git clone git@github.com:NSO-developer/nso-gitbook.git resource/nso-gitbook
Make sure install all the dependency from pip
pip install -r requirments.txt
Setup the API by configure config.json
{
"vdb_path":"resource/vectordb",
"markdown_path":"resource/nso-gitbook/",
"embedding_model":"sentence-transformers/all-mpnet-base-v2",
"doc_vers":["latest","6.4","6.3","6.2","6.1"]
}
save_vdb()
data=query_vdb(query,top_result=2)
from lib.gitbook_to_rag_converter.langchain_markdown import save_vdb, query_vdb
persist_directory = 'lib/resources/vectordb'
init=False
if not os.path.exists(persist_directory+"/chroma.sqlite3"):
save_db()
print("What can I help you today:")
query=input()
rag_result=query_vdb(query,mode="max_marginal_relevance_search",top_result=2)
source: title: CDB and YANG - Key Features of the CDB, url: https://nso-docs.cisco.com/guides/development/introduction-to-automation/cdb-and-yang
result: The CDB is a dedicated built-in storage for data in NSO. It was built from the ground up to efficiently store and access network configuration data, such as device configurations, service parameters, and even configuration for NSO itself. Unlike traditional SQL databases that store data as rows in a table, the CDB is a hierarchical database, with a structure resembling a tree. You could think of it as somewhat like a big XML document that can store all kinds of data.
There are a number of other features that make the CDB an excellent choice for a configuration store:
* Fast lightweight database access through a well-defined API.
* Subscription (“push”) mechanism for change notification.
* Transaction support for ensuring data consistency.
* Rich and extensible schema based on YANG.
* Built-in support for schema and associated data upgrade.
* Close integration with NSO for low-maintenance operation.
To speed up operations, CDB keeps a configurable amount of configuration data in RAM, in addition to persisting it to disk (see [CDB Persistence](../../administration/advanced-topics/cdb-persistence.md) for details). The CDB also stores transient operational data, such as alarms and traffic statistics. By default, this operational data is only kept in RAM and is reset during restarts, however, the CDB can be instructed to persist it if required.
{% hint style="info" %}
The automatic schema update feature is useful not only when performing an actual upgrade of NSO itself, it also simplifies the development process. It allows individual developers to add and delete items in the configuration independently.
Additionally, the schema for data in the CDB is defined with a standard modeling language called YANG. YANG (RFC 7950, [https://tools.ietf.org/html/rfc7950](https://tools.ietf.org/html/rfc7950)) describes constraints on the data and allows the CDB to store values more efficiently.
{% endhint %}
source: title: Tools - Insights, url: https://nso-docs.cisco.com/guides/operation-and-usage/webui/tools
result: The **Insights** view collects and displays the following types of operational information using the `/ncs:metrics` data model to present useful statistics:
* Real-time data about transactions, commit queues, and northbound sessions.
* Sessions created and closed towards northbound interfaces since the last restart (CLI, JSON-RPC, NETCONF, RESTCONF, SNMP).
* Transactions since last restart (committed, aborted, and conflicting). You can select between the running and operational data stores.
* Devices and their sync statuses.
* CDB info about its size, compaction, etc.
from langchain.chat_models import AzureChatOpenAI
os.environ["OPENAI_API_VERSION"] = "OPEN API VERSION"
os.environ["AZURE_OPENAI_ENDPOINT"] = "OPENAI ENDPOINT"
app_key="APP KEY"
model="LLM MODEL NAME"
def init_openai(model=None):
"""
Function to initialize the OpenAI service .
"""
if not model:
models=config_model
else:
models=model
llm = AzureChatOpenAI(deployment_name=models,
azure_endpoint = os.environ["AZURE_OPENAI_ENDPOINT"],
api_key=os.environ["OPENAI_API_KEY"],
api_version=os.environ["OPENAI_API_VERSION"],
model_kwargs=dict(
user=f'{{"appkey": "{app_key}"}}'
)
)
return llm
def query_openai(query,llm):
"""
Function to query the OpenAI service with a given query string.
"""
try:
response = llm.invoke(query)
except openai.AuthenticationError:
print("Authentication Error. Update access token")
llm=update_access_token()
response = llm.invoke(query)
return {"content":response.content, "token":response.response_metadata['token_usage']['total_tokens']}
from langchain.messages import SystemMessage, HumanMessage, AIMessage
systemPrompt = f'''
You are a NSO expert that will answer question based on the context provided below.
Here are the set of contexts:
<contexts>
{rag_result}
</contexts>
`;
'''
messages = [
SystemMessage(systemPrompt),
HumanMessage(query)
]
response = model.invoke(messages)
Regarding how to rephrase the query and the effect of rephrase, one can take a look at the following article - PaperMadeEasy | Rephrase and Respond : Let LLM Ask Better Questions for Themselves | by Himanshu Bajpai | Medium
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: