Skip to content

Commit

Permalink
Merge pull request #55 from corcel-api/release/3.1.7
Browse files Browse the repository at this point in the history
Release/3.2.3
  • Loading branch information
surcyf123 authored Mar 14, 2024
2 parents 501f701 + d0a4c56 commit 53274c0
Show file tree
Hide file tree
Showing 51 changed files with 1,771 additions and 827 deletions.
136 changes: 136 additions & 0 deletions Cortex.t.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
Metadata-Version: 2.1
Name: Cortex.t
Version: 3.1.6
Summary: Decentralized APIs for synthetic data generation
Home-page: https://github.com/corcel-api/cortex.t
Author: Fish
License: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp==3.*
Requires-Dist: bittensor==6.*
Requires-Dist: datasets==2.*
Requires-Dist: envparse==0.2.0
Requires-Dist: openai==1.*,>=1.3.2
Requires-Dist: Pillow==10.*
Requires-Dist: requests==2.*
Requires-Dist: scikit-learn==1.*
Requires-Dist: torch==2.*
Requires-Dist: transformers==4.*
Requires-Dist: wandb
Requires-Dist: anthropic
Requires-Dist: stability-sdk
Requires-Dist: boto3
Requires-Dist: anthropic_bedrock
Requires-Dist: pyOpenSSL

<div align="left">

# **Cortex.t Subnet** <!-- omit in toc -->
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
---

---
- [Introduction](#introduction)
- [Setup](#setup)
- [Mining](#mining)
- [Validating](#validating)
- [License](#license)


## Introduction

**IMPORTANT**: If you are new to Bittensor, please checkout the [Bittensor Website](https://bittensor.com/) before proceeding to the [Setup](#setup) section.

Introducing Bittensor Subnet 18 (Cortex.t): A Pioneering Platform for AI Development and Synthetic Data Generation.

Cortex.t stands at the forefront of artificial intelligence, offering a dual-purpose solution that caters to the needs of app developers and innovators in the AI space. This platform is meticulously designed to deliver reliable, high-quality text and image responses through API usage, utilising the decentralised Bittensor network. It serves as a cornerstone for creating a fair, transparent, and manipulation-free environment for the incentivised production of intelligence (mining) and generation and fulfilment of diverse user prompts.

Our initiative is a leap forward in redefining the reward system for text and image prompting with a commitment to providing stability and reassurance to developers. By focusing on the value delivered to clients, we alleviate the concerns of data inconsistencies that often plague app development. The quality of Cortex.t is seamlessly integrated within the Bittensor network, allowing developers to harness the power of multiple subnets and modalities by building directly onto an existing validator, or through an API key from [Corcel](https://corcel.io).

Cortex.t is also a transformative platform leveraging advanced AI models to generate synthetic prompt-response pairs. This novel method yields a comprehensive dataset of interactions, archived in wandb [wandb.ai/cortex-t/synthetic-QA](https://wandb.ai/cortex-t/synthetic-QA). The process involves recycling model outputs back into the system, using a prompt evolution and data augmentation strategy similar to Microsoft's approach in developing WizardLM. This enables the distillation of sophisticated AI models into smaller, yet efficient counterparts, mirroring the performance of their larger predecessors. Ultimately, Cortex.t democratizes access to high-end AI technology, encouraging innovation and customization.

By leveraging synthetic data, Cortex.t circumvents the traditional challenges of data collection and curation, accelerating the development of AI models that are both robust and adaptable. This platform is your gateway to AI mastery, offering the unique opportunity to train your models with data that reflects the depth and versatility of the parent model. With SynthPairPro, you're not just collecting data; you're capturing intelligence, providing a path to creating AI models that mirror the advanced understanding and response capabilities of their predecessors.

Join us at Cortex.t, your bridge to AI excellence, and democratise access to top-level AI capabilities. Be part of the AI revolution and stay at the forefront of innovation with SynthPairPro – Synthesizing Intelligence, Empowering the Future!


## Development

### Testing

install `nox` (`pip install nox`) and run `nox -s test`.

## Setup

### Before you proceed
Before you proceed with the installation of the subnet, note the following:

**IMPORTANT**: We **strongly recommend** before proceeding that you test both subtensor and OpenAI API keys. Ensure you are running Subtensor locally to minimize chances of outages and improve the latency/connection.

After exporting your OpenAI API key to your bash profile, test the streaming service for both the gpt-3.5-turbo and gpt-4 engines using ```./neurons/test_openai.py```. Neither the miner or the validator will function without a valid and working [OpenAI API key](https://platform.openai.com/).

**IMPORTANT:** Make sure you are aware of the minimum compute requirements for cortex.t. See the [Minimum compute YAML configuration](./min_compute.yml).
Note that this subnet requires very little compute. The main functionality is api calls, so we outsource the compute to openai. The cost for mining and validating on this subnet comes from api calls, not from compute. Please be aware of your API costs and monitor accordingly.

A high tier key is required for both mining and validations so it is important if you do not have one to work your way up slowly by running a single miner or small numbers of miners whilst payiing attention to your usage and limits.


### Installation

Download the repository, navigate to the folder and then install the necessary requirements with the following chained command.

```git clone https://github.com/corcel-api/cortex.t.git && cd cortex.t && pip install -e .```

Prior to proceeding, ensure you have a registered hotkey on subnet 18 mainnet. If not, run the command `btcli s register --netuid 18 --wallet.name [wallet_name] --wallet.hotkey [wallet.hotkey]`.

We recommend using [direnv](https://direnv.net). After installing it, copy `envrc.example` to `.envrc` and substitute
all env vars with values appropriate for your accounts. After making changes to `.envrc` run `direnv allow` and start a
new terminal tab.

## Mining

You can launch your miners via pm2 using the following command.

`pm2 start ./miner/miner.py --interpreter python3 -- --netuid 18 --subtensor.network <LOCAL/FINNEY/TEST> --wallet.name <WALLET NAME> --wallet.hotkey <HOTKEY NAME> --axon.port <PORT>`


## Validating

You can launch your validator via pm2 using the following command.

`pm2 start ./validators/validator.py --interpreter python3 -- --netuid 18 --subtensor.network <LOCAL/FINNEY/TEST> --wallet.name <WALLET NAME> --wallet.hotkey <HOTKEY NAME>`


## Logging

As cortex.t supports streaming natively, you do not (and should not) enable `logging.trace` or `logging.debug` as all of the important information is already output to `logging.info` which is set as default.

---

## License
This repository is licensed under the MIT License.
```text
# The MIT License (MIT)
# Copyright © 2023 Yuma Rao

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.

# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
```
14 changes: 14 additions & 0 deletions Cortex.t.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
LICENSE
README.md
setup.py
Cortex.t.egg-info/PKG-INFO
Cortex.t.egg-info/SOURCES.txt
Cortex.t.egg-info/dependency_links.txt
Cortex.t.egg-info/requires.txt
Cortex.t.egg-info/top_level.txt
base/__init__.py
template/__init__.py
template/protocol.py
template/reward.py
template/utils.py
test_base/__init__.py
1 change: 1 addition & 0 deletions Cortex.t.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

16 changes: 16 additions & 0 deletions Cortex.t.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
aiohttp==3.*
bittensor==6.*
datasets==2.*
envparse==0.2.0
openai==1.*,>=1.3.2
Pillow==10.*
requests==2.*
scikit-learn==1.*
torch==2.*
transformers==4.*
wandb
anthropic
stability-sdk
boto3
anthropic_bedrock
pyOpenSSL
3 changes: 3 additions & 0 deletions Cortex.t.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
base
template
test_base
86 changes: 86 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import bittensor as bt
import asyncio
import json
import traceback
from template.protocol import StreamPrompting, TextPrompting, ImageResponse

# Assuming initial setup remains the same
wallet = bt.wallet( name="validator", hotkey="default" )
axon = bt.axon(wallet=wallet)
dendrite = bt.dendrite(wallet=wallet)
subtensor = bt.subtensor( network = "test")
metagraph = subtensor.metagraph(netuid = 24 )

# StreamPrompting variables
question = [{"role": "user", "content": "quick question"}]
vali_uid = 1
target_uid = 3
provider = "OpenAI"
model = "gpt-3.5-turbo"
seed = 1234
temperature = 0.5
max_tokens = 2048
top_p = 0.8
top_k = 1000
timeout = 3
streaming = True

synapse = StreamPrompting(
messages=question,
uid=target_uid,
provider=provider,
model=model,
seed=seed,
temperature=temperature,
max_tokens=max_tokens,
top_p=top_p,
top_k=top_k,
timeout=timeout,
streaming=streaming,
)

# ImageResponse variables
messages = "a thick white cloud over a river"

synapse = ImageResponse(
messages=messages
)

print("messages", messages)
bt.trace()
response = dendrite.query(metagraph.axons[vali_uid], synapse, deserialize=False, timeout=synapse.timeout)
print('completion:', response.completion)

# async def query_miner(synapse):
# try:
# axon = metagraph.axons[vali_uid]
# responses = dendrite.query(
# axons=[axon],
# synapse=synapse,
# deserialize=False,
# timeout=timeout,
# streaming=streaming,
# )
# return await handle_response(responses)
# except Exception as e:
# print(f"Exception during query: {traceback.format_exc()}")
# return None

# async def handle_response(responses):
# full_response = ""
# try:
# for resp in responses:
# async for chunk in resp:
# if isinstance(chunk, str):
# full_response += chunk
# bt.logging.info(chunk)
# except Exception as e:
# print(f"Error processing response for uid {e}")
# return full_response

# async def main():
# response = await query_miner(synapse)
# bt.logging.info(f"full_response = {response}")

# if __name__ == "__main__":
# asyncio.run(main())
3 changes: 2 additions & 1 deletion template/__init__.py → cortext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


# version must stay on line 22
__version__ = "3.2.2"
__version__ = "3.2.3"
version_split = __version__.split(".")
__spec_version__ = (
(1000 * int(version_split[0]))
Expand Down Expand Up @@ -51,6 +51,7 @@
# must have the test_key whitelisted to avoid a global blacklist
testnet_key = ["5EhEZN6soubtKJm8RN7ANx9FGZ2JezxBUFxr45cdsHtDp3Uk"]
test_key = ["5DcRHcCwD33YsHfj4PX5j2evWLniR1wSWeNmpf5RXaspQT6t"]
VALIDATOR_API_WHITELIST = ["5EhEZN6soubtKJm8RN7ANx9FGZ2JezxBUFxr45cdsHtDp3Uk"]
valid_validators = [
'5FFApaS75bv5pJHfAp2FVLBj9ZaXuFDjEypsaBNc1wCfe52v',
'5EhvL1FVkQPpMjZX4MAADcW42i3xPSF1KiCpuaxTYVr28sux',
Expand Down
Loading

0 comments on commit 53274c0

Please sign in to comment.