kingkaikai commited on
Commit
7ce3564
·
verified ·
1 Parent(s): bafdd42

update the id

Browse files
Files changed (2) hide show
  1. agent.py +2 -6
  2. app.py +14 -1
agent.py CHANGED
@@ -124,8 +124,8 @@ sys_msg = SystemMessage(content=system_prompt)
124
  # build a retriever
125
  embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2") # dim=768
126
  supabase: Client = create_client(
127
- "https://kghadsdyocxyfohvdldg.supabase.co",
128
- "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImtnaGFkc2R5b2N4eWZvaHZkbGRnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTExODk4MjAsImV4cCI6MjA2Njc2NTgyMH0.fKKUi0B9vG4tiz7Fi2cZ_rol64hBcOX4xtNWxs9SesM")
129
  vector_store = SupabaseVectorStore(
130
  client=supabase,
131
  embedding= embeddings,
@@ -155,7 +155,6 @@ tools = [
155
  def build_graph(provider: str = "groq"):
156
  """Build the graph"""
157
  # Load environment variables from .env file
158
- HF_API_KEY=os.getenv("HF_API_KEY")
159
  if provider == "google":
160
  # Google Gemini
161
  llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
@@ -168,9 +167,6 @@ def build_graph(provider: str = "groq"):
168
  llm=HuggingFaceEndpoint(
169
  url="https://api-inference.huggingface.co/models/Meta-DeepLearning/llama-2-7b-chat-hf",
170
  temperature=0,
171
- headers={
172
- "Authorization": f"Bearer {HF_API_KEY}" # 硬编码方式传递 API 密钥
173
- }
174
  ),
175
  )
176
  else:
 
124
  # build a retriever
125
  embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2") # dim=768
126
  supabase: Client = create_client(
127
+ os.environ.get("SUPABASE_URL"),
128
+ os.environ.get("SUPABASE_SERVICE_KEY"))
129
  vector_store = SupabaseVectorStore(
130
  client=supabase,
131
  embedding= embeddings,
 
155
  def build_graph(provider: str = "groq"):
156
  """Build the graph"""
157
  # Load environment variables from .env file
 
158
  if provider == "google":
159
  # Google Gemini
160
  llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
 
167
  llm=HuggingFaceEndpoint(
168
  url="https://api-inference.huggingface.co/models/Meta-DeepLearning/llama-2-7b-chat-hf",
169
  temperature=0,
 
 
 
170
  ),
171
  )
172
  else:
app.py CHANGED
@@ -12,6 +12,7 @@ from agent import build_graph
12
  # (Keep Constants as is)
13
  # --- Constants ---
14
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
15
 
16
  # --- Basic Agent Definition ---
17
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
@@ -38,7 +39,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
38
  and displays the results.
39
  """
40
  # --- Determine HF Space Runtime URL and Repo URL ---
41
- space_id = "kingkaikai/Final_Assignment_Template_2" # Get the SPACE_ID for sending link to the code
42
 
43
  if profile:
44
  username= f"{profile.username}"
@@ -104,6 +105,17 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
104
  print("Agent did not produce any answers to submit.")
105
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
106
 
 
 
 
 
 
 
 
 
 
 
 
107
  # 4. Prepare Submission
108
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
109
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
@@ -120,6 +132,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
120
  f"User: {result_data.get('username')}\n"
121
  f"Overall Score: {result_data.get('score', 'N/A')}% "
122
  f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
 
123
  f"Message: {result_data.get('message', 'No message received.')}"
124
  )
125
  print("Submission successful.")
 
12
  # (Keep Constants as is)
13
  # --- Constants ---
14
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
15
+ SUBMISSION_FILE = "submission.jsonl"
16
 
17
  # --- Basic Agent Definition ---
18
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
39
  and displays the results.
40
  """
41
  # --- Determine HF Space Runtime URL and Repo URL ---
42
+ space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
43
 
44
  if profile:
45
  username= f"{profile.username}"
 
105
  print("Agent did not produce any answers to submit.")
106
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
107
 
108
+ # Generate JSON-line submission file
109
+ try:
110
+ with open(SUBMISSION_FILE, "w") as f:
111
+ for entry in answers_payload:
112
+ json.dump(entry, f)
113
+ f.write("\n")
114
+ print(f"Successfully generated submission file: {SUBMISSION_FILE}")
115
+ except Exception as e:
116
+ print(f"Error generating submission file: {e}")
117
+ return f"Error generating submission file: {e}", pd.DataFrame(results_log)
118
+
119
  # 4. Prepare Submission
120
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
121
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
 
132
  f"User: {result_data.get('username')}\n"
133
  f"Overall Score: {result_data.get('score', 'N/A')}% "
134
  f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
135
+ f"Submission file generated: {SUBMISSION_FILE}\n"
136
  f"Message: {result_data.get('message', 'No message received.')}"
137
  )
138
  print("Submission successful.")