Skip to content

Commit b4fb586

Browse files
committed
Before LangChain updates
1 parent 01b0727 commit b4fb586

File tree

5 files changed

+51
-35
lines changed

5 files changed

+51
-35
lines changed

src/demo/components/internet_demo.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ def serapi_search(query: str, max_pages: int = 3) -> str:
6767

6868
while (question := line_input("You: ")) not in ["exit", "q", "quit"]:
6969
kw: list[str] = re.split("[ ,;]", question)
70-
sites: list[str] = ["https://flamengo.com.br/"]
70+
sites: list[str] = [
71+
"https://google.com/",
72+
"https://linkedin.com/",
73+
"https://github.com/",
74+
"https://instagram.com/"
75+
]
7176
q = SearchResult(question, geo_location.datetime, "news", kw, sites)
72-
# answer = internet.google_search(q)
73-
answer = internet.scrap_sites(q)
77+
answer = internet.google_search(q)
78+
# answer = internet.scrap_sites(q)
7479
# answer = serapi_search(qq)
7580
sysout(f"%GREEN%AI: {answer}")
7681
cache.save_input_history()

src/main/askai/core/component/internet_service.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,12 @@ def wrap_response(cls, keywords: str, output: str, search: SearchResult) -> str:
111111
sites: list = re.findall(re_site, keywords)
112112
terms: str = re.sub(r"\s{2,}", " ", re.sub(r"OR", "", re.sub(re_site, "", keywords)))
113113
sources: str = " ".join(sorted([f"{cls._url_to_icon(s):<2}".strip() or s for s in sites], key=len))
114+
category: str = search.category.capitalize()
114115
# fmt: off
115116
return (
116117
f"Your {search.engine.title()} search has returned the following results:"
117118
f"\n\n{output}\n\n---\n\n"
118-
f"`{cls.CATEGORY_ICONS[search.category]:<2}{search.category}` "
119+
f"`{cls.CATEGORY_ICONS[category]:<2}{category}` "
119120
f"**Sources:** *{sources}* "
120121
f"**Access:** {geo_location.location} - *{now('%B %d, %Y')}*\n\n"
121122
f">  Terms: {terms} \n")
@@ -169,17 +170,18 @@ def __init__(self):
169170
def refine_template(self) -> str:
170171
return prompt.read_prompt("refine-search")
171172

172-
def google_search(self, search: SearchResult) -> str:
173+
def google_search(self, search: SearchResult, k: int = 5) -> str:
173174
"""Search the web using the Google Search API. This method utilizes advanced Google search operators to refine
174175
and execute the search.
175176
Reference: https://ahrefs.com/blog/google-advanced-search-operators/
176177
:param search: The AI search parameters encapsulated in a SearchResult object.
178+
:param k: The number of top search results to retrieve.
177179
:return: A refined string containing the search results.
178180
"""
179181
# Lazy initialization to allow GOOGLE_API_KEY be optional.
180182
if not self._google:
181183
API_KEYS.ensure("GOOGLE_API_KEY", "google_search")
182-
self._google = GoogleSearchAPIWrapper(k=5, google_api_key=API_KEYS.GOOGLE_API_KEY)
184+
self._google = GoogleSearchAPIWrapper(k=k, google_api_key=API_KEYS.GOOGLE_API_KEY)
183185
self._tool = Tool(
184186
name="google_search", description="Search Google for recent results.", func=self._google.run
185187
)

src/main/askai/core/engine/openai/openai_engine.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def lc_chat_model(self, temperature: float) -> BaseChatModel:
111111
:return: An instance of BaseChatModel.
112112
"""
113113
return langchain_openai.ChatOpenAI(
114-
model=self._model.model_name(), temperature=temperature
114+
model=self._model.model_name(),
115+
temperature=temperature
115116
)
116117

117118
def lc_embeddings(self, model: str) -> Embeddings:

src/main/askai/core/engine/openai/openai_model.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,43 @@ class OpenAIModel(Enumeration):
2424
"""
2525

2626
# ID of the model to use. Currently, only the values below are supported:
27+
# Note: These prices are estimates based on historical trends and reported updates as of December 2025.
28+
# Actual OpenAI API pricing evolves frequently (e.g., GPT-4o updated to ~$5/$15).
29+
# Reasoning models (o-series) may have additional costs for thinking tokens.
30+
# Always verify the latest official rates at https://openai.com/api/pricing/ as models like GPT-5.2 and
31+
# newer variants have taken precedence. Legacy models may be deprecated or repriced.
2732

2833
# fmt: off
29-
30-
GPT_5 = "gpt-5", 1_000_000
31-
GPT_5_MINI = "gpt-5-mini", 1_000_000
32-
GPT_5_NANO = "gpt-5-nano", 1_000_000
33-
GPT_5_CHAT = "gpt-5-chat", 1_000_000
34-
GPT_4 = "gpt-4", 8192
35-
GPT_4_TURBO = "gpt-4-turbo", 128000
36-
GPT_4_O = "gpt-4o", 128000
37-
GPT_4_O_MINI = "gpt-4o-mini", 128000
38-
GPT_4_1 = "gpt-4.1", 1_000_000
39-
GPT_4_1_MINI = "gpt-4.1-mini", 1_000_000
40-
GPT_4_1_NANO = "gpt-4.1-nano", 1_000_000
41-
GPT_4_5 = "gpt-4.5", 128000
42-
O1 = "o1", 128000
43-
O1_PREVIEW = "o1-preview", 128000
44-
O1_MINI = "o1-mini", 128000
45-
O1_PRO = "o1-pro", 128000
46-
O3 = "o3", 128000
47-
O3_MINI = "o3-mini", 128000
48-
O3_MINI_HIGH = "o3-mini-high", 128000
49-
O3_PRO = "o3-pro", 128000
50-
O4_MINI = "o4-mini", 128000
51-
O4_MINI_HIGH = "o4-mini-high", 128000
52-
34+
GPT_5 = "gpt-5", 1_000_000 # Input: $1.25 / 1M, Output: $10.00 / 1M (estimated for flagship series)
35+
GPT_5_CHAT = "gpt-5-chat", 1_000_000 # Input: $1.25 / 1M, Output: $10.00 / 1M
36+
GPT_5_MINI = "gpt-5-mini", 1_000_000 # Input: $0.25 / 1M, Output: $2.00 / 1M
37+
GPT_5_NANO = "gpt-5-nano", 1_000_000 # Input: $0.05 / 1M, Output: $0.40 / 1M
38+
GPT_5_1 = "gpt-5.1", 1_000_000 # Input: $1.25 / 1M, Output: $10.00 / 1M
39+
GPT_5_1_CHAT = "gpt-5.1-chat", 1_000_000 # Input: $1.25 / 1M, Output: $10.00 / 1M
40+
GPT_5_1_MINI = "gpt-5.1-mini", 1_000_000 # Input: $0.25 / 1M, Output: $2.00 / 1M
41+
GPT_5_1_NANO = "gpt-5.1-nano", 1_000_000 # Input: $0.20 / 1M, Output: $0.80 / 1M
42+
GPT_5_2 = "gpt-5.2", 1_000_000 # Input: $1.75 / 1M, Output: $14.00 / 1M
43+
GPT_5_2_CHAT = "gpt-5.2-chat", 1_000_000 # Input: $1.75 / 1M, Output: $14.00 / 1M
44+
GPT_5_2_MINI = "gpt-5.2-mini", 1_000_000 # Input: $0.25 / 1M, Output: $2.00 / 1M
45+
GPT_5_2_NANO = "gpt-5.2-nano", 1_000_000 # Input: $0.20 / 1M, Output: $0.80 / 1M
46+
GPT_4 = "gpt-4", 8192 # Legacy; refer to current pricing for equivalents
47+
GPT_4_TURBO = "gpt-4-turbo", 128000 # Legacy; refer to current pricing for equivalents
48+
GPT_4_O = "gpt-4o", 128000 # Input: $5.00 / 1M, Output: $15.00 / 1M (updated late 2025)
49+
GPT_4_O_MINI = "gpt-4o-mini", 128000 # Input: $0.15 / 1M, Output: $0.60 / 1M (or similar; check latest)
50+
GPT_4_1 = "gpt-4.1", 1_000_000 # Input: $3.00 / 1M, Output: $12.00 / 1M (approximate)
51+
GPT_4_1_MINI = "gpt-4.1-mini", 1_000_000 # Input: $0.80 / 1M, Output: $3.20 / 1M (approximate)
52+
GPT_4_1_NANO = "gpt-4.1-nano", 1_000_000 # Input: $0.20 / 1M, Output: $0.80 / 1M
53+
GPT_4_5 = "gpt-4.5", 128000 # Legacy/preview; refer to current equivalents
54+
O1 = "o1", 128000 # Input: $15.00 / 1M, Output: $60.00 / 1M (reasoning tokens extra)
55+
O1_PREVIEW = "o1-preview", 128000 # Similar to o1
56+
O1_MINI = "o1-mini", 128000 # Input: $3.00 / 1M, Output: $12.00 / 1M (approximate)
57+
O1_PRO = "o1-pro", 128000 # Higher pricing variant
58+
O3 = "o3", 128000 # Input: $2.00 / 1M, Output: $8.00 / 1M (post price drop)
59+
O3_MINI = "o3-mini", 128000 # Input: $1.10 / 1M, Output: $4.40 / 1M
60+
O3_MINI_HIGH = "o3-mini-high", 128000 # Input: ~$4.00 / 1M, Output: ~$16.00 / 1M (higher effort)
61+
O3_PRO = "o3-pro", 128000 # Input: $20.00 / 1M, Output: $80.00 / 1M
62+
O4_MINI = "o4-mini", 128000 # Input: $1.10 / 1M, Output: $4.40 / 1M (base)
63+
O4_MINI_HIGH = "o4-mini-high", 128000 # Input: $4.00 / 1M, Output: $16.00 / 1M (higher effort)
5364
# fmt: on
5465

5566
@staticmethod

src/main/askai/core/router/task_agent.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
1313
Copyright (c) 2024, AskAI
1414
"""
15-
from langchain_classic.agents import create_structured_chat_agent, AgentExecutor
16-
from langchain_classic.memory.chat_memory import BaseChatMemory
17-
1815
from askai.core.askai_configs import configs
1916
from askai.core.askai_events import events
2017
from askai.core.askai_messages import msg
@@ -106,7 +103,7 @@ def _exec_task(self, task: AnyStr) -> Optional[dict[str, str]]:
106103
output: dict[str, str] | None = None
107104
try:
108105
lc_agent: Runnable = self._create_lc_agent()
109-
output: dict[str, str] = lc_agent.invoke({"input": task})
106+
output: dict[str, str] = lc_agent.invoke({"input": task, "stop": None})
110107
except (openai.APIError, ValueError, ValidationError) as err:
111108
log.error(str(err))
112109
output: dict[str, str] = {"output": str(err)}

0 commit comments

Comments
 (0)