K00B404 commited on
Commit
2346874
1 Parent(s): 9807ba6

Update babi_app.py

Browse files
Files changed (1) hide show
  1. babi_app.py +33 -49
babi_app.py CHANGED
@@ -15,7 +15,7 @@ from langchain.callbacks.manager import CallbackManagerForLLMRun
15
  from langchain.chat_models.base import BaseChatModel
16
  from typing import Any, Iterator, List, Optional
17
  from huggingface_hub import login
18
- # from elevenlabs import set_api_key
19
  from tempfile import TemporaryDirectory
20
  from langchain_community.tools.eleven_labs.text2speech import ElevenLabsText2SpeechTool
21
  from langchain.utilities.serpapi import SerpAPIWrapper
@@ -23,22 +23,8 @@ from langchain_community.embeddings import HuggingFaceEmbeddings
23
  from langchain_community.llms import HuggingFaceHub
24
  warnings.filterwarnings('ignore')
25
 
26
- from credits import (
27
- HUGGINGFACE_TOKEN,
28
- HUGGINGFACE_TOKEN as HUGGINGFACEHUB_API_TOKEN,
29
- HUGGINGFACE_EMAIL,
30
- HUGGINGFACE_PASS,
31
- OPENAI_API_KEY,
32
- ELEVENLABS_API_KEY,
33
- SERPAPI_API_KEY)
34
-
35
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = HUGGINGFACEHUB_API_TOKEN
36
- os.environ["HUGGINGFACE_TOKEN"] = HUGGINGFACE_TOKEN
37
- os.environ["HUGGINGFACE_EMAIL"] = HUGGINGFACE_EMAIL
38
- os.environ["HUGGINGFACE_PASS"] = HUGGINGFACE_PASS
39
- os.environ["SERPAPI_API_KEY"] = SERPAPI_API_KEY
40
- os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
41
- os.environ["ELEVEN_API_KEY"] = ELEVENLABS_API_KEY
42
 
43
  if os.path.exists("/home/codemonkeyxl/.cache/huggingface/token"):
44
  newsession_bool = False
@@ -47,7 +33,7 @@ else:
47
  newsession_bool = True
48
  write_permission_bool = False
49
 
50
- login(HUGGINGFACEHUB_API_TOKEN, new_session= newsession_bool, write_permission= write_permission_bool )
51
 
52
  import langchain
53
  from langchain.chains import LLMChain
@@ -63,11 +49,9 @@ import streamlit as st
63
 
64
  from langchain.llms.base import LLM
65
 
66
- ##set_api_key(ELEVENLABS_API_KEY)
67
  tts = ElevenLabsText2SpeechTool()
68
  serp_search = SerpAPIWrapper()
69
 
70
- from credits import HUGGINGFACE_TOKEN
71
 
72
  embeddings= HuggingFaceEmbeddings(
73
  model_name="all-MiniLM-L6-v2",
@@ -75,9 +59,10 @@ embeddings= HuggingFaceEmbeddings(
75
  encode_kwargs = {'normalize_embeddings': True}
76
  )
77
 
78
- openllm= HuggingFaceHub( repo_id="openchat/openchat_3.5", task="text-generation", model_kwargs = {"min_length": 16,"max_length":1000,"temperature":0.1, "max_new_tokens":512, "num_return_sequences":1 })
 
79
  best_llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", task="text-generation",
80
- model_kwargs = {"min_length": 200,"max_length":1000,"temperature":0.1, "max_new_tokens":512, "num_return_sequences":1})
81
 
82
  # Set Variables
83
  load_dotenv()
@@ -218,7 +203,6 @@ class Message:
218
 
219
  class BabyAGI(BaseModel):
220
  """Controller model for the BabyAGI agent."""
221
-
222
  objective: str = Field(alias="objective")
223
  task_list: deque = Field(default_factory=deque)
224
  task_creation_chain: TaskCreationChain = Field(...)
@@ -317,31 +301,31 @@ class BabyAGI(BaseModel):
317
 
318
  @classmethod
319
  def from_llm_and_objectives(
320
- cls,
321
- llm: BaseLLM,
322
- vectorstore: VectorStore,
323
- objective: str,
324
- first_task: str,
325
- verbose: bool = False,
326
- ) -> "BabyAGI":
327
- """Initialize the BabyAGI Controller."""
328
- task_creation_chain = TaskCreationChain.from_llm(
329
- llm, objective, verbose=verbose
330
- )
331
- task_prioritization_chain = TaskPrioritizationChain.from_llm(
332
- llm, objective, verbose=verbose
333
- )
334
- execution_chain = ExecutionChain.from_llm(llm, vectorstore, verbose=verbose)
335
- controller = cls(
336
- objective=objective,
337
- task_creation_chain=task_creation_chain,
338
- task_prioritization_chain=task_prioritization_chain,
339
- execution_chain=execution_chain,
340
- )
341
- #task_id = int(time.time())
342
- #controller.add_task({"task_id": task_id, "task_name": first_task})
343
- controller.add_task({"task_id": 1, "task_name": first_task})
344
- return controller
345
 
346
 
347
  def main():
@@ -361,7 +345,7 @@ def main():
361
  max_iterations = st.number_input("Max iterations", value=3, min_value=1, step=1)
362
  button = st.button("Run")
363
 
364
- embedding_model = HuggingFaceInferenceAPIEmbeddings(api_key=os.environ["HUGGINGFACE_TOKEN"])
365
 
366
  vectorstore = FAISS.from_texts(["_"], embedding_model, metadatas=[{"task":first_task}])
367
 
 
15
  from langchain.chat_models.base import BaseChatModel
16
  from typing import Any, Iterator, List, Optional
17
  from huggingface_hub import login
18
+
19
  from tempfile import TemporaryDirectory
20
  from langchain_community.tools.eleven_labs.text2speech import ElevenLabsText2SpeechTool
21
  from langchain.utilities.serpapi import SerpAPIWrapper
 
23
  from langchain_community.llms import HuggingFaceHub
24
  warnings.filterwarnings('ignore')
25
 
26
+
27
+ HUGGINGFACE_TOKEN = os.getenv["HUGGINGFACE_TOKEN"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  if os.path.exists("/home/codemonkeyxl/.cache/huggingface/token"):
30
  newsession_bool = False
 
33
  newsession_bool = True
34
  write_permission_bool = False
35
 
36
+ login(HUGGINGFACE_TOKEN, new_session= newsession_bool, write_permission= write_permission_bool )
37
 
38
  import langchain
39
  from langchain.chains import LLMChain
 
49
 
50
  from langchain.llms.base import LLM
51
 
 
52
  tts = ElevenLabsText2SpeechTool()
53
  serp_search = SerpAPIWrapper()
54
 
 
55
 
56
  embeddings= HuggingFaceEmbeddings(
57
  model_name="all-MiniLM-L6-v2",
 
59
  encode_kwargs = {'normalize_embeddings': True}
60
  )
61
 
62
+ openllm= HuggingFaceHub( repo_id="openchat/openchat_3.5", task="text-generation",
63
+ model_kwargs = {"min_length": 16,"max_length":1000,"temperature":0.1, "max_new_tokens":512, "num_return_sequences":1 })
64
  best_llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", task="text-generation",
65
+ model_kwargs = {"min_length": 200,"max_length":1000,"temperature":0.1, "max_new_tokens":512, "num_return_sequences":1})
66
 
67
  # Set Variables
68
  load_dotenv()
 
203
 
204
  class BabyAGI(BaseModel):
205
  """Controller model for the BabyAGI agent."""
 
206
  objective: str = Field(alias="objective")
207
  task_list: deque = Field(default_factory=deque)
208
  task_creation_chain: TaskCreationChain = Field(...)
 
301
 
302
  @classmethod
303
  def from_llm_and_objectives(
304
+ cls,
305
+ llm: BaseLLM,
306
+ vectorstore: VectorStore,
307
+ objective: str,
308
+ first_task: str,
309
+ verbose: bool = False,
310
+ ) -> "BabyAGI":
311
+ """Initialize the BabyAGI Controller."""
312
+ task_creation_chain = TaskCreationChain.from_llm(
313
+ llm, objective, verbose=verbose
314
+ )
315
+ task_prioritization_chain = TaskPrioritizationChain.from_llm(
316
+ llm, objective, verbose=verbose
317
+ )
318
+ execution_chain = ExecutionChain.from_llm(llm, vectorstore, verbose=verbose)
319
+ controller = cls(
320
+ objective=objective,
321
+ task_creation_chain=task_creation_chain,
322
+ task_prioritization_chain=task_prioritization_chain,
323
+ execution_chain=execution_chain,
324
+ )
325
+ #task_id = int(time.time())
326
+ #controller.add_task({"task_id": task_id, "task_name": first_task})
327
+ controller.add_task({"task_id": 1, "task_name": first_task})
328
+ return controller
329
 
330
 
331
  def main():
 
345
  max_iterations = st.number_input("Max iterations", value=3, min_value=1, step=1)
346
  button = st.button("Run")
347
 
348
+ embedding_model = HuggingFaceInferenceAPIEmbeddings(api_key=os.getenv["HUGGINGFACE_TOKEN"])
349
 
350
  vectorstore = FAISS.from_texts(["_"], embedding_model, metadatas=[{"task":first_task}])
351