Spaces:
Paused
Paused
Update data_collector.py
Browse files5 unmodified lines67891011121314159101112131415161718192021221819202122232425262728293031323334353637383940414243444546474849502425262728293031323334353637383940414243444546474849505152535452535455565657585960616263585960616263646566666768695 unmodified linesfrom transformers import pipelineimport requests
# def consume_llm_api(prompt):# """# Sends a prompt to the LLM API and processes the streamed response.# """# url = "https://8417-201-238-124-65.ngrok-free.app/api/llm-response"# headers = {"Content-Type": "application/json"}# payload = {"prompt": prompt,"extension":"1"}def consume_llm_api(prompt): """ Sends a prompt to the LLM API and processes the streamed response. """ url = "https://8417-201-238-124-65.ngrok-free.app/api/llm-response" headers = {"Content-Type": "application/json"} payload = {"prompt": prompt,"extension":"1"}
# print("Sending prompt to the LLM API...")# response_ = requests.post(url, json=payload,verify=False)# response_data = response_.json()# return response_data['text']def consume_llm_api(prompt): print("Sending prompt to the LLM API...") response_ = requests.post(url, json=payload,verify=False) response_data = response_.json() return response_data['text']# def consume_llm_api(prompt):
import requests from sentence_transformers import SentenceTransformer from pinecone import Pinecone, ServerlessSpec Gen_api = "https://8417-201-238-124-65.ngrok-free.app/api/llm-response" api_key = "pcsk_2EhvKP_GqGkpAjF4p4ziL7PgrgM9xuKcthX9gtqhyLxV3UaMmWTQufW4qKZrjhLrf2d1ma" pc = Pinecone(api_key=api_key) model = SentenceTransformer("all-mpnet-base-v2") try: index_name = "quickstart" pc.create_index( name=index_name, dimension=768, metric="cosine", spec=ServerlessSpec( cloud="aws", region="us-east-1" ) ) except: pass index = pc.Index(index_name) index.upsert( vectors=[ { "id": "lorum", "values": [float(i) for i in list(model.encode("lorum"))], "metadata": {"string":str(prompt)}# import requests# from sentence_transformers import SentenceTransformer# from pinecone import Pinecone, ServerlessSpec# Gen_api = "https://8417-201-238-124-65.ngrok-free.app/api/llm-response"# api_key = "pcsk_2EhvKP_GqGkpAjF4p4ziL7PgrgM9xuKcthX9gtqhyLxV3UaMmWTQufW4qKZrjhLrf2d1ma"# pc = Pinecone(api_key=api_key)# model = SentenceTransformer("all-mpnet-base-v2")# try:# index_name = "quickstart"# pc.create_index(# name=index_name,# dimension=768, # metric="cosine", # spec=ServerlessSpec(# cloud="aws",# region="us-east-1"# ) # )# except:# pass# index = pc.Index(index_name)# index.upsert(# vectors=[# {# "id": "lorum", # "values": [float(i) for i in list(model.encode("lorum"))], # "metadata": {"string":str(prompt)} } ] )# }# ]# )
gen_api_response = requests.post(url = Gen_api,json={"api_key": api_key},verify=False)# gen_api_response = requests.post(url = Gen_api,json={"api_key": api_key},verify=False)
if gen_api_response.json().get("status"): response = index.query( vector=[float(i) for i in model.encode(str(prompt))], top_k=1, include_metadata=True, )# if gen_api_response.json().get("status"):# response = index.query(# vector=[float(i) for i in model.encode(str(prompt))],# top_k=1,# include_metadata=True,# )
return response['matches'][0]['metadata']['string']# return response['matches'][0]['metadata']['string']
def relevent_value(long_query,count=3):data_collector.py+50-50