navid72m commited on
Commit
33a10cf
1 Parent(s): 6f30cc4

Update selection.py

Browse files
Files changed (1) hide show
  1. selection.py +12 -14
selection.py CHANGED
@@ -1,5 +1,6 @@
 
1
  import os
2
- import numpy as np
3
  from sklearn.feature_extraction.text import TfidfVectorizer
4
  from sklearn.metrics.pairwise import cosine_similarity
5
  from datasets import load_dataset
@@ -33,19 +34,16 @@ most_relevant_context = find_most_relevant_context(contexts, Question)
33
  # Create the instruction for the model
34
  instruction = most_relevant_context[:300] + " " + Question
35
 
36
- # Load Mistral model and tokenizer
37
- model_name = "mistralai/Mistral-7B-v0.1" # Replace with the appropriate Mistral model name if available
38
- tokenizer = AutoTokenizer.from_pretrained(model_name , token= my_token)
39
- model = AutoModelForCausalLM.from_pretrained(model_name, token= my_token)
40
-
41
-
42
- # Tokenize the input
43
- input_ids = tokenizer.encode(instruction, return_tensors='pt')
44
 
45
- # Generate response
46
- outputs = model.generate(input_ids, max_new_tokens=150, num_return_sequences=1)
47
 
48
- # Decode the response
49
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
50
- print(response)
51
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
  import os
3
+
4
  from sklearn.feature_extraction.text import TfidfVectorizer
5
  from sklearn.metrics.pairwise import cosine_similarity
6
  from datasets import load_dataset
 
34
  # Create the instruction for the model
35
  instruction = most_relevant_context[:300] + " " + Question
36
 
 
 
 
 
 
 
 
 
37
 
 
 
38
 
39
+ API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
40
+ headers = {"Authorization": f"Bearer {my_token}"}
 
41
 
42
+ def query(payload):
43
+ response = requests.post(API_URL, headers=headers, json=payload)
44
+ return response.json()
45
+
46
+ output = query({
47
+ "inputs": instruction,
48
+ })
49
+ print(output)