Skip to content

Latest commit

 

History

History

examples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Nyx AI Examples

A set of demo built on top of the Nyx SDK

https://iotics.com

🤔 Why Nyx for AI?

  • Decentralized Data Gathering: Access a vast network of data producers.
  • Efficiency: Augment smaller language models with relevant information for informed decision-making.
  • Sustainability: Smaller models are good for the planet, cost-effective whilst still providing grounded answers with the help of RAG.

🔥 Quick Start

If you'd like to experience the SDK without installing it first:

💾 Installation

To get started, we recommend installing the package extras which provide close integration with one of the most popular AI libraries for Python: LangChain.

You can install the full set of extras as follows:

cd examples
pip install -r requirements.txt

This will install core functionality to interact with Nyx, as well as some support for auto-vectorization, and conversion of CSV products from Nyx into an SQLite DB that can be handled by an AI. It's designed to support advanced usage where you will integrate results from Nyx yourself.

To only install the core of the client with pip install nyx_client if you're planning on advanced usage. See Nyx SDK.

⚙️ Configuration

See First time set up on how to generate initial configuration to communicate with your nyx instance.

🔐 API Keys

The Nyx SDK currently supports a variety of LangChain-based LLM specific plugins, including Cohere and OpenAI. To use these, you will need to expose the specific API key to your application through environment variables or instantiate the relevant configuration object with the key.

export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>

or

from nyx_client import NyxConfigExtended, ConfigType, BaseNyxConfig

config = NyxConfigExtended(api_key="", provider=ConfigType.OPENAI, base_config=BaseNyxConfig.from_env())

or if using Cohere

export COHERE_API_KEY=<YOUR_COHERE_API_KEY>

or

from nyx_client import NyxConfigExtended, ConfigType, BaseNyxConfig

config = NyxConfigExtended(api_key="", provider=ConfigType.COHERE, base_config=BaseNyxConfig.from_env())

The NyxConfigExtended instance can then be used with the NyxLangChain client.

🎓 Examples

To run

cd examples/high_level
python highlevel.py

These use additional dependencies for an out-of-the-box experience with minimal integration.

Example Summary Notes
highlevel.py::main() Minimal CLI chat prompt, considering all subscribed-to Nyx data. Defaults to OpenAI LLM but can easily be changed to use Cohere
highlevel.py::custom_data() Use a filtered set of data rather than all subscribed-to
highlevel.py::include_own_data() Include own data in addition to subscribed-to
highlevel.py::custom_openai_llm() Use a custom model instead of the nyx default one for an LLM. This also demonstrates how do specify your own BaseChatModel, i.e. any LLM provider supporting said LangChain interface.

e.g. to run the RAG API example:

cd examples/advanced/rag_api
python app.py

These require manual integration with AI or other tools, offering more control over the process.

Example Summary Notes
rag_api Web server chat bot Demonstrates configuration of LLM agent, nyx data and RAG SQL tooling
rag_with_sources How to include information about data sources in query responses Similar to rag_api
rag_with_judge Let the LLM attempt to answer the query on its own and enrich its context with data from Nyx Similar to rag_api
evaluate Compare the performance of different Language Models (LLMs) on a set of predefined questions.

📔 Try it out (Jupyter)

To get a feel for the NYX SDK without a local environment setup, you can try our Jupyter Notebooks.

Available notebooks

Path Summary
examples/high_level/highlevel.ipynb Introduction to NYX SDK with minimal RAG demo code
examples/advanced/advanced.ipynb RAG demo showing how to put the building blocks together yourself (LLM, agent, RAG tooling)

Running in Google Colab

Click Open All Colab, select one of the above listed examples and start running it by clicking the "Play" button on the first code snippet.

Running with local JupyterLab

Clone the repo:

git clone https://github.com/Iotic-Labs/nyx-sdk.git
cd nyx-sdk

Install JupyterLab in a new virtual environment:

python3 -mvenv jupyterlab
. jupyterlab/bin/activate
pip install jupyterlab

Thereafter, each time to start it:

. jupyterlab/bin/activate
jupyter lab

👉 Gotchas

See SDK readme section

🐞 Troubleshooting

If you encounter any issues, we'd love to hear from you

🤝 Contributing

See SDK readme section.