Skip to content

Instantly share code, notes, and snippets.

@Kurry
Last active October 12, 2023 04:09
Show Gist options
  • Save Kurry/68ffb96bc470ccce9897931cd43d2a43 to your computer and use it in GitHub Desktop.
Save Kurry/68ffb96bc470ccce9897931cd43d2a43 to your computer and use it in GitHub Desktop.
Prompt As A Service Sample Code
from datasets import load_dataset
# Load the dataset from Hugging Face
dataset = load_dataset("kurry/sp500_constituents_10q")
# Placeholder list for companies with known accounting issues
companies_with_issues = ["CompanyA", "CompanyB"] # This needs to be populated
# Analyze each company's 10-Q using Claude 2
true_positives = 0
false_positives = 0
def analyze_with_claude_2(ten_q_content):
url = "https://api.promptperfect.jina.ai/your-api-endpoint"
headers = {"Content-Type": "application/json"}
response = requests.post(url, headers=headers, json={"parameters": {"earnings_call_transcript": ten_q_content}})
if response.status_code == 200:
return response.json() # Assuming the response contains the risks identified
else:
print(response.text)
return []
# Dictionary of known accounting issues for each company
known_issues_dict = {
"CompanyA": ["issue1", "issue2", ...],
"CompanyB": ["issue1", ...],
# ... add other companies and their known issues
}
for company in companies_with_issues:
# Extracting the report content using the 'report' field
ten_q_content = dataset['train'][company]['report']
# Analyze using Claude 2
risks_identified = analyze_with_claude_2(ten_q_content)
# Retrieve known issues for the current company
known_issues = known_issues_dict.get(company, [])
# Compare with known issues
matching_issues = [issue for issue in risks_identified if issue in known_issues]
if matching_issues:
true_positives += 1
else:
false_positives += 1
# Calculate precision
precision = true_positives / (true_positives + false_positives)
print(f"Precision: {precision * 100:.2f}%")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment