Skip to content

Commit

Permalink
testllm
Browse files Browse the repository at this point in the history
  • Loading branch information
pokhiii committed Nov 13, 2024
1 parent 7958598 commit b9c32d5
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions testLlm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import torch
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
from datetime import datetime
from dotenv import load_dotenv

# Load the environment variables from the .env file
load_dotenv()

# # Local path to your saved model
# model_path = "./training/models/fine_tuned_model"
# tokenizer = AutoTokenizer.from_pretrained(model_path)
# model = AutoModelForCausalLM.from_pretrained(model_path)

# # Use pipeline for text generation
# pipe = pipeline(
# "text-generation",
# model=model,
# tokenizer=tokenizer,
# torch_dtype=torch.bfloat16,
# device_map="auto",
# )


model_id = "coloredcow/paani-1b-instruct-marathi"

pipe = pipeline(
"text-generation",
model=model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)

selected_language = 'en'
language_configs = {
"en": {
"chatbot_instruction": "Please answer the following question in English:\n",
},
"hi": {
"chatbot_instruction": "कृपया निम्नलिखित प्रश्न का उत्तर हिंदी में दें:\n",
},
"mr": {
"chatbot_instruction": "कृपया पुढील प्रश्नाचे उत्तर मराठीत द्या:\n",
},
"bn": {
"chatbot_instruction": "দয়া করে নিচের প্রশ্নের উত্তর দিন মারাঠিতে:\n",
},
}

def get_chatbot_response(input_text, language):
instruction = language_configs[language]['chatbot_instruction']
prompt = instruction + input_text

messages = [{"role": "user", "content": prompt}]
outputs = pipe(
messages,
max_new_tokens=256,
do_sample=False,
)
response = outputs[0]["generated_text"]
return response

# Interactive loop for user input
print("Chatbot is ready! Type 'exit' to quit.\n")

while True:
# Prompt the user for input
user_input = input("You: ")

# Check if the user wants to exit
if user_input.lower() in ["exit", "quit"]:
print("Exiting the chatbot. Goodbye!")
break

# Get and print the chatbot response
response_text = get_chatbot_response(user_input, selected_language)
print("Chatbot:", response_text)

0 comments on commit b9c32d5

Please sign in to comment.