-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.py
More file actions
175 lines (155 loc) · 5.05 KB
/
Copy pathmain.py
File metadata and controls
175 lines (155 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import os
from argparse import ArgumentParser
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# Apply DataDreamer patches before importing anything else
from pipeline.utils.datadreamer_patches import *
from pipeline import run_datadreamer_session
from pipeline.utils.gpt4o_support import datadreamer_gpt4o_support
def validate_config():
"""Validate environment configuration based on API mode."""
api_mode = os.getenv("API_MODE", "official")
print(f"\n=== Configuration Validation ===")
print(f"API Mode: {api_mode}")
if api_mode == "official":
# Check official API requirements
required_vars = ["OPENAI_API_KEY", "ANTHROPIC_API_KEY"]
missing_vars = [var for var in required_vars if not os.getenv(var)]
if missing_vars:
print(f"\nERROR: Missing required environment variables for official mode:")
print(f" {', '.join(missing_vars)}")
print(f"\nPlease set these variables in your .env file or environment.")
return False
else:
# Check proxy API requirements
required_vars = ["PROXY_API_KEY", "PROXY_BASE_URL"]
missing_vars = [var for var in required_vars if not os.getenv(var)]
if missing_vars:
print(f"\nERROR: Missing required environment variables for proxy mode:")
print(f" {', '.join(missing_vars)}")
print(f"\nPlease set these variables in your .env file or environment.")
return False
# Display model configuration
print(f"\nModel Configuration:")
print(f" OpenAI Model: {os.getenv('OPENAI_MODEL', 'gpt-4o')}")
print(f" OpenAI Mini Model: {os.getenv('OPENAI_MINI_MODEL', 'gpt-4o-mini')}")
print(f" Anthropic Model: {os.getenv('ANTHROPIC_MODEL', 'claude-3-7-sonnet-20250219')}")
if api_mode == "official":
print(f"\nAPI Endpoints:")
print(f" OpenAI: {os.getenv('OPENAI_BASE_URL', 'https://api.openai.com/v1 (default)')}")
print(f" Anthropic: {os.getenv('ANTHROPIC_BASE_URL', 'https://api.anthropic.com (default)')}")
else:
print(f"\nProxy Endpoint: {os.getenv('PROXY_BASE_URL')}")
print(f"\n=== Configuration Valid ===\n")
return True
def main(args):
with datadreamer_gpt4o_support():
run_datadreamer_session(args)
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument(
"-o",
"--openai_api_key",
type=str,
default=os.getenv("OPENAI_API_KEY"),
help="The OpenAI secret key.",
)
parser.add_argument(
"-a",
"--anthropic_api_key",
type=str,
default=os.getenv("ANTHROPIC_API_KEY"),
help="The Anthropic secret key.",
)
parser.add_argument(
"-l",
"--llm",
type=str,
default="gpt-4o",
help="LLM to use (gpt-4 or claude-sonnet).",
)
parser.add_argument(
"-c",
"--code_llm",
type=str,
default="claude-sonnet",
help="LLM to use (gpt-4 or claude-sonnet) for code generation.",
)
parser.add_argument(
"-p",
"--pipelines",
type=str,
default="MatplotlibChartPipeline",
help="Which pipelines to run comma-separated.",
)
parser.add_argument(
"-n",
"--num",
type=str,
default="1",
help="The number of visualizations to generate per pipeline. (either a single number or a comma-separated list of numbers)",
)
parser.add_argument(
"-s",
"--seed",
type=int,
default=42,
help="The seed to use for generation.",
)
parser.add_argument(
"-b",
"--batch_size",
type=int,
default=24,
help="The number of requests to make to the LLM in parallel.",
)
parser.add_argument(
"-cb",
"--code_batch_size",
type=int,
default=24,
help="The number of requests to make to the coding LLM in parallel.",
)
parser.add_argument(
"-f",
"--force",
action="store_true",
default=False,
help="Force regenerate.",
)
parser.add_argument(
"-m",
"--name",
type=str,
default="scifi",
help="The name of the dataset to push to huggingface.",
)
parser.add_argument(
"-t",
"--types",
type=str,
default="bar chart",
help="The types of visualizations to generate.",
)
parser.add_argument(
"-q",
"--qa",
type=bool,
default=True,
help="whether to generate QA for the visualizations.",
)
args = parser.parse_args()
# Validate configuration before proceeding
if not validate_config():
exit(1)
print("LLM:", args.llm)
print("Code LLM:", args.code_llm)
print("Pipelines:", args.pipelines)
print("Num:", args.num)
print("Seed:", args.seed)
print("Batch Size:", args.batch_size)
print("Code Batch Size:", args.code_batch_size)
print("Name:", args.name)
print("Types:", args.types)
main(args)