Error: Can any one help?
Describe the bug issue while running devika.py
24.04.04 07:41:04: root: INFO : Initializing Devika...
24.04.04 07:41:04: root: INFO : Initializing Prerequisites Jobs...
24.04.04 07:41:10: root: INFO : Loading sentence-transformer BERT models...
24.04.04 07:41:14: root: INFO : BERT model loaded successfully.
24.04.04 07:41:15: root: INFO : Ollama available
Traceback (most recent call last):
File ".\devika.py", line 26, in
I got the same error
Follow the Bug Report template for reporting errors, as it guarantees a better understanding and readability for fellow users and developers.
Upgrade python version to python 3.10 or 3.11
upgrading python version is not working
Change the code in the file path 'src/agents/researcher/researcher.py' to this code
import json
from typing import List
from jinja2 import Environment, BaseLoader
from typing import Union
from src.llm import LLM
from src.browser.search import BingSearch
PROMPT = open("src/agents/researcher/prompt.jinja2").read().strip()
class Researcher:
def __init__(self, base_model: str):
self.bing_search = BingSearch()
self.llm = LLM(model_id=base_model)
def render(self, step_by_step_plan: str, contextual_keywords: str) -> str:
env = Environment(loader=BaseLoader())
template = env.from_string(PROMPT)
return template.render(
step_by_step_plan=step_by_step_plan,
contextual_keywords=contextual_keywords
)
def validate_response(self, response: str) -> Union[dict , bool]:
response = response.strip().replace("```json", "```")
if response.startswith("```") and response.endswith("```"):
response = response[3:-3].strip()
try:
response = json.loads(response)
except Exception as _:
return False
response = {k.replace("\\", ""): v for k, v in response.items()}
if "queries" not in response and "ask_user" not in response:
return False
else:
return {
"queries": response["queries"],
"ask_user": response["ask_user"]
}
def execute(self, step_by_step_plan: str, contextual_keywords: List[str], project_name: str) -> Union[dict , bool]:
contextual_keywords_str = ", ".join(map(lambda k: k.capitalize(), contextual_keywords))
prompt = self.render(step_by_step_plan, contextual_keywords_str)
response = self.llm.inference(prompt, project_name)
valid_response = self.validate_response(response)
while not valid_response:
print("Invalid response from the model, trying again...")
return self.execute(step_by_step_plan, contextual_keywords, project_name)
return valid_response
Thank me later 👋
Change the code in the file path 'src/agents/researcher/researcher.py' to this code
import json from typing import List from jinja2 import Environment, BaseLoader from typing import Union from src.llm import LLM from src.browser.search import BingSearch PROMPT = open("src/agents/researcher/prompt.jinja2").read().strip() class Researcher: def __init__(self, base_model: str): self.bing_search = BingSearch() self.llm = LLM(model_id=base_model) def render(self, step_by_step_plan: str, contextual_keywords: str) -> str: env = Environment(loader=BaseLoader()) template = env.from_string(PROMPT) return template.render( step_by_step_plan=step_by_step_plan, contextual_keywords=contextual_keywords ) def validate_response(self, response: str) -> Union[dict , bool]: response = response.strip().replace("```json", "```") if response.startswith("```") and response.endswith("```"): response = response[3:-3].strip() try: response = json.loads(response) except Exception as _: return False response = {k.replace("\\", ""): v for k, v in response.items()} if "queries" not in response and "ask_user" not in response: return False else: return { "queries": response["queries"], "ask_user": response["ask_user"] } def execute(self, step_by_step_plan: str, contextual_keywords: List[str], project_name: str) -> Union[dict , bool]: contextual_keywords_str = ", ".join(map(lambda k: k.capitalize(), contextual_keywords)) prompt = self.render(step_by_step_plan, contextual_keywords_str) response = self.llm.inference(prompt, project_name) valid_response = self.validate_response(response) while not valid_response: print("Invalid response from the model, trying again...") return self.execute(step_by_step_plan, contextual_keywords, project_name) return valid_responseThank me later 👋
@Abhishekrajpurohit Thank you, It worked. You should raise a PR with the changes.