-
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 #211 from polywrap/release/dev
Release Feb 21st
- Loading branch information
Showing
10 changed files
with
106 additions
and
263 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
47 changes: 0 additions & 47 deletions
47
workers/fund_public_goods/lib/strategy/utils/categorize_project.py
This file was deleted.
Oops, something went wrong.
53 changes: 0 additions & 53 deletions
53
workers/fund_public_goods/lib/strategy/utils/categorize_prompt.py
This file was deleted.
Oops, something went wrong.
102 changes: 0 additions & 102 deletions
102
workers/fund_public_goods/lib/strategy/utils/constants.py
This file was deleted.
Oops, something went wrong.
15 changes: 6 additions & 9 deletions
15
workers/fund_public_goods/lib/strategy/utils/fetch_matching_projects.py
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 |
---|---|---|
@@ -1,21 +1,18 @@ | ||
from fund_public_goods.db.entities import Projects | ||
from fund_public_goods.db.tables.projects import fetch_projects_by_category, get_unique_categories | ||
from fund_public_goods.db.tables.projects import get_all_projects_lightweight, get_projects_by_ids | ||
from fund_public_goods.lib.strategy.models.answer import Answer | ||
from fund_public_goods.lib.strategy.utils.categorize_prompt import categorize_prompt | ||
from fund_public_goods.lib.strategy.utils.get_top_matching_projects import get_top_matching_projects | ||
from fund_public_goods.lib.strategy.utils.utils import get_latest_project_per_website | ||
|
||
|
||
def fetch_matching_projects(prompt: str) -> list[tuple[Projects, list[Answer]]]: | ||
prompt_categories = categorize_prompt(prompt, get_unique_categories()) | ||
fetched_projects = fetch_projects_by_category(prompt_categories) | ||
|
||
answers_by_id = { project.id: answers for (project, answers) in fetched_projects } | ||
projects = [project for (project, _) in fetched_projects] | ||
projects_to_rank = get_all_projects_lightweight() | ||
|
||
deduplicated_projects = get_latest_project_per_website(projects) | ||
deduplicated_projects = get_latest_project_per_website(projects_to_rank) | ||
matching_projects = get_top_matching_projects(prompt, deduplicated_projects)[:10] | ||
|
||
matching_projects_with_answers = [(project, answers_by_id[project.id]) for project in matching_projects] | ||
matched_ids = [p.id for p in matching_projects] | ||
|
||
matching_projects_with_answers = get_projects_by_ids(matched_ids) | ||
|
||
return matching_projects_with_answers |
33 changes: 33 additions & 0 deletions
33
workers/fund_public_goods/lib/strategy/utils/generate_queries.py
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 langchain_openai import ChatOpenAI | ||
from langchain_core.prompts import ChatPromptTemplate | ||
from langchain_core.output_parsers import CommaSeparatedListOutputParser | ||
|
||
|
||
queries_prompt_template = """ | ||
Your goal is to provide a list of queries that will be used to perform | ||
and embeddings search over different project descriptions and get the ones | ||
that best match the user's interests. All projects are public goods funding | ||
projects in the crypto ecosystem. | ||
Provide a maximum of {n} queries. | ||
This is the user's interest: {prompt} | ||
Respond strictly with a comma-separated list of queries, without quotes | ||
""" | ||
|
||
|
||
def generate_queries(prompt: str, n) -> list[str]: | ||
queries_prompt = ChatPromptTemplate.from_messages([ | ||
("system", queries_prompt_template), | ||
]) | ||
llm = ChatOpenAI(model="gpt-4-1106-preview") # type: ignore | ||
|
||
queries_chain = queries_prompt | llm | CommaSeparatedListOutputParser() | ||
|
||
queries = queries_chain.invoke({ | ||
"prompt": prompt, | ||
"n": n, | ||
}) | ||
|
||
return queries |
Oops, something went wrong.