char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
a19b5cef1
char/aliceai-t5-moe
1import asyncio 2import asyncio .threads 3import requests 4import numpy as np 5 6 7n = 8 8 9result = [] 10 11async def requests_post_async (* args ,** kwargs ): 12return await asyncio .threads .to_thread (requests .post ,* args ,** kwargs ) 13 14async def main (): 15model_url = "http://127.0.0.1:6900" 16responses :list [requests .Response ]= await asyncio .gather (* [requests_post_async ( 17url = f" { model_url } /embedding" , 18json = {"content" :"a " * 1022 } 19 )for i in range (n )]) 20 21for response in responses : 22embedding = response .json ()["embedding" ] 23embedding [- 8 :]) 24result .append (embedding ) 25 26asyncio .run (main ()) 27 28# compute cosine similarity 29 30for i in range (n - 1 ): 31for j in range (i + 1 ,n ): 32embedding1 = np .array (result [i ]) 33embedding2 = np .array (result [j ]) 34similarity = np .dot (embedding1 ,embedding2 )/ (np .linalg .norm (embedding1 )* np .linalg .norm (embedding2 )) 35f"Similarity between { i } and { j } : { similarity :.2f } " )