Spaces:
Sleeping
Sleeping
groq-llama-3.1
Browse files- app.py +7 -12
- requirements.txt +0 -0
app.py
CHANGED
|
@@ -5,7 +5,9 @@ from dotenv import load_dotenv
|
|
| 5 |
import inspect
|
| 6 |
import pandas as pd
|
| 7 |
from langchain_community.tools import DuckDuckGoSearchRun
|
|
|
|
| 8 |
from langchain_huggingface import ChatHuggingFace, HuggingFacePipeline
|
|
|
|
| 9 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 10 |
|
| 11 |
|
|
@@ -18,16 +20,12 @@ class BasicAgent:
|
|
| 18 |
|
| 19 |
|
| 20 |
def __init__(self):
|
| 21 |
-
self.
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
max_new_tokens=1024
|
| 27 |
)
|
| 28 |
-
self.llm = HuggingFacePipeline(pipeline=pipe)
|
| 29 |
-
self.model = ChatHuggingFace(llm=self.llm, verbose=True)
|
| 30 |
-
self.search = DuckDuckGoSearchRun()
|
| 31 |
print("BasicAgent initialized.")
|
| 32 |
|
| 33 |
|
|
@@ -37,9 +35,6 @@ class BasicAgent:
|
|
| 37 |
prompt = f"""
|
| 38 |
Give concise answer to this question: {question}
|
| 39 |
"""
|
| 40 |
-
# try:
|
| 41 |
-
# fixed_answer = self.search.invoke(question)
|
| 42 |
-
# except Exception as _:
|
| 43 |
pattern = r'.*?<start_of_turn>model'
|
| 44 |
fixed_answer = self.model.invoke(prompt).content
|
| 45 |
fixed_answer = re.sub(pattern, '', fixed_answer, flags=re.DOTALL)
|
|
|
|
| 5 |
import inspect
|
| 6 |
import pandas as pd
|
| 7 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 8 |
+
from langchain_groq import ChatGroq
|
| 9 |
from langchain_huggingface import ChatHuggingFace, HuggingFacePipeline
|
| 10 |
+
from openai import api_key
|
| 11 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 12 |
|
| 13 |
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
def __init__(self):
|
| 23 |
+
self.model = ChatGroq(
|
| 24 |
+
model="llama-3.1-8b-instant",
|
| 25 |
+
temperature=0.0,
|
| 26 |
+
max_new_tokens=1024,
|
| 27 |
+
api_key=os.getenv("GROQ_API_KEY")
|
|
|
|
| 28 |
)
|
|
|
|
|
|
|
|
|
|
| 29 |
print("BasicAgent initialized.")
|
| 30 |
|
| 31 |
|
|
|
|
| 35 |
prompt = f"""
|
| 36 |
Give concise answer to this question: {question}
|
| 37 |
"""
|
|
|
|
|
|
|
|
|
|
| 38 |
pattern = r'.*?<start_of_turn>model'
|
| 39 |
fixed_answer = self.model.invoke(prompt).content
|
| 40 |
fixed_answer = re.sub(pattern, '', fixed_answer, flags=re.DOTALL)
|
requirements.txt
CHANGED
|
Binary files a/requirements.txt and b/requirements.txt differ
|
|
|