TextGen / load_model.py
abdullah10's picture
Upload 35 files
8bc7dc5
from langchain.llms import GooglePalm, LlamaCpp
def call_palm(google_api_key, temperature=0, max_tokens=8000, top_p=0.95, top_k=40, n_batch=9, repeat_penalty=1.1, n_ctx=8000):
'''
desc:
call_palm() is a fuction can be used to instantiate a Google Palm model.
this model can be used to generate text, translate languages, write different kinds of creative content, and answer your questions in an informative way.
'''
'''
Params and args:
google_api_key (str): Required Parameter -> The Google API key for the Palm model.
temperature (float): Optional Parameter -> The temperature parameter controls the randomness of the generated text. A higher temperature will result in more creative and varied text, but it may also be less accurate.
max_output_tokens (int): Optional Parameter -> The maximum number of tokens to generate.
top_p (float): Optional Parameter -> The top_p parameter controls the diversity of the generated text. A higher top_p will result in more diverse text, but it may also be less coherent.
top_k (int): Optional Parameter -> The top_k parameter controls the number of tokens to consider when generating text. A higher top_k will result in more accurate text, but it may also be less creative.
n_batch (int): Optional Parameter -> The n_batch parameter controls the number of batches to use when generating text. A higher n_batch will result in faster generation, but it may also be less accurate.
repeat_penalty (float): Optional Parameter -> The repeat_penalty parameter controls the penalty for repeating tokens. A higher repeat_penalty will result in more diverse text, but it may also be less fluent.
n_ctx (int): Optional Parameter -> The n_ctx parameter controls the context length used to generate text. A higher n_ctx will result in more coherent text, but it may also be slower to generate.
'''
'''
return:
This function returns Google Palm as language model object.
This object can be used to generate text, translate languages, write different kinds of creative content, and answer your questions in an informative way.
'''
google_palm_model = GooglePalm(
google_api_key=google_api_key,
temperature=temperature,
max_output_tokens=max_tokens,
top_p=top_p,
top_k=top_k,
n_batch=n_batch,
repeat_penalty = repeat_penalty,
n_ctx = n_ctx
)
return google_palm_model
def call_llama2(model_path, temperature=0, max_tokens=8192, top_p=0.95, top_k=40, n_batch=9, repeat_penalty=1.1, n_ctx=8192):
'''
desc:
call_llama() is a fuction can be used to instantiate a Meta llama-2 13B model.
this model can be used to generate text, translate languages, write different kinds of creative content, and answer your questions in an informative way.
'''
'''
Params and args:
model_path (str): Required Parameter -> The path to the Llama model file.
temperature (float): Optional Parameter -> The temperature parameter controls the randomness of the generated text. A higher temperature will result in more creative and varied text, but it may also be less accurate.
max_tokens (int): Optional Parameter -> The maximum number of tokens to generate.
top_p (float): Optional Parameter -> The top_p parameter controls the diversity of the generated text. A higher top_p will result in more diverse text, but it may also be less coherent.
top_k (int): Optional Parameter -> The top_k parameter controls the number of tokens to consider when generating text. A higher top_k will result in more accurate text, but it may also be less creative.
n_batch (int): Optional Parameter -> The n_batch parameter controls the number of batches to use when generating text. A higher n_batch will result in faster generation, but it may also be less accurate.
repeat_penalty (float): Optional Parameter -> The repeat_penalty parameter controls the penalty for repeating tokens. A higher repeat_penalty will result in more diverse text, but it may also be less fluent.
n_ctx (int): Optional Parameter -> The n_ctx parameter controls the context length used to generate text. A higher n_ctx will result in more coherent text, but it may also be slower to generate.
'''
'''
return:
This function returns Meta llama-2 13B as language model object.
This object can be used to generate text, translate languages, write different kinds of creative content, and answer your questions in an informative way.
'''
llm = LlamaCpp(
model_path=model_path,
temperature=temperature,
max_tokens=max_tokens,
top_p=top_p,
top_k=top_k,
n_batch=n_batch,
repeat_penalty=repeat_penalty,
n_ctx=n_ctx
)
return llm