Spaces:
Sleeping
Sleeping
Upload 9 files
Browse filesFiles changed (10)
- .gitattributes+2
- backend/query_llm.pyAdded+177
- backend/semantic_search.pyAdded+28
- lancedb/cbse.lance/_latest.manifestAdded
- lancedb/cbse.lance/_transactions/0-bf8e63bb-3e01-448f-95c6-f20996e7415f.txnAdded+1
- lancedb/cbse.lance/_transactions/1-76260358-b577-4610-83d2-64fb3c14ebc6.txnAdded
- lancedb/cbse.lance/_versions/1.manifestAdded
- lancedb/cbse.lance/_versions/2.manifestAdded
- lancedb/cbse.lance/data/615853d2-bbd1-453c-88c7-8df0edb43e5e.lanceAdded+3
- logo.pngAdded
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines333435363732 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textlancedb/cbse.lance/data/615853d2-bbd1-453c-88c7-8df0edb43e5e.lance filter=lfs diff=lfs merge=lfs -textlogo.png filter=lfs diff=lfs merge=lfs -text
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
# import openai
# import gradio as gr
# from os import getenv
# from typing import Any, Dict, Generator, List
# from huggingface_hub import InferenceClient
# from transformers import AutoTokenizer
# from gradio_client import Client
# #tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
# #tokenizer = AutoTokenizer.from_pretrained("mistralai/Mixtral-8x7B-Instruct-v0.1")
# #tokenizer = AutoTokenizer.from_pretrained("mistralai/Mixtral-8x22B-Instruct-v0.1")
# tokenizer=''
# temperature = 0.5
# top_p = 0.7
# repetition_penalty = 1.2
# OPENAI_KEY = getenv("OPENAI_API_KEY")
# HF_TOKEN = getenv("HUGGING_FACE_HUB_TOKEN")
# # hf_client = InferenceClient(
# # "mistralai/Mistral-7B-Instruct-v0.1",
# # token=HF_TOKEN
# # )
# client = Client("Qwen/Qwen1.5-110B-Chat-demo")
# hf_client=''
# # hf_client = InferenceClient(
# # "mistralai/Mixtral-8x7B-Instruct-v0.1",
# # token=HF_TOKEN
# # )
# def format_prompt(message: str, api_kind: str):
# """
# Formats the given message using a chat template.
# Args:
# message (str): The user message to be formatted.
# Returns:
# str: Formatted message after applying the chat template.
# """
# # Create a list of message dictionaries with role and content
# messages: List[Dict[str, Any]] = [{'role': 'user', 'content': message}]
# if api_kind == "openai":
# return messages
# elif api_kind == "hf":
# return tokenizer.apply_chat_template(messages, tokenize=False)
# elif api_kind:
# raise ValueError("API is not supported")
# def generate_hf(prompt: str, history: str, temperature: float = 0.5, max_new_tokens: int = 4000,
# top_p: float = 0.95, repetition_penalty: float = 1.0) -> Generator[str, None, str]:
# """
# Generate a sequence of tokens based on a given prompt and history using Mistral client.
# Args:
# prompt (str): The initial prompt for the text generation.
# history (str): Context or history for the text generation.
# temperature (float, optional): The softmax temperature for sampling. Defaults to 0.9.
# max_new_tokens (int, optional): Maximum number of tokens to be generated. Defaults to 256.
# top_p (float, optional): Nucleus sampling probability. Defaults to 0.95.
# repetition_penalty (float, optional): Penalty for repeated tokens. Defaults to 1.0.
# Returns:
# Generator[str, None, str]: A generator yielding chunks of generated text.
# Returns a final string if an error occurs.
# """
# temperature = max(float(temperature), 1e-2) # Ensure temperature isn't too low
# top_p = float(top_p)
# generate_kwargs = {
# 'temperature': temperature,
# 'max_new_tokens': max_new_tokens,
# 'top_p': top_p,
# 'repetition_penalty': repetition_penalty,
# 'do_sample': True,
# 'seed': 42,
# }
# formatted_prompt = format_prompt(prompt, "hf")
# try:
# stream = hf_client.text_generation(formatted_prompt, **generate_kwargs,
# stream=True, details=True, return_full_text=False)
# output = ""
# for response in stream:
# output += response.token.text
# yield output
# except Exception as e:
# if "Too Many Requests" in str(e):
# print("ERROR: Too many requests on Mistral client")
# gr.Warning("Unfortunately Mistral is unable to process")
# return "Unfortunately, I am not able to process your request now."
# elif "Authorization header is invalid" in str(e):
# print("Authetification error:", str(e))
# gr.Warning("Authentication error: HF token was either not provided or incorrect")
# return "Authentication error"
# else:
# print("Unhandled Exception:", str(e))
# gr.Warning("Unfortunately Mistral is unable to process")
# return "I do not know what happened, but I couldn't understand you."
# def generate_qwen(formatted_prompt: str, history: str):
# response = client.predict(
# query=formatted_prompt,
# history=[],
# system='You are wonderful',
# api_name="/model_chat"
# )
# print('Response:',response)
# #return output
# #return response[1][0][1]
# return response[1][0][1]
# def generate_openai(prompt: str, history: str, temperature: float = 0.9, max_new_tokens: int = 256,
# top_p: float = 0.95, repetition_penalty: float = 1.0) -> Generator[str, None, str]:
# """
# Generate a sequence of tokens based on a given prompt and history using Mistral client.
# Args:
# prompt (str): The initial prompt for the text generation.
# history (str): Context or history for the text generation.
# temperature (float, optional): The softmax temperature for sampling. Defaults to 0.9.
# max_new_tokens (int, optional): Maximum number of tokens to be generated. Defaults to 256.
# top_p (float, optional): Nucleus sampling probability. Defaults to 0.95.
# repetition_penalty (float, optional): Penalty for repeated tokens. Defaults to 1.0.
# Returns:
# Generator[str, None, str]: A generator yielding chunks of generated text.
# Returns a final string if an error occurs.
# """
# temperature = max(float(temperature), 1e-2) # Ensure temperature isn't too low
# top_p = float(top_p)
# generate_kwargs = {
# 'temperature': temperature,
# 'max_tokens': max_new_tokens,
# 'top_p': top_p,
# 'frequency_penalty': max(-2., min(repetition_penalty, 2.)),
# }
# formatted_prompt = format_prompt(prompt, "openai")
# try:
# stream = openai.ChatCompletion.create(model="gpt-3.5-turbo-0301",
# messages=formatted_prompt,
# **generate_kwargs,
# stream=True)
# output = ""
# for chunk in stream:
# output += chunk.choices[0].delta.get("content", "")
# yield output
# except Exception as e:
# if "Too Many Requests" in str(e):
# print("ERROR: Too many requests on OpenAI client")
# gr.Warning("Unfortunately OpenAI is unable to process")
# return "Unfortunately, I am not able to process your request now."
# elif "You didn't provide an API key" in str(e):
# print("Authetification error:", str(e))
# gr.Warning("Authentication error: OpenAI key was either not provided or incorrect")
# return "Authentication error"
# else:
# print("Unhandled Exception:", str(e))
# gr.Warning("Unfortunately OpenAI is unable to process")
# return "I do not know what happened, but I couldn't understand you."12345678910111213141516171819202122232425262728
import logging
import lancedb
import os
from pathlib import Path
from sentence_transformers import SentenceTransformer
#from FlagEmbedding import LLMEmbedder, FlagReranker # Al document present here https://github.com/FlagOpen/FlagEmbedding/tree/master
#EMB_MODEL_NAME = "thenlper/gte-base"
EMB_MODEL_NAME = 'BAAI/llm-embedder'
task = "qa" # Encode for a specific task (qa, icl, chat, lrlm, tool, convsearch)
#EMB_MODEL_NAME = LLMEmbedder('BAAI/llm-embedder', use_fp16=False) # Load model (automatically use GPUs)
#reranker_model = FlagReranker('BAAI/bge-reranker-base', use_fp16=True) # use_fp16 speeds up computation with a slight performance degradation
#EMB_MODEL_NAME = "thenlper/gte-base"
#DB_TABLE_NAME = "Huggingface_docs"
DB_TABLE_NAME = "cbse"
# Setting up the logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
retriever = SentenceTransformer(EMB_MODEL_NAME)
# db
db_uri = os.path.join(Path(__file__).parents[1], "lancedb")
print(f'DB URL is {db_uri}')
db = lancedb.connect(db_uri)
table = db.open_table(DB_TABLE_NAME)1$bf8e63bb-3e01-448f-95c6-f20996e7415f�Utext ���������*string084vector ���������*fixed_size_list:float:76808123version https://git-lfs.github.com/spec/v1oid sha256:1611699c7fdfa82b6674466912c66b6b5dbf1f21fba597cf5fc01381aacb828bsize 16009653.gitattributes+2
backend/query_llm.pyAdded+177
backend/semantic_search.pyAdded+28
lancedb/cbse.lance/_latest.manifestAdded
lancedb/cbse.lance/_transactions/0-bf8e63bb-3e01-448f-95c6-f20996e7415f.txnAdded+1
lancedb/cbse.lance/_transactions/1-76260358-b577-4610-83d2-64fb3c14ebc6.txnAdded
lancedb/cbse.lance/_versions/1.manifestAdded
lancedb/cbse.lance/_versions/2.manifestAdded
lancedb/cbse.lance/data/615853d2-bbd1-453c-88c7-8df0edb43e5e.lanceAdded+3
logo.pngAdded

Large File Pointer Details
- SHA256: 13f1597b502a8d8c9e02ab1110fd8d6da227f23249dfb3bb9f7a8edfc69d5de1
- Pointer size: 131 Bytes
- Size of remote file: 137 kB