Skip to content

Commit

Permalink
Bugfixes and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Sep 28, 2024
1 parent 7153aaa commit 790d1c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/askai/core/component/internet_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from typing import List

import bs4
import openai
from askai.__classpath__ import API_KEYS
from askai.core.askai_configs import configs
from askai.core.askai_events import events
Expand All @@ -46,6 +45,7 @@
from langchain_core.tools import Tool
from langchain_google_community import GoogleSearchAPIWrapper
from langchain_text_splitters import RecursiveCharacterTextSplitter
from openai import APIError


class InternetService(metaclass=Singleton):
Expand Down Expand Up @@ -181,7 +181,7 @@ def google_search(self, search: SearchResult) -> str:
lc_llm.create_chat_model(temperature=Temperature.COLDEST.temp), llm_prompt
)
output = chain.invoke({"question": question, "context": docs})
except (HttpError, openai.APIError) as err:
except (HttpError, APIError) as err:
return msg.fail_to_search(str(err))

return self.refine_search(terms, output, search)
Expand Down
12 changes: 10 additions & 2 deletions src/main/askai/core/features/router/task_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
from askai.core.model.ai_reply import AIReply
from askai.core.support.langchain_support import lc_llm
from askai.core.support.shared_instances import shared
from askai.exception.exceptions import InaccurateResponse
from hspylib.core.config.path_object import PathObject
from hspylib.core.metaclass.singleton import Singleton
from langchain.agents import AgentExecutor, create_structured_chat_agent
from langchain.memory.chat_memory import BaseChatMemory
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.runnables import Runnable
from langchain_core.runnables.utils import Output
from openai import APIError


class TaskAgent(metaclass=Singleton):
Expand Down Expand Up @@ -94,8 +96,14 @@ def _exec_task(self, task: AnyStr) -> Optional[Output]:
:return: An instance of Output containing the result of the task, or None if the task fails or produces
no output.
"""
lc_agent: Runnable = self._create_lc_agent()
return lc_agent.invoke({"input": task})
output: str | None = None
try:
lc_agent: Runnable = self._create_lc_agent()
output = lc_agent.invoke({"input": task})
except APIError as err:
raise InaccurateResponse(str(err))

return output


assert (agent := TaskAgent().INSTANCE) is not None
1 change: 1 addition & 0 deletions src/main/askai/resources/prompts/search-builder.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Your task is to respond to a user query following the steps below. You MUST foll

8. **Map Inquiries:** For map-related inquiries, add the filter: 'map:"<location>"' to your list.

9. **General Search:** For broad inquiries or searches where the nature of the query cannot be determined, avoid using restrictive filters. Instead, rely on general search engines such as "google.com", "bing.com", "duckduckgo.com", and "ask.com."

The response should follow this format:

Expand Down

0 comments on commit 790d1c6

Please sign in to comment.