baconnier commited on
Commit
1a6469a
·
verified ·
1 Parent(s): 4282819

Update art_explorer.py

Browse files
Files changed (1) hide show
  1. art_explorer.py +34 -9
art_explorer.py CHANGED
@@ -37,6 +37,7 @@ class ExplorationPathGenerator:
37
  ) -> Dict[str, Any]:
38
  """Generate an exploration path based on the query and parameters"""
39
  try:
 
40
  selected_path = selected_path or []
41
  exploration_parameters = exploration_parameters or {}
42
 
@@ -46,35 +47,59 @@ class ExplorationPathGenerator:
46
  selected_path=selected_path,
47
  exploration_parameters=exploration_parameters
48
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  response = self.client.chat.completions.create(
51
  model="mixtral-8x7b-32768",
52
- messages=[
53
- {"role": "system", "content": SYSTEM_PROMPT},
54
- {"role": "user", "content": formatted_prompt}
55
- ],
56
  temperature=0.7,
57
  max_tokens=2000
58
  )
 
 
 
59
 
60
  # Parse the response
61
  try:
62
  result = json.loads(response.choices[0].message.content)
63
- except json.JSONDecodeError:
64
- print("Failed to parse API response as JSON, using default response")
 
 
 
65
  result = DEFAULT_RESPONSE
66
 
67
  # Convert to ExplorationPath model
68
  exploration_path = ExplorationPath(
69
- nodes=[ExplorationNode(**node) for node in result.get("nodes", [])],
70
  query=query,
71
  domain=exploration_parameters.get("domain")
72
  )
73
 
74
- return exploration_path.model_dump()
 
 
 
 
75
 
76
  except Exception as e:
77
- print(f"Error generating exploration path: {e}")
78
  return {
79
  "error": str(e),
80
  "status": "failed",
 
37
  ) -> Dict[str, Any]:
38
  """Generate an exploration path based on the query and parameters"""
39
  try:
40
+ print("\n=== Starting API Request ===")
41
  selected_path = selected_path or []
42
  exploration_parameters = exploration_parameters or {}
43
 
 
47
  selected_path=selected_path,
48
  exploration_parameters=exploration_parameters
49
  )
50
+
51
+ print("\n=== Formatted Request ===")
52
+ print("System Prompt:", SYSTEM_PROMPT[:200] + "...") # First 200 chars
53
+ print("\nFormatted Prompt (excerpt):", formatted_prompt[:200] + "...")
54
+
55
+ messages = [
56
+ {"role": "system", "content": SYSTEM_PROMPT},
57
+ {"role": "user", "content": formatted_prompt}
58
+ ]
59
+
60
+ print("\n=== API Request Parameters ===")
61
+ print(json.dumps({
62
+ "model": "mixtral-8x7b-32768",
63
+ "messages": [{"role": m["role"], "content": m["content"][:100] + "..."} for m in messages],
64
+ "temperature": 0.7,
65
+ "max_tokens": 2000
66
+ }, indent=2))
67
 
68
  response = self.client.chat.completions.create(
69
  model="mixtral-8x7b-32768",
70
+ messages=messages,
 
 
 
71
  temperature=0.7,
72
  max_tokens=2000
73
  )
74
+
75
+ print("\n=== API Response ===")
76
+ print("Raw response content:", response.choices[0].message.content[:200] + "...")
77
 
78
  # Parse the response
79
  try:
80
  result = json.loads(response.choices[0].message.content)
81
+ print("\n=== Parsed Response ===")
82
+ print(json.dumps(result, indent=2)[:200] + "...")
83
+ except json.JSONDecodeError as e:
84
+ print(f"\n=== JSON Parse Error ===\n{str(e)}")
85
+ print("Using default response")
86
  result = DEFAULT_RESPONSE
87
 
88
  # Convert to ExplorationPath model
89
  exploration_path = ExplorationPath(
90
+ nodes=result.get("nodes", []), # Changed from list comprehension to simple get
91
  query=query,
92
  domain=exploration_parameters.get("domain")
93
  )
94
 
95
+ final_result = exploration_path.model_dump()
96
+ print("\n=== Final Result ===")
97
+ print(json.dumps(final_result, indent=2))
98
+
99
+ return final_result
100
 
101
  except Exception as e:
102
+ print(f"\n=== Error ===\n{str(e)}")
103
  return {
104
  "error": str(e),
105
  "status": "failed",