rameshmoorthy commited on
Commit
553ea70
·
verified ·
1 Parent(s): a6bf2ef

Upload 9 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ lancedb/cbse.lance/data/615853d2-bbd1-453c-88c7-8df0edb43e5e.lance filter=lfs diff=lfs merge=lfs -text
37
+ logo.png filter=lfs diff=lfs merge=lfs -text
backend/query_llm.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ # import openai
4
+ # import gradio as gr
5
+
6
+ # from os import getenv
7
+ # from typing import Any, Dict, Generator, List
8
+
9
+ # from huggingface_hub import InferenceClient
10
+ # from transformers import AutoTokenizer
11
+ # from gradio_client import Client
12
+ # #tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
13
+ # #tokenizer = AutoTokenizer.from_pretrained("mistralai/Mixtral-8x7B-Instruct-v0.1")
14
+ # #tokenizer = AutoTokenizer.from_pretrained("mistralai/Mixtral-8x22B-Instruct-v0.1")
15
+ # tokenizer=''
16
+ # temperature = 0.5
17
+ # top_p = 0.7
18
+ # repetition_penalty = 1.2
19
+
20
+ # OPENAI_KEY = getenv("OPENAI_API_KEY")
21
+ # HF_TOKEN = getenv("HUGGING_FACE_HUB_TOKEN")
22
+
23
+ # # hf_client = InferenceClient(
24
+ # # "mistralai/Mistral-7B-Instruct-v0.1",
25
+ # # token=HF_TOKEN
26
+ # # )
27
+
28
+ # client = Client("Qwen/Qwen1.5-110B-Chat-demo")
29
+ # hf_client=''
30
+ # # hf_client = InferenceClient(
31
+ # # "mistralai/Mixtral-8x7B-Instruct-v0.1",
32
+ # # token=HF_TOKEN
33
+ # # )
34
+ # def format_prompt(message: str, api_kind: str):
35
+ # """
36
+ # Formats the given message using a chat template.
37
+
38
+ # Args:
39
+ # message (str): The user message to be formatted.
40
+
41
+ # Returns:
42
+ # str: Formatted message after applying the chat template.
43
+ # """
44
+
45
+ # # Create a list of message dictionaries with role and content
46
+ # messages: List[Dict[str, Any]] = [{'role': 'user', 'content': message}]
47
+
48
+ # if api_kind == "openai":
49
+ # return messages
50
+ # elif api_kind == "hf":
51
+ # return tokenizer.apply_chat_template(messages, tokenize=False)
52
+ # elif api_kind:
53
+ # raise ValueError("API is not supported")
54
+
55
+
56
+ # def generate_hf(prompt: str, history: str, temperature: float = 0.5, max_new_tokens: int = 4000,
57
+ # top_p: float = 0.95, repetition_penalty: float = 1.0) -> Generator[str, None, str]:
58
+ # """
59
+ # Generate a sequence of tokens based on a given prompt and history using Mistral client.
60
+
61
+ # Args:
62
+ # prompt (str): The initial prompt for the text generation.
63
+ # history (str): Context or history for the text generation.
64
+ # temperature (float, optional): The softmax temperature for sampling. Defaults to 0.9.
65
+ # max_new_tokens (int, optional): Maximum number of tokens to be generated. Defaults to 256.
66
+ # top_p (float, optional): Nucleus sampling probability. Defaults to 0.95.
67
+ # repetition_penalty (float, optional): Penalty for repeated tokens. Defaults to 1.0.
68
+
69
+ # Returns:
70
+ # Generator[str, None, str]: A generator yielding chunks of generated text.
71
+ # Returns a final string if an error occurs.
72
+ # """
73
+
74
+ # temperature = max(float(temperature), 1e-2) # Ensure temperature isn't too low
75
+ # top_p = float(top_p)
76
+
77
+ # generate_kwargs = {
78
+ # 'temperature': temperature,
79
+ # 'max_new_tokens': max_new_tokens,
80
+ # 'top_p': top_p,
81
+ # 'repetition_penalty': repetition_penalty,
82
+ # 'do_sample': True,
83
+ # 'seed': 42,
84
+ # }
85
+
86
+ # formatted_prompt = format_prompt(prompt, "hf")
87
+
88
+ # try:
89
+ # stream = hf_client.text_generation(formatted_prompt, **generate_kwargs,
90
+ # stream=True, details=True, return_full_text=False)
91
+ # output = ""
92
+ # for response in stream:
93
+ # output += response.token.text
94
+ # yield output
95
+
96
+ # except Exception as e:
97
+ # if "Too Many Requests" in str(e):
98
+ # print("ERROR: Too many requests on Mistral client")
99
+ # gr.Warning("Unfortunately Mistral is unable to process")
100
+ # return "Unfortunately, I am not able to process your request now."
101
+ # elif "Authorization header is invalid" in str(e):
102
+ # print("Authetification error:", str(e))
103
+ # gr.Warning("Authentication error: HF token was either not provided or incorrect")
104
+ # return "Authentication error"
105
+ # else:
106
+ # print("Unhandled Exception:", str(e))
107
+ # gr.Warning("Unfortunately Mistral is unable to process")
108
+ # return "I do not know what happened, but I couldn't understand you."
109
+
110
+ # def generate_qwen(formatted_prompt: str, history: str):
111
+ # response = client.predict(
112
+ # query=formatted_prompt,
113
+ # history=[],
114
+ # system='You are wonderful',
115
+ # api_name="/model_chat"
116
+ # )
117
+ # print('Response:',response)
118
+
119
+ # #return output
120
+ # #return response[1][0][1]
121
+ # return response[1][0][1]
122
+
123
+
124
+
125
+ # def generate_openai(prompt: str, history: str, temperature: float = 0.9, max_new_tokens: int = 256,
126
+ # top_p: float = 0.95, repetition_penalty: float = 1.0) -> Generator[str, None, str]:
127
+ # """
128
+ # Generate a sequence of tokens based on a given prompt and history using Mistral client.
129
+
130
+ # Args:
131
+ # prompt (str): The initial prompt for the text generation.
132
+ # history (str): Context or history for the text generation.
133
+ # temperature (float, optional): The softmax temperature for sampling. Defaults to 0.9.
134
+ # max_new_tokens (int, optional): Maximum number of tokens to be generated. Defaults to 256.
135
+ # top_p (float, optional): Nucleus sampling probability. Defaults to 0.95.
136
+ # repetition_penalty (float, optional): Penalty for repeated tokens. Defaults to 1.0.
137
+
138
+ # Returns:
139
+ # Generator[str, None, str]: A generator yielding chunks of generated text.
140
+ # Returns a final string if an error occurs.
141
+ # """
142
+
143
+ # temperature = max(float(temperature), 1e-2) # Ensure temperature isn't too low
144
+ # top_p = float(top_p)
145
+
146
+ # generate_kwargs = {
147
+ # 'temperature': temperature,
148
+ # 'max_tokens': max_new_tokens,
149
+ # 'top_p': top_p,
150
+ # 'frequency_penalty': max(-2., min(repetition_penalty, 2.)),
151
+ # }
152
+
153
+ # formatted_prompt = format_prompt(prompt, "openai")
154
+
155
+ # try:
156
+ # stream = openai.ChatCompletion.create(model="gpt-3.5-turbo-0301",
157
+ # messages=formatted_prompt,
158
+ # **generate_kwargs,
159
+ # stream=True)
160
+ # output = ""
161
+ # for chunk in stream:
162
+ # output += chunk.choices[0].delta.get("content", "")
163
+ # yield output
164
+
165
+ # except Exception as e:
166
+ # if "Too Many Requests" in str(e):
167
+ # print("ERROR: Too many requests on OpenAI client")
168
+ # gr.Warning("Unfortunately OpenAI is unable to process")
169
+ # return "Unfortunately, I am not able to process your request now."
170
+ # elif "You didn't provide an API key" in str(e):
171
+ # print("Authetification error:", str(e))
172
+ # gr.Warning("Authentication error: OpenAI key was either not provided or incorrect")
173
+ # return "Authentication error"
174
+ # else:
175
+ # print("Unhandled Exception:", str(e))
176
+ # gr.Warning("Unfortunately OpenAI is unable to process")
177
+ # return "I do not know what happened, but I couldn't understand you."
backend/semantic_search.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import logging
3
+ import lancedb
4
+ import os
5
+ from pathlib import Path
6
+ from sentence_transformers import SentenceTransformer
7
+ #from FlagEmbedding import LLMEmbedder, FlagReranker # Al document present here https://github.com/FlagOpen/FlagEmbedding/tree/master
8
+ #EMB_MODEL_NAME = "thenlper/gte-base"
9
+ EMB_MODEL_NAME = 'BAAI/llm-embedder'
10
+ task = "qa" # Encode for a specific task (qa, icl, chat, lrlm, tool, convsearch)
11
+ #EMB_MODEL_NAME = LLMEmbedder('BAAI/llm-embedder', use_fp16=False) # Load model (automatically use GPUs)
12
+
13
+ #reranker_model = FlagReranker('BAAI/bge-reranker-base', use_fp16=True) # use_fp16 speeds up computation with a slight performance degradation
14
+
15
+
16
+ #EMB_MODEL_NAME = "thenlper/gte-base"
17
+ #DB_TABLE_NAME = "Huggingface_docs"
18
+ DB_TABLE_NAME = "cbse"
19
+ # Setting up the logging
20
+ logging.basicConfig(level=logging.INFO)
21
+ logger = logging.getLogger(__name__)
22
+ retriever = SentenceTransformer(EMB_MODEL_NAME)
23
+
24
+ # db
25
+ db_uri = os.path.join(Path(__file__).parents[1], "lancedb")
26
+ print(f'DB URL is {db_uri}')
27
+ db = lancedb.connect(db_uri)
28
+ table = db.open_table(DB_TABLE_NAME)
lancedb/cbse.lance/_latest.manifest ADDED
Binary file (236 Bytes). View file
 
lancedb/cbse.lance/_transactions/0-bf8e63bb-3e01-448f-95c6-f20996e7415f.txn ADDED
@@ -0,0 +1 @@
 
 
1
+ $bf8e63bb-3e01-448f-95c6-f20996e7415f�Utext ���������*string084vector ���������*fixed_size_list:float:76808
lancedb/cbse.lance/_transactions/1-76260358-b577-4610-83d2-64fb3c14ebc6.txn ADDED
Binary file (98 Bytes). View file
 
lancedb/cbse.lance/_versions/1.manifest ADDED
Binary file (181 Bytes). View file
 
lancedb/cbse.lance/_versions/2.manifest ADDED
Binary file (236 Bytes). View file
 
lancedb/cbse.lance/data/615853d2-bbd1-453c-88c7-8df0edb43e5e.lance ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1611699c7fdfa82b6674466912c66b6b5dbf1f21fba597cf5fc01381aacb828b
3
+ size 16009653
logo.png ADDED

Git LFS Details

  • SHA256: 13f1597b502a8d8c9e02ab1110fd8d6da227f23249dfb3bb9f7a8edfc69d5de1
  • Pointer size: 131 Bytes
  • Size of remote file: 137 kB