-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from prabha-git/mixtral
Mixtral
- Loading branch information
Showing
4 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
import tiktoken | ||
from LLMNeedleHaystackTester import LLMNeedleHaystackTester | ||
from langchain_together import Together | ||
import time | ||
|
||
|
||
|
||
class OSS_TogetherEvaluator(LLMNeedleHaystackTester): | ||
def __init__(self,**kwargs): | ||
if 'together_api_key' not in kwargs and not os.getenv('TOGETHER_API_KEY'): | ||
raise ValueError("Either together_api_key must be supplied with init, or TOGETHER_API_KEY must be in env") | ||
|
||
if 'model_name' not in kwargs: | ||
raise ValueError("model_name must be supplied with init, accepted model_names are ''") | ||
elif kwargs['model_name'] not in ['Mixtral-8x7B-Instruct-v0.1','Mistral-7B-Instruct-v0.2']: | ||
raise ValueError(f"Model name must be in this list (Mixtral-8x7B-Instruct-v0.1,Mistral-7B-Instruct-v0.2) but given {kwargs['model_name']}") | ||
|
||
if 'evaluation_method' not in kwargs: | ||
print("since evaluation method is not specified , 'gpt4' will be used for evaluation") | ||
elif kwargs['evaluation_method'] not in ('gpt4', 'substring_match'): | ||
raise ValueError("evaluation_method must be 'substring_match' or 'gpt4'") | ||
|
||
|
||
self.google_api_key = kwargs.pop('together_api_key', os.getenv('TOGETHER_API_KEY')) | ||
self.model_name = kwargs['model_name'] | ||
self.model_to_test_description = kwargs.pop('model_name') | ||
self.tokenizer = tiktoken.encoding_for_model('gpt-4-1106-previe3') # Probably need to change in future | ||
self.model_to_test = Together(model=f'mistralai/{self.model_name}', temperature=0) | ||
kwargs['context_lengths_max'] = 32000 | ||
super().__init__(**kwargs) | ||
|
||
|
||
|
||
def get_encoding(self,context): | ||
return self.tokenizer.encode(context) | ||
|
||
def get_decoding(self, encoded_context): | ||
return self.tokenizer.decode(encoded_context) | ||
|
||
def get_prompt(self, context): | ||
with open('Google_prompt.txt', 'r') as file: # Need to change it | ||
prompt = file.read() | ||
return prompt.format(retrieval_question=self.retrieval_question, context=context) | ||
|
||
async def get_response_from_model(self, prompt): | ||
response = self.model_to_test.invoke( # Need to make it async | ||
prompt | ||
) | ||
return response | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
# Tons of defaults set, check out the LLMNeedleHaystackTester's init for more info | ||
ht = OSS_TogetherEvaluator(model_name='Mistral-7B-Instruct-v0.2', evaluation_method='substring_match', | ||
save_results_dir='results/Mixtral_7B/results-run2', | ||
save_contexts_dir='contexts/Mixtral_7B/contexts-run2' | ||
) | ||
|
||
ht.start_test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters