Skip to content

Commit

Permalink
change organic query
Browse files Browse the repository at this point in the history
  • Loading branch information
acer-king committed Oct 15, 2024
1 parent 3caad48 commit 8fc7ca8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
50 changes: 27 additions & 23 deletions organic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from cortext.protocol import StreamPrompting
from cortext.dendrite import CortexDendrite
import aiohttp
from validators.services.cache import cache_service
from validators.services.cache import QueryResponseCache

cache_service = QueryResponseCache("cache_1.db")



Expand Down Expand Up @@ -143,28 +145,30 @@ async def main():

num_prompts = 10
prompts = load_entire_questions()
prompts = prompts[:10000]
synapses = [StreamPrompting(
messages=[{"role": "user", "content": prompt}],
provider="OpenAI",
model="gpt-4o"
) for prompt in prompts]

an_synapses = [StreamPrompting(
messages=[{"role": "user", "content": prompt}],
provider="Anthropic",
model="claude-3-5-sonnet-20240620"
) for prompt in prompts]
synapses += an_synapses

async def query_and_log(synapse):
return await query_miner(dendrite, axon_to_use, synapse)

responses = await asyncio.gather(*[query_and_log(synapse) for synapse in synapses])

cache_service.set_cache_in_batch(synapses)

print("Responses saved to cache database")
for idx in range(0, len(prompts), 1000):
items = prompts[idx:idx+1000]
synapses = [StreamPrompting(
messages=[{"role": "user", "content": prompt}],
provider="OpenAI",
model="gpt-4o"
) for prompt in items]

an_synapses = [StreamPrompting(
messages=[{"role": "user", "content": prompt}],
provider="Anthropic",
model="claude-3-5-sonnet-20240620"
) for prompt in items]
synapses += an_synapses

async def query_and_log(synapse):
return await query_miner(dendrite, axon_to_use, synapse)

responses = await asyncio.gather(*[query_and_log(synapse) for synapse in synapses])
global cache_service
cache_service.set_cache_in_batch(synapses)
await asyncio.sleep(3)

print("Responses saved to cache database")


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions validators/services/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@


class QueryResponseCache:
def __init__(self):
def __init__(self, database="cache.db"):
# Connect to (or create) the SQLite database
conn = sqlite3.connect('cache.db')
conn = sqlite3.connect(database)
cursor = conn.cursor()

# Create a table for caching (key, value, and expiry time)
Expand Down

0 comments on commit 8fc7ca8

Please sign in to comment.