1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
import torch
import transformers
from langchain import LLMChain, PromptTemplate
class AIAgent:
def __init__(self, config):
self.model_name = config["model"]
self.temperature = config["temperature"]
self.max_tokens = config["max_tokens"]
self.model = self._load_model()
def _load_model(self):
# Initialize model from Hugging Face
model = transformers.AutoModelForCausalLM.from_pretrained(
self.model_name,
torch_dtype=torch.float16,
device_map="auto"
)
return model
def generate(self, prompt):
# Generate text using the model
inputs = transformers.AutoTokenizer.from_pretrained(
self.model_name
)(prompt, return_tensors="pt").to("cuda")
outputs = self.model.generate(
inputs["input_ids"],
max_new_tokens=self.max_tokens,
temperature=self.temperature
)
return outputs
# Initialize AI agent with configuration
llm_config = {
"model": "llama-3",
"temperature": 0.7,
"max_tokens": 1024
}
agent = AIAgent(llm_config)
# Define a prompt for the AI
prompt = """
Generate a creative solution for the following problem:
How can we use computer vision to improve healthcare?
"""
# Generate response
response = agent.generate(prompt)
print(response)
Subhash B S
AI Engineer | LLM Specialist | ML Researcher
I specialize in Generative AI, LLM Systems, AI Agents, and Computer Vision with expertise in building real-world solutions using PyTorch, TensorFlow, LangChain, and Hugging Face. Passionate about creating innovative AI applications with measurable impact.
{
}
<>
/>
()
[]
=>