Spaces:
Sleeping
Sleeping
Update art_explorer.py
Browse files- art_explorer.py +5 -6
art_explorer.py
CHANGED
@@ -1,19 +1,17 @@
|
|
1 |
from typing import Optional, List, Dict
|
2 |
import json
|
3 |
-
import instructor
|
4 |
from openai import OpenAI
|
|
|
5 |
from prompts import SYSTEM_PROMPT, format_exploration_prompt, DEFAULT_RESPONSE
|
6 |
from models import ExplorationResponse
|
7 |
|
8 |
class ExplorationPathGenerator:
|
9 |
def __init__(self, api_key: str):
|
10 |
-
# Initialize the base client
|
11 |
base_client = OpenAI(
|
12 |
base_url="https://api.groq.com/openai/v1",
|
13 |
api_key=api_key
|
14 |
)
|
15 |
-
|
16 |
-
self.client = instructor.patch(base_client)
|
17 |
|
18 |
def generate_exploration_path(
|
19 |
self,
|
@@ -37,7 +35,7 @@ class ExplorationPathGenerator:
|
|
37 |
exploration_parameters=exploration_parameters
|
38 |
)
|
39 |
|
40 |
-
# Use
|
41 |
response = self.client.chat.completions.create(
|
42 |
model="mixtral-8x7b-32768",
|
43 |
messages=[
|
@@ -55,9 +53,10 @@ class ExplorationPathGenerator:
|
|
55 |
response_model=ExplorationResponse
|
56 |
)
|
57 |
|
58 |
-
#
|
59 |
return response.model_dump()
|
60 |
|
61 |
except Exception as e:
|
62 |
print(f"Error in API call: {e}")
|
|
|
63 |
return DEFAULT_RESPONSE
|
|
|
1 |
from typing import Optional, List, Dict
|
2 |
import json
|
|
|
3 |
from openai import OpenAI
|
4 |
+
from instructor_function_calling import InstructorFunctionCalling
|
5 |
from prompts import SYSTEM_PROMPT, format_exploration_prompt, DEFAULT_RESPONSE
|
6 |
from models import ExplorationResponse
|
7 |
|
8 |
class ExplorationPathGenerator:
|
9 |
def __init__(self, api_key: str):
|
|
|
10 |
base_client = OpenAI(
|
11 |
base_url="https://api.groq.com/openai/v1",
|
12 |
api_key=api_key
|
13 |
)
|
14 |
+
self.client = InstructorFunctionCalling(client=base_client)
|
|
|
15 |
|
16 |
def generate_exploration_path(
|
17 |
self,
|
|
|
35 |
exploration_parameters=exploration_parameters
|
36 |
)
|
37 |
|
38 |
+
# Use the function calling client to generate response
|
39 |
response = self.client.chat.completions.create(
|
40 |
model="mixtral-8x7b-32768",
|
41 |
messages=[
|
|
|
53 |
response_model=ExplorationResponse
|
54 |
)
|
55 |
|
56 |
+
# Response is already validated against the Pydantic model
|
57 |
return response.model_dump()
|
58 |
|
59 |
except Exception as e:
|
60 |
print(f"Error in API call: {e}")
|
61 |
+
print(f"Error details: {str(e)}")
|
62 |
return DEFAULT_RESPONSE
|