-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0c1890
commit b17f8a5
Showing
5 changed files
with
195 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
AI-Scientist | ||
2408.06292v2_no_appendix.pdf |
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,57 @@ | ||
|
||
from ai_scientist.perform_review import load_paper, perform_review | ||
import openai | ||
import typer | ||
import agentops | ||
from rich.console import Console | ||
from langsmith import traceable | ||
from langsmith.wrappers import wrap_openai | ||
from traceloop.sdk import Traceloop | ||
from traceloop.sdk.decorators import workflow | ||
|
||
|
||
|
||
def review_paper(paper_pdf_path: str, client: openai.OpenAI) -> str: | ||
model="gpt-4o-mini-2024-07-18" | ||
# Load paper from pdf file (raw text) | ||
paper_txt = load_paper(paper_pdf_path) | ||
review = perform_review( | ||
paper_txt, | ||
model, | ||
client, | ||
num_reflections=5, | ||
num_fs_examples=1, | ||
num_reviews_ensemble=5, | ||
temperature=0.1, | ||
) | ||
|
||
res = f'{review["Overall"]}\n{review["Decision"]}\n{review["Weaknesses"]}' | ||
return res | ||
|
||
|
||
console = Console() | ||
|
||
|
||
def run_pipeline(): | ||
|
||
paper_pdf_path = "llm-apps/2408.06292v2_no_appendix.pdf" | ||
|
||
# console.print("1. Agentops", style="bold green") | ||
# agentops.init() | ||
# client_agentops = openai.Client() | ||
# result = review_paper(paper_pdf_path=paper_pdf_path, client=client_agentops) | ||
# agentops.end_session() | ||
|
||
# console.print("2. LangSmith", style="bold green") | ||
# client_lang_smith = wrap_openai(openai.Client()) | ||
# result = review_paper(paper_pdf_path=paper_pdf_path, client=client_lang_smith) | ||
|
||
console.print("3. OpenllMetry", style="bold green") | ||
Traceloop.init(app_name="ai-scientist-v2") | ||
client_traceloop = openai.Client() | ||
review_paper_traceloop = workflow(name="paper-review")(review_paper) | ||
result = review_paper_traceloop(paper_pdf_path=paper_pdf_path, client=client_traceloop) | ||
|
||
print(f"result = {result}") | ||
if __name__ == "__main__": | ||
typer.run(run_pipeline) |
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,82 @@ | ||
import json | ||
|
||
import evaluate | ||
from datasets import Dataset | ||
from openai import OpenAI | ||
import openai | ||
from tqdm import tqdm | ||
import typer | ||
from typing import Tuple | ||
from datasets import load_dataset | ||
import random | ||
import functools | ||
import agentops | ||
from rich.console import Console | ||
from langsmith import traceable | ||
from langsmith.wrappers import wrap_openai | ||
from traceloop.sdk import Traceloop | ||
from traceloop.sdk.decorators import workflow | ||
|
||
console = Console() | ||
|
||
|
||
def get_random_datapint() -> Tuple[str, str]: | ||
dataset = load_dataset("gretelai/synthetic_text_to_sql", split='train') | ||
dataset_size = len(dataset) | ||
|
||
index = random.randint(0, dataset_size - 1) | ||
sample = dataset[index] | ||
|
||
sql_context = sample['sql_context'] | ||
sql_prompt = sample['sql_prompt'] | ||
return sql_context, sql_prompt | ||
|
||
def get_sql(query: str, context: str, client: OpenAI) -> str: | ||
|
||
prompt = f"""" | ||
Write the corresponding SQL query based on user requests and database context: | ||
User requests: {query} | ||
Database context: {context} | ||
Please return in JSON format: {{"sql": ""}} | ||
""" | ||
|
||
chat_completion = client.chat.completions.create( | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": prompt, | ||
} | ||
], | ||
model="gpt-4o-mini-2024-07-18", | ||
response_format={"type": "json_object"}, | ||
) | ||
|
||
return json.loads(chat_completion.choices[0].message.content)["sql"] | ||
|
||
|
||
def run_pipeline(): | ||
|
||
sql_context, sql_prompt = get_random_datapint() | ||
|
||
# console.print("1. Agentops", style="bold green") | ||
# agentops.init() | ||
# client_agentops = openai.Client() | ||
# result = get_sql(query=sql_prompt, context=sql_context, client=client_agentops) | ||
# agentops.end_all_sessions() | ||
|
||
# console.print("2. LangSmith", style="bold green") | ||
# client_lang_smith = wrap_openai(openai.Client()) | ||
# result = get_sql(query=sql_prompt, context=sql_context, client=client_lang_smith) | ||
|
||
console.print("3. OpenllMetry", style="bold green") | ||
Traceloop.init(app_name="text2sql-v2") | ||
|
||
client_traceloop = openai.Client() | ||
get_sql_traceloop = workflow(name="get_sql")(get_sql) | ||
result = get_sql_traceloop(query=sql_prompt, context=sql_context, client=client_traceloop) | ||
|
||
print(f"result = {result}") | ||
if __name__ == "__main__": | ||
typer.run(run_pipeline) |