Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions majority-vote/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
__pycache__
34 changes: 34 additions & 0 deletions majority-vote/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Answer by Majority Vote

The intention of this app is that for our collective answer to each question, we each run our individual answer and choose the one that has a majority.

## Setup

Create a `.env` file containing an OpenAI API key. Example:

```
OPENAI_API_KEY=sk-proj-thisisafakeapikey
```

Install requirements.
```
pip install -r requirements.txt
```

## Adding your solution

Make a python package like `sample`. It should have a function
like this:

```
def answer_question(question, schema):
...
```

Include this function in the list `answer_functions` in `__main__.py`.

## Running it

```
python -m majority_vote
```
Empty file.
64 changes: 64 additions & 0 deletions majority-vote/majority_vote/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import json
import random
from collections import Counter
from typing import Callable, Optional

import sample

from dotenv import load_dotenv


def majorities(items):
# Count occurrences of each item
counts = Counter(items)

# Find the maximum occurrence
max_count = max(counts.values())

# Extract items that have the maximum occurrence
result = [item for item, count in counts.items() if count == max_count]

return result


def majority_vote(items):
not_none_items = [item for item in items if item is not None]
# Only return None if all items are None.
if len(not_none_items) == 0:
return None
else:
result = majorities(items)
# If there's a tie, return a random item from those that are tied.
return random.choice(result)

load_dotenv()

AnswerFunction = Callable[[str, str], Optional[str]]

# TODO: Remove the sample answer_question function; add real functions.
answer_functions = [ sample.answer_question ]

results = []

with open('questions.json', 'r') as json_file:
items = json.load(json_file)

for item in items:
question = item["question"]
print(f"Processing question: {question}")

answers = [ answer_question(question, item["schema"]) for answer_question in answer_functions ]
print(f"All answers: {answers}")

answer = majority_vote(answers)
print(f"Chosen answer: {answer}")
print()

results.append({
"question": question,
"schema": item["schema"],
"answer": "n/a" if answer is None else answer
})

with open('results.json', 'w') as json_file:
json.dump(results, json_file, indent=4)
202 changes: 202 additions & 0 deletions majority-vote/questions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
[
{
"question": "How much did \"Accuray Incorporated\" spend on risk management in Q2 2022?",
"schema": "number",
"answer": null
},
{
"question": "Who is the CEO in the company \"Zegona Communications plc\"?",
"schema": "name",
"answer": null
},
{
"question": "Did \"Global Medical REIT Inc.\" have a greater Debt-to-Equity ratio than \"Zegona Communications plc\" in Q2 2021?",
"schema": "boolean",
"answer": null
},
{
"question": "How many stores did \"Accuray Incorporated\" have in the end of fiscal year 2021?",
"schema": "number",
"answer": null
},
{
"question": "How much did \"Sandwell Aquatics Centre\" spend on R&D in Q2 2023?",
"schema": "number",
"answer": null
},
{
"question": "Who is the CFO in the company \"EMT\"?",
"schema": "name",
"answer": null
},
{
"question": "Did \"Calyxt, Inc.\" have a greater Return on Assets (ROA) than \"Global Medical REIT Inc.\" in Q2 2023?",
"schema": "boolean",
"answer": null
},
{
"question": "How many stores did \"OTC_UNCIF\" have in the end of fiscal year 2022?",
"schema": "number",
"answer": null
},
{
"question": "How much did \"Accuray Incorporated\" spend on customer acquisition in Q2 2021?",
"schema": "number",
"answer": null
},
{
"question": "Who is the CEO in the company \"Accuray Incorporated\"?",
"schema": "name",
"answer": null
},
{
"question": "Did \"Comet Holding AG\" have a greater Operating Margin than \"Ethernity Networks Ltd\" in Q2 2022?",
"schema": "boolean",
"answer": null
},
{
"question": "How many stores did \"VENUS METALS CORPORATION LIMITED\" have in the end of fiscal year 2022?",
"schema": "number",
"answer": null
},
{
"question": "How much did \"Ethernity Networks Ltd\" spend on R&D in Q2 2023?",
"schema": "number",
"answer": null
},
{
"question": "Who is the COO in the company \"Sandwell Aquatics Centre\"?",
"schema": "name",
"answer": null
},
{
"question": "Did \"Calyxt, Inc.\" have a greater market capitalization than \"NICE\" in Q2 2022?",
"schema": "boolean",
"answer": null
},
{
"question": "How many stores did \"Renishaw plc\" have in the end of fiscal year 2023?",
"schema": "number",
"answer": null
},
{
"question": "How much did \"TD SYNNEX\" spend on R&D in Q2 2022?",
"schema": "number",
"answer": null
},
{
"question": "Who is the CFO in the company \"TD SYNNEX\"?",
"schema": "name",
"answer": null
},
{
"question": "Did \"Eurocell PLC\" have a greater Return on Equity (ROE) than \"Strike Energy Limited\" in Q2 2022?",
"schema": "boolean",
"answer": null
},
{
"question": "How many stores did \"OTC_UNCIF\" have in the end of fiscal year 2023?",
"schema": "number",
"answer": null
},
{
"question": "How much did \"EMT\" spend on customer acquisition in Q2 2023?",
"schema": "number",
"answer": null
},
{
"question": "Who is the Board Chairman in the company \"Motus GI Holdings, Inc.\"?",
"schema": "name",
"answer": null
},
{
"question": "Did \"Calyxt, Inc.\" have a greater Operating Margin than \"Banque Cantonale Vaudoise\" in Q2 2023?",
"schema": "boolean",
"answer": null
},
{
"question": "How many stores did \"EMT\" have in the end of fiscal year 2023?",
"schema": "number",
"answer": null
},
{
"question": "How much did \"Ethernity Networks Ltd\" spend on customer acquisition in Q2 2023?",
"schema": "number",
"answer": null
},
{
"question": "Who is the CFO in the company \"Ethernity Networks Ltd\"?",
"schema": "name",
"answer": null
},
{
"question": "Did \"Canadian Banc Corp.\" have a greater Return on Assets (ROA) than \"VENUS METALS CORPORATION LIMITED\" in Q2 2021?",
"schema": "boolean",
"answer": null
},
{
"question": "How many stores did \"VENUS METALS CORPORATION LIMITED\" have in the end of fiscal year 2023?",
"schema": "number",
"answer": null
},
{
"question": "How much did \"Motus GI Holdings, Inc.\" spend on sustainability initiatives in Q2 2023?",
"schema": "number",
"answer": null
},
{
"question": "Who is the Board Chairman in the company \"Renishaw plc\"?",
"schema": "name",
"answer": null
},
{
"question": "Did \"Canadian Banc Corp.\" have a greater Gross Profit Margin than \"Motus GI Holdings, Inc.\" in Q2 2022?",
"schema": "boolean",
"answer": null
},
{
"question": "How many stores did \"VENUS METALS CORPORATION LIMITED\" have in the end of fiscal year 2021?",
"schema": "number",
"answer": null
},
{
"question": "How much did \"Renishaw plc\" spend on risk management in Q2 2022?",
"schema": "number",
"answer": null
},
{
"question": "Who is the Board Chairman in the company \"TD SYNNEX\"?",
"schema": "name",
"answer": null
},
{
"question": "Did \"Banque Cantonale Vaudoise\" have a greater Operating Margin than \"Zegona Communications plc\" in Q2 2021?",
"schema": "boolean",
"answer": null
},
{
"question": "How many stores did \"Strike Energy Limited\" have in the end of fiscal year 2021?",
"schema": "number",
"answer": null
},
{
"question": "How much did \"Ethernity Networks Ltd\" spend on customer acquisition in Q2 2023?",
"schema": "number",
"answer": null
},
{
"question": "Who is the Chief Legal Officer in the company \"Nykredit\"?",
"schema": "name",
"answer": null
},
{
"question": "Did \"Comet Holding AG\" have a greater Operating Margin than \"Calyxt, Inc.\" in Q2 2021?",
"schema": "boolean",
"answer": null
},
{
"question": "How many stores did \"EMT\" have in the end of fiscal year 2022?",
"schema": "number",
"answer": null
}
]
1 change: 1 addition & 0 deletions majority-vote/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_dotenv==1.0.1
Loading