-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from LemurPwned/feat/query-optim
Feat/query optim
- Loading branch information
Showing
9 changed files
with
101 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from typing import Any | ||
|
||
from rich.markdown import Markdown | ||
from swarm import Swarm | ||
|
||
from .agent import Agent | ||
from .prompts.optim import OPTIMIZATION_PROMPT_GENERAL | ||
|
||
|
||
class Optimizer: | ||
def __init__(self, cfg: dict): | ||
self.optimizer_agent = Agent( | ||
name="Cypher Query Optimizer", | ||
model="gpt-4o-mini", | ||
temperature=0.0, | ||
instructions=OPTIMIZATION_PROMPT_GENERAL, | ||
) | ||
self.client = Swarm() | ||
|
||
def __call__(self, *args: Any, **kwds: Any) -> Any: | ||
pass | ||
|
||
def optimize_query(self, query: dict[str, Any]) -> str: | ||
msg = self.client.run( | ||
agent=self.optimizer_agent, | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": f"Query: {query}. Reread the query carefully: {query}", | ||
} | ||
], | ||
) | ||
return Markdown(msg.messages[-1]["content"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
OPTIMIZATION_PROMPT_GENERAL = """ | ||
You're an expert at optimizing Cypher queries. | ||
You're given a Cypher query and the user query. | ||
You need to optimize the query to be more efficient. | ||
If you think adding an index will help, suggest it. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters