Skip to content

Commit

Permalink
chore: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dOrgJelli committed Jan 26, 2024
1 parent bf11f27 commit 3a332d8
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 139 deletions.
91 changes: 0 additions & 91 deletions ops/models.py

This file was deleted.

4 changes: 4 additions & 0 deletions web/app/actions/startWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const startWorker = async (
},
});

if (response.status !== 200) {
throw Error(`Error startring new worker. Status: ${response.status}\nMessage: ${response.statusText}`);
}

const result = await response.json();
if (!result.worker_id || !result.run_id) {
throw new Error("Error starting new worker");
Expand Down
3 changes: 3 additions & 0 deletions web/supabase/dbTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,21 @@ export interface Database {
description: string | null
id: string
title: string | null
updated_at: number
website: string | null
}
Insert: {
description?: string | null
id: string
title?: string | null
updated_at: number
website?: string | null
}
Update: {
description?: string | null
id?: string
title?: string | null
updated_at?: number
website?: string | null
}
Relationships: []
Expand Down
1 change: 1 addition & 0 deletions web/supabase/migrations/20240118120046_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ SELECT

CREATE TABLE "public"."projects" (
"id" text NOT NULL,
"updated_at" int NOT NULL,
"title" TEXT,
"description" TEXT,
"website" TEXT,
Expand Down
1 change: 1 addition & 0 deletions workers/fund_public_goods/db/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Logs(BaseModel):
class Projects(BaseModel):

id: str
updated_at: int = Field(..., alias="updatedAt")
title: Optional[str] = None
description: Optional[str] = None
website: Optional[str] = None
Expand Down
47 changes: 36 additions & 11 deletions workers/fund_public_goods/db/tables/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,39 @@ def insert(
db: Client,
row: Applications
):
db.table("applications").insert(
{
"id": id,
"created_at": row.created_at,
"recipient": row.recipient,
"network": row.network,
"round": row.round,
"answers": row.answers,
"project_id": row.project_id
}
).execute()
db.table("applications").insert({
"id": row.id,
"created_at": row.created_at,
"recipient": row.recipient,
"network": row.network,
"round": row.round,
"answers": row.answers,
"project_id": row.project_id
}).execute()

def get_applications(
db: Client,
project_id: str
) -> list[Applications]:
result = (db.table("applications")
.select("id, created_at, recipient, network, round, answers, project_id")
.eq("project_id", project_id)
.execute())

if not result.data:
return []

applications = []

for item in result.data:
applications.append(Applications(
id=item["id"],
created_at=item["created_at"],
recipient=item["recipient"],
network=item["network"],
round=item["round"],
answers=item["answers"],
project_id=item["project_id"]
))

return applications
20 changes: 16 additions & 4 deletions workers/fund_public_goods/db/tables/gitcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fund_public_goods.db.client import create_admin
from fund_public_goods.db import tables, entities

def upsert_project(project: GitcoinProjects):
def upsert_project(project: GitcoinProjects, created_at: int):
db = create_admin()

db.table("gitcoin_projects").upsert({
Expand All @@ -14,18 +14,30 @@ def upsert_project(project: GitcoinProjects):
"data": project.data
}).execute()

tables.projects.insert(db, entities.Projects(
result = tables.projects.get(db, project.id)

if result and result.updated_at > created_at:
return

row = entities.Projects(
id=project.id,
updated_at=created_at,
title=project.data["title"],
description=project.data["description"],
website=project.data["website"]
))
)

if result == None:
tables.projects.insert(db, row)
else:
tables.projects.upsert(db, row)

def save_application(app: GitcoinApplications, network: int):
db = create_admin()

db.table("gitcoin_applications").insert({
"id": app.id,
"created_at": app.created_at,
"protocol": app.protocol,
"pointer": app.pointer,
"round_id": app.round_id,
Expand All @@ -39,7 +51,7 @@ def save_application(app: GitcoinApplications, network: int):
recipient=app.data["application"]["recipient"],
network=network,
round=app.round_id,
answers=app.data["application"]["answers"],
answers=json.dumps(app.data["application"]["answers"]),
project_id=app.project_id
))

Expand Down
2 changes: 1 addition & 1 deletion workers/fund_public_goods/db/tables/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ def insert(
row: Logs
):
db.table("logs").insert({
"run_id": row.run_id,
"run_id": str(row.run_id),
"message": row.message
}).execute()
62 changes: 46 additions & 16 deletions workers/fund_public_goods/db/tables/projects.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,59 @@
from typing import Any, Dict
from supabase import Client, PostgrestAPIResponse
import uuid
from fund_public_goods.db.entities import Projects


def insert(
db: Client, row: Projects
db: Client,
row: Projects
) -> str:
id = str(uuid.uuid4())
db.table("projects").insert(
{
"id": id,
"title": row.title,
"description": row.description,
"website": row.website,
}
).execute()
return id


def get_projects(db: Client) -> PostgrestAPIResponse[Dict[str, Any]]:
db.table("projects").insert({
"id": row.id,
"updated_at": row.updated_at,
"title": row.title,
"description": row.description,
"website": row.website,
}).execute()

def upsert(
db: Client,
row: Projects
) -> str:
db.table("projects").upsert({
"id": row.id,
"updated_at": row.updated_at,
"title": row.title,
"description": row.description,
"website": row.website,
}).execute()

def get(
db: Client,
project_id: str
) -> Projects | None:
result = (db.table("projects")
.select("id", "updated_at", "title", "description", "website")
.eq("id", project_id)
.execute())

if not result.data:
return None

data = result.data[0]

return Projects(
id=data["id"],
updated_at=data["updated_at"],
title=data["title"],
description=data["description"],
website=data["website"]
)

def get_projects(db: Client) -> list[Projects]:
return (
db.table("projects")
.select(
"id, title, description, website, applications(id, recipient, round, answers)"
"id, updated_at, title, description, website, applications(id, recipient, round, answers)"
)
.execute()
)
2 changes: 1 addition & 1 deletion workers/fund_public_goods/db/tables/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def insert(db: Client, row: Runs) -> str:
id = str(uuid.uuid4())
db.table("runs").insert({
"id": id,
"worker_id": row.worker_id,
"worker_id": str(row.worker_id),
"prompt": row.prompt
}).execute()
return id
Expand Down
2 changes: 1 addition & 1 deletion workers/fund_public_goods/db/tables/strategy_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def insert(
row: StrategyEntries
):
db.table("strategy_entries").insert({
"run_id": row.run_id,
"run_id": str(row.run_id),
"project_id": row.project_id,
"reasoning": row.reasoning,
"impact": row.impact,
Expand Down
2 changes: 0 additions & 2 deletions workers/fund_public_goods/lib/gitcoin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ def fetch_project_applications(url: str, round_id: str, skip: int, first: int) -
}
}

print(f"Fetching projects for round {round_id} ...")

response = requests.post(url, json=data)

if response.status_code == 200:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def remove_duplicate_projects(projects: list[Project]) -> list[Project]:
return unique_projects

def get_top_matching_projects(prompt: str, projects: list[Project]) -> list[Project]:
if len(projects) == 0:
return []

projects_by_id = {project.id: project for project in projects}
queries = generate_queries(prompt=prompt, n=3)
texts: list[str] = []
Expand All @@ -50,7 +53,8 @@ def get_top_matching_projects(prompt: str, projects: list[Project]) -> list[Proj
project_text = get_project_text(project=project)
texts.append(project_text)
metadatas.append({ "id": project["id"] })



db_client = EphemeralClient()
collection = Chroma.from_texts(
texts=texts,
Expand All @@ -59,7 +63,7 @@ def get_top_matching_projects(prompt: str, projects: list[Project]) -> list[Proj
client=db_client,
collection_name="projects"
)

top_matches: list[Project] = []

for query in queries:
Expand Down
Loading

0 comments on commit 3a332d8

Please sign in to comment.