Guhanselvam commited on
Commit
f15d385
·
verified ·
1 Parent(s): 146c9e6

Rename client.py to api.py

Browse files
Files changed (2) hide show
  1. api.py +17 -0
  2. client.py +0 -7
api.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer
2
+ import torch
3
+
4
+ class LlamaChatbot:
5
+ def __init__(self, model_name="meta-llama/Llama-3.2-7b"):
6
+ self.tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ self.model = AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ def get_response(self, user_input: str, conversation_history: str) -> str:
10
+ # Combine user input with the conversation history
11
+ input_text = conversation_history + user_input + " "
12
+
13
+ inputs = self.tokenizer(input_text, return_tensors="pt")
14
+ outputs = self.model.generate(**inputs, max_length=150)
15
+ response = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
16
+
17
+ return response.strip()
client.py DELETED
@@ -1,7 +0,0 @@
1
- import requests
2
-
3
- response=requests.post(
4
- "http://localhost:8000/essay/invoke",
5
- json={'input':{'topic':"my best friend"}})
6
-
7
- print(response.json()['output']['content'])