Team Ai
Apppublic

RahulSinghPundir/SQL_Wizard

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
examples.py29 linesDownload Raw Back to root
1import os
2import json
3from langchain_community.vectorstores import Chroma
4from langchain_core.example_selectors import SemanticSimilarityExampleSelector
5from langchain_huggingface import HuggingFaceEmbeddings
6
7def get_examples():
8    # Get the current script directory
9    script_dir = os.path.dirname("E:\\Codes\\Ai_Ml\\PWD\\GUI\\")
10    # Construct the full path to the fewshot.json file
11    file_path = os.path.join(script_dir, 'fewshot.json')
12    with open(file_path, 'r') as f:
13        data = json.load(f)
14    examples = data["fewshots_examples"]
15    return examples
16
17def get_example_selector():
18    example_selector = SemanticSimilarityExampleSelector.from_examples(
19        examples,
20        HuggingFaceEmbeddings(),
21        Chroma,
22        k=2,
23        input_keys=["input"],
24    )
25    return example_selector
26
27examples = get_examples()
28embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2')
29